crang commited on
Commit
40bac30
·
verified ·
1 Parent(s): 6e483b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -3
app.py CHANGED
@@ -1,4 +1,21 @@
1
- from transformers.tools.base import launch_gradio_demo
2
- from sentiment_analysis import SentimentAnalysisTool
3
 
4
- launch_gradio_demo(SentimentAnalysisTool)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ def analyze_sentiment(text):
5
+ classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
6
+ result = classifier(text)
7
+ return {
8
+ "label": result[0]["label"],
9
+ "score": result[0]["score"]
10
+ }
11
+
12
+ demo = gr.Interface(
13
+ fn=analyze_sentiment,
14
+ inputs="textbox",
15
+ outputs="json",
16
+ title="Sentiment Analysis",
17
+ description="Enter text to analyze its sentiment using DistilBERT."
18
+ )
19
+
20
+ demo.queue(api_open=True)
21
+ demo.launch()