NickTran commited on
Commit
90ae3f3
1 Parent(s): de57d8a

add requirements

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -1,17 +1,21 @@
1
  import gradio as gr
2
- from transformers import pipeline # Assuming you're using Hugging Face's transformers library
3
 
4
- # Load your pipeline
5
- pipe = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")
6
 
7
- # Define the Gradio interface function
8
- def classify_text(text):
9
- result = pipe(text)
10
- return result[0]["label"], result[0]["score"]
11
 
12
- # Create the Gradio interface
13
  iface = gr.Interface(
14
- fn=classify_text,
15
- inputs=[gr.Textbox(label="Enter text")],
16
- outputs=[gr.Label(label="Label"), gr.Number(label="Confidence")]
17
- )
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Load a sentiment analysis pipeline from Hugging Face
5
+ sentiment_pipeline = pipeline("sentiment-analysis")
6
 
7
+ def analyze_sentiment(text):
8
+ result = sentiment_pipeline(text)
9
+ return result[0]["label"] # Return the sentiment label (positive, negative, neutral)
 
10
 
11
+ # Create a Gradio interface
12
  iface = gr.Interface(
13
+ fn=analyze_sentiment,
14
+ inputs=[gr.Textbox(label="Enter text here")],
15
+ outputs=[gr.Label(label="Sentiment")],
16
+ title="Sentiment Analyzer",
17
+ description="Enter a text to analyze its sentiment",
18
+ )
19
+
20
+ # Launch the Gradio interface
21
+ iface.launch()