shrirangphadke's picture
Update app.py
4066f8e verified
raw
history blame
692 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=gr.inputs.Textbox(lines=5, label="Enter Text"),
outputs="html"
)
iface.launch()