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

# Load the model from Hugging Face
classifier = pipeline("sentiment-analysis")

# Define the function to make predictions
def predict(text):
    result = classifier(text)[0]
    return f"{result['label']} ({result['score']:.2f})"

# Create the Gradio interface
gr.Interface(
    fn=predict,
    inputs=gr.Textbox(label="Enter Text"),
    outputs=gr.Label(label="Sentiment"),
    title="Sentiment Analysis with DistilBERT",
    description="Classify text as positive or negative.",
).launch()