File size: 594 Bytes
884c2a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
from transformers import pipeline

# Load a sentiment analysis model
classifier = pipeline("sentiment-analysis")

# Define the function for sentiment analysis
def analyze_sentiment(text):
    result = classifier(text)
    return result

# Create a Gradio interface
iface = gr.Interface(
    fn=analyze_sentiment,
    inputs=gr.inputs.Textbox(lines=2, placeholder="Type your text here..."),
    outputs=gr.outputs.Label(num_top_classes=1),
    title="Sentiment Analysis",
    description="Enter a sentence to analyze its sentiment."
)

# Launch the Gradio app
iface.launch()