Create inference.py
Browse files- inference.py +21 -0
inference.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
# Load your model
|
| 5 |
+
classifier = pipeline(
|
| 6 |
+
"text-classification",
|
| 7 |
+
model="your-username/your-model-name", # Replace with your model path
|
| 8 |
+
tokenizer="your-username/your-model-name"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
def predict(text):
|
| 12 |
+
"""Simple prediction function"""
|
| 13 |
+
result = classifier(text)
|
| 14 |
+
return result
|
| 15 |
+
|
| 16 |
+
# Example usage
|
| 17 |
+
if __name__ == "__main__":
|
| 18 |
+
sample_text = "This is an amazing model!"
|
| 19 |
+
prediction = predict(sample_text)
|
| 20 |
+
print(f"Input: {sample_text}")
|
| 21 |
+
print(f"Prediction: {prediction}")
|