Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +22 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the sentiment analysis model
|
5 |
+
classifier = pipeline("sentiment-analysis")
|
6 |
+
|
7 |
+
# Define the function to analyze sentiment
|
8 |
+
def analyze_sentiment(text):
|
9 |
+
result = classifier(text)[0]
|
10 |
+
return f"Sentiment: {result['label']}", f"Confidence: {result['score']:.2f}"
|
11 |
+
|
12 |
+
# Create a Gradio interface
|
13 |
+
demo = gr.Interface(
|
14 |
+
fn=analyze_sentiment,
|
15 |
+
inputs="text",
|
16 |
+
outputs=["text", "text"],
|
17 |
+
title="Sentiment Analyzer",
|
18 |
+
description="Enter a sentence to analyze sentiment (Positive or Negative)."
|
19 |
+
)
|
20 |
+
|
21 |
+
if __name__ == "__main__":
|
22 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
transformers
|
3 |
+
torch
|