Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
|
|
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
| 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 |
-
|
| 26 |
-
|
|
|
|
| 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()
|