File size: 856 Bytes
748571c
 
 
e4be09f
 
748571c
e4be09f
748571c
e4be09f
 
748571c
e4be09f
 
 
 
 
 
 
 
 
748571c
e4be09f
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr
from transformers import pipeline

# Initialize the Hugging Face sentiment-analysis pipeline
sentiment_model = pipeline("sentiment-analysis")

# Define the function that will use the model to predict sentiment
def get_sentiment(text):
    results = sentiment_model(text)
    return results[0]["label"]

# Create the Gradio interface
interface = gr.Interface(
    fn=get_sentiment,
    inputs=gr.inputs.Textbox(placeholder="Type your text here..."),
    outputs="text",
    title="Sentiment Analysis",
    description="Input a piece of text and click the button to analyze sentiment.",
    theme="huggingface"  # This applies Hugging Face theme to the interface
)

# The interface can be launched directly in Python
# interface.launch()

# To deploy to Hugging Face Spaces, save the interface as an object called 'demo'
demo = interface