Spaces:
Build error
Build error
from pyexpat import model | |
from fastai.text.all import * | |
import gradio as gr | |
learner = load_learner('models/sentiment_analysis.pkl') | |
sent_dict = { | |
'pos': 'Positive', | |
'neg': 'Negative', | |
'neutral': 'Neutral' | |
} | |
def predict_sentiment(input_text): | |
map_dict = learner.dls.categorize.vocab.o2i | |
predicted_sentiment = learner.predict(input_text)[0] | |
predicted_confidence = float(list(learner.predict(input_text)[2])[map_dict[learner.predict(input_text)[0]]]) | |
flag = False | |
threshold = 0.5 | |
if predicted_confidence < threshold: | |
predicted_sentiment = 'neutral' | |
flag = True | |
# return{ | |
# 'sentiment': sent_dict[predicted_sentiment], | |
# 'confidence': predicted_confidence, | |
# 'below_threshold': flag, | |
# } | |
return str(sent_dict[predicted_sentiment]) | |
inputs = gr.Textbox() | |
outputs = "text" | |
title = "Sentiment Analysis" | |
description = "Gradio demo for Sentiment Analysis. To use it, simply upload your audio, or click one of the examples to load them. Read more at the links below." | |
gr.Interface(predict_sentiment, inputs, outputs, title=title, description=description).launch() |