2022-09-15 23:24:10 +08:00
|
|
|
import gradio as gr
|
2020-09-16 01:37:02 +08:00
|
|
|
import nltk
|
|
|
|
from nltk.sentiment.vader import SentimentIntensityAnalyzer
|
2022-01-21 21:44:12 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-04-22 09:33:23 +08:00
|
|
|
demo = gr.Interface(
|
2022-09-15 23:24:10 +08:00
|
|
|
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
|
|
|
|
2022-09-15 23:24:10 +08:00
|
|
|
demo.launch()
|