Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
|
7 |
-
#
|
8 |
def get_sentiment(text):
|
9 |
-
|
10 |
-
return
|
11 |
|
12 |
-
# Gradio
|
13 |
-
interface = gr.Interface(
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Initialize the Hugging Face sentiment-analysis pipeline
|
5 |
+
sentiment_model = pipeline("sentiment-analysis")
|
6 |
|
7 |
+
# Define the function that will use the model to predict sentiment
|
8 |
def get_sentiment(text):
|
9 |
+
results = sentiment_model(text)
|
10 |
+
return results[0]["label"]
|
11 |
|
12 |
+
# Create the Gradio interface
|
13 |
+
interface = gr.Interface(
|
14 |
+
fn=get_sentiment,
|
15 |
+
inputs=gr.inputs.Textbox(placeholder="Type your text here..."),
|
16 |
+
outputs="text",
|
17 |
+
title="Sentiment Analysis",
|
18 |
+
description="Input a piece of text and click the button to analyze sentiment.",
|
19 |
+
theme="huggingface" # This applies Hugging Face theme to the interface
|
20 |
+
)
|
21 |
|
22 |
+
# The interface can be launched directly in Python
|
23 |
+
# interface.launch()
|
24 |
+
|
25 |
+
# To deploy to Hugging Face Spaces, save the interface as an object called 'demo'
|
26 |
+
demo = interface
|