Spaces:
Sleeping
Sleeping
Commit
·
85c04da
1
Parent(s):
a3e41d0
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
|
|
|
|
| 10 |
iface = gr.Interface(
|
| 11 |
-
fn=
|
| 12 |
inputs=gr.Textbox(),
|
| 13 |
outputs=gr.Textbox(),
|
| 14 |
live=True,
|
| 15 |
-
title="
|
| 16 |
-
description="Enter a
|
| 17 |
)
|
| 18 |
|
|
|
|
| 19 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load pre-trained sentiment analysis model
|
| 5 |
+
classifier = pipeline('sentiment-analysis')
|
| 6 |
|
| 7 |
+
# Define the sentiment analysis function
|
| 8 |
+
def analyze_sentiment(text):
|
| 9 |
+
result = classifier(text)
|
| 10 |
+
sentiment = result[0]['label']
|
| 11 |
+
confidence = result[0]['score']
|
| 12 |
+
return f"Sentiment: {sentiment}, Confidence: {confidence:.4f}"
|
| 13 |
|
| 14 |
+
# Create Gradio interface
|
| 15 |
iface = gr.Interface(
|
| 16 |
+
fn=analyze_sentiment,
|
| 17 |
inputs=gr.Textbox(),
|
| 18 |
outputs=gr.Textbox(),
|
| 19 |
live=True,
|
| 20 |
+
title="Sentiment Analysis App",
|
| 21 |
+
description="Enter a sentence, and the model will predict its sentiment.",
|
| 22 |
)
|
| 23 |
|
| 24 |
+
# Launch the Gradio app
|
| 25 |
iface.launch()
|