Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
# Load the pre-trained pipeline for sentiment analysis | |
sentiment_analysis = pipeline('text-classification', model='distilbert-base-uncased-finetuned-sst-2-english') | |
# Define the function that will be called by Gradio | |
def analyze_sentiment(input_text): | |
output = sentiment_analysis(input_text) | |
sentiment = output[0]['label'] | |
score = output[0]['score'] | |
return f"Sentiment: {sentiment} (Score: {score:.2f})" | |
# Create the Gradio interface | |
gr.Interface(fn=analyze_sentiment, inputs="text", outputs="text", title="Sentiment Analysis AI").launch() |