shrirangphadke's picture
Update app.py
2e37ab6 verified
raw
history blame
652 Bytes
import gradio as gr
from textblob import TextBlob
def analyze_sentiment(text):
blob = TextBlob(text)
sentiment = blob.sentiment.polarity
if sentiment > 0:
color = "green"
label = "Positive"
elif sentiment < 0:
color = "red"
label = "Negative"
else:
color = "yellow"
label = "Neutral"
return color, label
def sentiment_analysis(text):
color, label = analyze_sentiment(text)
return "<h2 style='color:{}; text-align:center;'>{} Sentiment</h2>".format(color, label)
iface = gr.Interface(
fn=sentiment_analysis,
inputs="text",
outputs="html"
)
iface.launch()