app
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the sentiment analysis pipeline from Hugging Face
|
5 |
+
sentiment_pipeline = pipeline("sentiment-analysis")
|
6 |
+
|
7 |
+
def analyze_sentiment(text):
|
8 |
+
result = sentiment_pipeline(text)[0]
|
9 |
+
sentiment = result['label']
|
10 |
+
confidence = result['score']
|
11 |
+
return f"Sentiment: {sentiment}, Confidence: {confidence:.2f}"
|
12 |
+
|
13 |
+
# Create the Gradio interface
|
14 |
+
iface = gr.Interface(
|
15 |
+
fn=analyze_sentiment,
|
16 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text here..."),
|
17 |
+
outputs="text",
|
18 |
+
title="Sentiment Analysis",
|
19 |
+
description="Enter text and click the button to detect the sentiment."
|
20 |
+
)
|
21 |
+
|
22 |
+
# Launch the interface
|
23 |
+
iface.launch()
|