Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 8 |
-
result = sentiment_pipeline(text)[0]
|
| 9 |
-
return f"Sentiment: {result['label']} (Confidence: {result['score']:.2f})"
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
outputs="text",
|
| 16 |
-
title="Sentiment
|
| 17 |
-
description="Enter a sentence
|
| 18 |
)
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
| 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()
|