dominguezdaniel's picture
Create app.py
f908c53 verified
raw
history blame
838 Bytes
from transformers import pipeline
import gradio as gr
# Load the sentiment analysis model
sentiment_analysis = pipeline("sentiment-analysis")
# Define the prediction function
def predict_sentiment(text):
result = sentiment_analysis(text)[0]
label = result['label']
confidence = round(result['score'], 4)
return f"Sentiment: {label}, Confidence: {confidence}"
# Create a Gradio interface
interface = gr.Interface(fn=predict_sentiment,
inputs=gr.inputs.Textbox(lines=2, placeholder="Type your text here..."),
outputs="text",
title="Text Sentiment Analysis",
description="This tool predicts the sentiment of the entered text. Sentiment can be positive, negative, or neutral.")
# Launch the application
interface.launch()