Spaces:
Sleeping
Sleeping
black shadow
commited on
Commit
·
d898436
1
Parent(s):
02972ad
Hugging Face Project✅
Browse files
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load Sentiment Analysis Model
|
5 |
+
sentiment_pipeline = pipeline("sentiment-analysis")
|
6 |
+
|
7 |
+
# Define Function for Prediction
|
8 |
+
def analyze_sentiment(text):
|
9 |
+
result = sentiment_pipeline(text)
|
10 |
+
return result[0]["label"], result[0]["score"]
|
11 |
+
|
12 |
+
# Create Gradio Interface
|
13 |
+
iface = gr.Interface(
|
14 |
+
fn=analyze_sentiment,
|
15 |
+
inputs=gr.Textbox(label="Enter Text"),
|
16 |
+
outputs=[gr.Textbox(label="Sentiment"), gr.Textbox(label="Confidence Score")],
|
17 |
+
title="Sentiment Analysis App",
|
18 |
+
description="Enter a sentence and get its sentiment (Positive/Negative).",
|
19 |
+
)
|
20 |
+
|
21 |
+
iface.launch()
|