gradio/demo/sentiment_analysis/run.py

20 lines
514 B
Python
Raw Normal View History

import gradio as gr
2020-09-16 01:37:02 +08:00
import nltk
from nltk.sentiment.vader import SentimentIntensityAnalyzer
nltk.download("vader_lexicon")
2020-09-16 01:37:02 +08:00
sid = SentimentIntensityAnalyzer()
def sentiment_analysis(text):
2020-09-17 07:43:37 +08:00
scores = sid.polarity_scores(text)
del scores["compound"]
return scores
2020-09-16 01:37:02 +08:00
demo = gr.Interface(
fn=sentiment_analysis,
inputs=gr.Textbox(placeholder="Enter a positive or negative sentence here..."),
outputs="label",
interpretation="default",
examples=[["This is wonderful!"]])
2020-09-16 01:37:02 +08:00
demo.launch()