Spaces:
Sleeping
Sleeping
app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,23 @@
|
|
1 |
-
from transformers import pipeline
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
-
# Load sentiment analysis model
|
5 |
-
sentiment_pipeline = pipeline("
|
6 |
|
7 |
-
|
8 |
-
def sentiment_analysis(text):
|
9 |
result = sentiment_pipeline(text)[0]
|
10 |
-
|
|
|
|
|
11 |
|
12 |
-
# Gradio
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# Load pre-trained sentiment analysis model from Hugging Face
|
5 |
+
sentiment_pipeline = pipeline("tabularisai/multilingual-sentiment-analysis")
|
6 |
|
7 |
+
def analyze_sentiment(text):
|
|
|
8 |
result = sentiment_pipeline(text)[0]
|
9 |
+
label = result['label']
|
10 |
+
score = round(result['score'], 3)
|
11 |
+
return f"Sentiment: {label} | Confidence: {score}"
|
12 |
|
13 |
+
# Gradio UI
|
14 |
+
iface = gr.Interface(
|
15 |
+
fn=analyze_sentiment,
|
16 |
+
inputs=gr.Textbox(label="Enter Text"),
|
17 |
+
outputs=gr.Textbox(label="Sentiment Result"),
|
18 |
+
title="Sentiment Analysis with Hugging Face 🤗",
|
19 |
+
description="This app performs sentiment analysis on user input text using Hugging Face Transformers."
|
20 |
+
)
|
21 |
|
22 |
+
if __name__ == "__main__":
|
23 |
+
iface.launch()
|