File size: 587 Bytes
40bac30
e433261
40bac30
c52adb8
e433261
40bac30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
import spaces
from transformers import pipeline

@spaces.GPU(duration=150)
def analyze_sentiment(text):
    classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
    result = classifier(text)
    return {
        "label": result[0]["label"],
        "score": result[0]["score"]
    }

demo = gr.Interface(
    fn=analyze_sentiment,
    inputs="textbox",
    outputs="json",
    title="Sentiment Analysis",
    description="Enter text to analyze its sentiment using DistilBERT."
)

demo.queue(api_open=True)
demo.launch()