File size: 556 Bytes
da09bc0 | 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 pre-trained model
classifier = pipeline('sentiment-analysis')
# Define the prediction function
def predict_sentiment(text):
results = classifier(text)
return results[0]['label'], results[0]['score']
# Create the Gradio interface
iface = gr.Interface(
fn=predict_sentiment,
inputs="text",
outputs=["text", "number"],
title="Sentiment Analysis",
description="Enter text to classify its sentiment as positive or negative."
)
# Launch the interface
iface.launch() |