Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
sentiment_analyzer = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment")
|
| 5 |
+
|
| 6 |
+
def analyze_sentiment(text):
|
| 7 |
+
result = sentiment_analyzer(text)[0]
|
| 8 |
+
score = result['label']
|
| 9 |
+
return score
|
| 10 |
+
|
| 11 |
+
interface = gr.Interface(
|
| 12 |
+
fn=analyze_sentiment,
|
| 13 |
+
inputs=[
|
| 14 |
+
gr.Textbox(label="Enter your text here", placeholder="Type a sentence or paragraph...", lines=5),
|
| 15 |
+
],
|
| 16 |
+
outputs=gr.Label(label="Predicted Sentiment (1-5 stars)"),
|
| 17 |
+
examples=[
|
| 18 |
+
["I love this product! It's amazing!"],
|
| 19 |
+
["This was the worst experience I've ever had."],
|
| 20 |
+
["The movie was okay, not great but not bad either."],
|
| 21 |
+
["Absolutely fantastic! I would recommend it to everyone."]
|
| 22 |
+
],
|
| 23 |
+
title="Sentiment Analysis App",
|
| 24 |
+
description="This app analyzes the sentiment of the text you provide, showing a score from 1 to 5 stars, where 1 is negative and 5 is positive."
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
interface.launch()
|