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

# Load sentiment analysis model
sentiment_pipeline = pipeline("text-classification", model="tabularisai/multilingual-sentiment-analysis")

# Function for sentiment analysis
def sentiment_analysis(text):
    result = sentiment_pipeline(text)[0]
    return f"Label: {result['label']}, Confidence: {round(result['score'], 4)}"

# Gradio Interface
demo = gr.Interface(fn=sentiment_analysis, 
                    inputs=gr.Textbox(label="Enter Text"), 
                    outputs=gr.Textbox(label="Sentiment Output"), 
                    title="Multilingual Sentiment Analysis")

# Launch app locally
demo.launch()