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