NickTran
commited on
Commit
•
90ae3f3
1
Parent(s):
de57d8a
add requirements
Browse files
app.py
CHANGED
@@ -1,17 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import pipeline
|
3 |
|
4 |
-
# Load
|
5 |
-
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
result
|
10 |
-
return result[0]["label"], result[0]["score"]
|
11 |
|
12 |
-
# Create
|
13 |
iface = gr.Interface(
|
14 |
-
fn=
|
15 |
-
inputs=[gr.Textbox(label="Enter text")],
|
16 |
-
outputs=[gr.Label(label="
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# Load a sentiment analysis pipeline from Hugging Face
|
5 |
+
sentiment_pipeline = pipeline("sentiment-analysis")
|
6 |
|
7 |
+
def analyze_sentiment(text):
|
8 |
+
result = sentiment_pipeline(text)
|
9 |
+
return result[0]["label"] # Return the sentiment label (positive, negative, neutral)
|
|
|
10 |
|
11 |
+
# Create a Gradio interface
|
12 |
iface = gr.Interface(
|
13 |
+
fn=analyze_sentiment,
|
14 |
+
inputs=[gr.Textbox(label="Enter text here")],
|
15 |
+
outputs=[gr.Label(label="Sentiment")],
|
16 |
+
title="Sentiment Analyzer",
|
17 |
+
description="Enter a text to analyze its sentiment",
|
18 |
+
)
|
19 |
+
|
20 |
+
# Launch the Gradio interface
|
21 |
+
iface.launch()
|