| import gradio as ui |
| from transformers import pipeline |
|
|
| |
| |
| pipe = pipeline( |
| "text-classification", model="tabularisai/multilingual-sentiment-analysis" |
| ) |
|
|
|
|
| |
| def analyze_sentiment(text): |
| if not text.strip(): |
| return "Please enter some text to analyze." |
|
|
| |
| result = pipe(text)[0] |
|
|
| |
| label = result["label"] |
| score = result["score"] |
|
|
| |
| return f"Prediction: {label} | Confidence: {score:.2%}" |
|
|
|
|
| |
| demo = ui.Interface( |
| fn=analyze_sentiment, |
| inputs=ui.Textbox( |
| lines=3, placeholder="Enter text here...", label="Input Text" |
| ), |
| outputs=ui.Textbox(label="Sentiment Analysis Result"), |
| title="Multilingual Sentiment Analysis", |
| description="Enter text in various languages to detect the underlying sentiment using the `tabularisai/multilingual-sentiment-analysis` model.", |
| examples=[ |
| ["I love this product! It's amazing and works perfectly."], |
| ["Ce produit est terrible, je déteste ça."], |
| ["Este producto es increíble y funciona a la perfección."], |
| ], |
| ) |
|
|
| |
| if __name__ == "__main__": |
| demo.launch() |