File size: 653 Bytes
9e0d191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 pre-trained sentiment analysis model
model = pipeline("sentiment-analysis")

# Define the function to be called by Gradio
def predict(text):
    result = model(text)[0]  # e.g., {'label': 'POSITIVE', 'score': 0.999}
    return f"{result['label']} (score: {result['score']:.2f})"

# Build Gradio interface
demo = gr.Interface(
    fn=predict,
    inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
    outputs="text",
    title="Sentiment Analysis",
    description="This app uses a Hugging Face model to predict sentiment (positive/negative)."
)

# Launch the app
demo.launch()