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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -17
app.py CHANGED
@@ -1,26 +1,28 @@
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()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ sentiment_pipeline = pipeline("sentiment-analysis")
5
 
6
+ def analyze_sentiment(text):
7
+ result = sentiment_pipeline(text)[0]
8
+ return f"Sentiment: {result['label']} (Confidence: {result['score']:.2f})"
9
 
 
 
 
 
 
 
 
10
 
11
+ custom_css = """
12
+ #interface-container {background-color: #f8f9fa;}
13
+ #title {color: #2c3e50; font-size: 24px;}
14
+ """
15
 
 
 
 
 
 
 
 
16
 
17
+ iface = gr.Interface(
18
+ fn=analyze_sentiment,
19
+ inputs=gr.Textbox(label="Enter Text", placeholder="Type your sentence here..."),
20
+ outputs=gr.Text(label="Sentiment Analysis Result"),
21
+ title="Sentiment Analysis API",
22
+ description="🔍 Enter a sentence, and the model will predict if it's POSITIVE or NEGATIVE.",
23
+ theme="compact",
24
+ css=custom_css
25
+ )
26
 
27
+ # Launch the Gradio app
28
+ iface.launch()