Ujeshhh commited on
Commit
1886dd0
·
verified ·
1 Parent(s): 544363a
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -1,19 +1,23 @@
1
- from transformers import pipeline
2
  import gradio as gr
 
3
 
4
- # Load sentiment analysis model
5
- sentiment_pipeline = pipeline("text-classification", model="tabularisai/multilingual-sentiment-analysis")
6
 
7
- # Function for sentiment analysis
8
- def sentiment_analysis(text):
9
  result = sentiment_pipeline(text)[0]
10
- return f"Label: {result['label']}, Confidence: {round(result['score'], 4)}"
 
 
11
 
12
- # Gradio Interface
13
- demo = gr.Interface(fn=sentiment_analysis,
14
- inputs=gr.Textbox(label="Enter Text"),
15
- outputs=gr.Textbox(label="Sentiment Output"),
16
- title="Multilingual Sentiment Analysis")
 
 
 
17
 
18
- # Launch app locally
19
- demo.launch()
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Load pre-trained sentiment analysis model from Hugging Face
5
+ sentiment_pipeline = pipeline("tabularisai/multilingual-sentiment-analysis")
6
 
7
+ def analyze_sentiment(text):
 
8
  result = sentiment_pipeline(text)[0]
9
+ label = result['label']
10
+ score = round(result['score'], 3)
11
+ return f"Sentiment: {label} | Confidence: {score}"
12
 
13
+ # Gradio UI
14
+ iface = gr.Interface(
15
+ fn=analyze_sentiment,
16
+ inputs=gr.Textbox(label="Enter Text"),
17
+ outputs=gr.Textbox(label="Sentiment Result"),
18
+ title="Sentiment Analysis with Hugging Face 🤗",
19
+ description="This app performs sentiment analysis on user input text using Hugging Face Transformers."
20
+ )
21
 
22
+ if __name__ == "__main__":
23
+ iface.launch()