Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +20 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load sentiment analysis pipeline
|
| 5 |
+
sentiment_pipeline = pipeline("sentiment-analysis")
|
| 6 |
+
|
| 7 |
+
def analyze_sentiment(text):
|
| 8 |
+
result = sentiment_pipeline(text)[0]
|
| 9 |
+
label = result['label']
|
| 10 |
+
score = result['score']
|
| 11 |
+
return f"Sentiment: {label} (Confidence: {score:.2f})"
|
| 12 |
+
|
| 13 |
+
# Create Gradio interface
|
| 14 |
+
iface = gr.Interface(fn=analyze_sentiment,
|
| 15 |
+
inputs=gr.Textbox(lines=4, placeholder="Type a review here..."),
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="Sentiment Analyzer",
|
| 18 |
+
description="A simple sentiment analysis demo using Hugging Face transformers.")
|
| 19 |
+
|
| 20 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
gradio
|
| 3 |
+
torch
|