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

# Load the sentiment analysis pipeline
sentiment_pipeline = pipeline("sentiment-analysis")

# Define the function that will use the model
def analyze_sentiment(text):
    result = sentiment_pipeline(text)[0]
    return {"label": result['label'], "score": result['score']}

# Create the Gradio interface
iface = gr.Interface(
    fn=analyze_sentiment,
    inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
    outputs="json",
    title="Sentiment Analysis",
    description="A simple sentiment analysis web app using Hugging Face Transformers."
)

if __name__ == "__main__":
    iface.launch()