Spaces:
Build error
Build error
Commit
·
38d0ec4
1
Parent(s):
6c31cfa
Added all UI files
Browse files- .gitattributes +1 -0
- app.py +34 -0
- models/sentiment_analysis.pkl +3 -0
- requirements.txt +1 -0
.gitattributes
CHANGED
@@ -25,3 +25,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
25 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
25 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
models/sentiment_analysis.pkl filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pyexpat import model
|
2 |
+
from fastai.text.all import *
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
learner = load_learner('models/sentiment_analysis.pkl')
|
6 |
+
|
7 |
+
sent_dict = {
|
8 |
+
'pos': 'Positive',
|
9 |
+
'neg': 'Negative',
|
10 |
+
'neutral': 'Neutral'
|
11 |
+
}
|
12 |
+
|
13 |
+
def predict_sentiment(input_text):
|
14 |
+
map_dict = learner.dls.categorize.vocab.o2i
|
15 |
+
predicted_sentiment = learner.predict(input_text)[0]
|
16 |
+
predicted_confidence = float(list(learner.predict(input_text)[2])[map_dict[learner.predict(input_text)[0]]])
|
17 |
+
flag = False
|
18 |
+
threshold = 0.5
|
19 |
+
if predicted_confidence < threshold:
|
20 |
+
predicted_sentiment = 'neutral'
|
21 |
+
flag = True
|
22 |
+
|
23 |
+
# return{
|
24 |
+
# 'sentiment': sent_dict[predicted_sentiment],
|
25 |
+
# 'confidence': predicted_confidence,
|
26 |
+
# 'below_threshold': flag,
|
27 |
+
# }
|
28 |
+
return str(sent_dict[predicted_sentiment])
|
29 |
+
|
30 |
+
inputs = gr.Textbox()
|
31 |
+
outputs = "text"
|
32 |
+
title = "Sentiment Analysis"
|
33 |
+
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."
|
34 |
+
gr.Interface(predict_sentiment, inputs, outputs, title=title, description=description).launch()
|
models/sentiment_analysis.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:afbd42cd88301e868a99dea9cac833209c8d0fcc83fe3c9fae8497fc65b93d7e
|
3 |
+
size 231439231
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
fastai
|