Spaces:
Sleeping
Sleeping
File size: 879 Bytes
9d35eb6 16e269b 9d35eb6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import gradio as gr
from transformers import AutoModelForSequenceClassification, DistilBertTokenizerFast, pipeline
MODEL_ID = "Krish623/sentiment-model"
tokenizer = DistilBertTokenizerFast.from_pretrained(MODEL_ID)
model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID)
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer, top_k=None)
def predict(text):
results = classifier(text)
scores = results[0] if isinstance(results[0], list) else results
best = max(scores, key=lambda x: x["score"])
return {"label": best["label"], "score": best["score"]}
# ✅ USE BLOCKS (IMPORTANT)
with gr.Blocks() as demo:
inp = gr.Textbox(label="Enter text")
out = gr.JSON()
btn = gr.Button("Predict")
# 👇 THIS LINE FIXES EVERYTHING
btn.click(fn=predict, inputs=inp, outputs=out, api_name="/predict")
demo.launch()
|