AsthanM commited on
Commit
806b724
·
verified ·
1 Parent(s): 3575337

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -1,21 +1,26 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load Sentiment Analysis model
5
- sentiment_pipeline = pipeline("sentiment-analysis")
6
 
7
- def analyze_sentiment(text):
8
- result = sentiment_pipeline(text)[0]
9
- return f"Sentiment: {result['label']} (Confidence: {result['score']:.2f})"
10
 
11
- # Create Gradio Interface
12
- iface = gr.Interface(
13
- fn=analyze_sentiment,
14
- inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
 
 
 
 
 
 
 
 
15
  outputs="text",
16
- title="Sentiment Analysis API",
17
- description="Enter a sentence, and the model will predict if it's POSITIVE or NEGATIVE."
18
  )
19
 
20
- # Launch the Gradio app
21
- iface.launch()
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
 
 
4
 
5
+ analyzer = pipeline("sentiment-analysis")
 
 
6
 
7
+ def sentiment_classifier(input_text):
8
+ """Classifies the sentiment of the given text."""
9
+ prediction = analyzer(input_text)[0]
10
+ sentiment_label = prediction['label']
11
+ confidence_score = round(prediction['score'], 2)
12
+
13
+ return f"Sentiment: {sentiment_label} (Confidence: {confidence_score})"
14
+
15
+
16
+ app = gr.Interface(
17
+ fn=sentiment_classifier,
18
+ inputs=gr.Textbox(lines=3, placeholder="Type something..."),
19
  outputs="text",
20
+ title="Text Sentiment Classifier",
21
+ description="Enter a sentence to analyze its sentiment as POSITIVE or NEGATIVE."
22
  )
23
 
24
+
25
+ if __name__ == "__main__":
26
+ app.launch()