File size: 612 Bytes
b19f251
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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()