Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForSequenceClassification, DistilBertTokenizerFast, pipeline
|
| 3 |
+
|
| 4 |
+
MODEL_ID = "Krish623/sentiment-model"
|
| 5 |
+
tokenizer = DistilBertTokenizerFast.from_pretrained(MODEL_ID)
|
| 6 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID)
|
| 7 |
+
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer, top_k=None)
|
| 8 |
+
|
| 9 |
+
def predict(text):
|
| 10 |
+
results = classifier(text)
|
| 11 |
+
scores = results[0] if isinstance(results[0], list) else results
|
| 12 |
+
best = max(scores, key=lambda x: x["score"])
|
| 13 |
+
return {"label": best["label"], "score": best["score"]}
|
| 14 |
+
|
| 15 |
+
demo = gr.Interface(fn=predict, inputs="text", outputs="json", title="Sentiment Analysis")
|
| 16 |
+
demo.launch()
|