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

# Load the sentiment analysis pipeline
pipe = pipeline("text-classification", model="nlptown/bert-base-multilingual-uncased-sentiment")

def analyze_sentiment(text):
    # Analyze sentiment using the pipeline
    result = pipe(text)[0]
    label = result['label']
    score = result['score']
    return f"Sentiment: {label}, Score: {score}"

# Create the Gradio interface
text_input = gr.inputs.Textbox(label="Enter Text")
output_text = gr.outputs.Textbox(label="Sentiment Analysis Result")

gr.Interface(fn=analyze_sentiment, inputs=text_input, outputs=output_text).launch()