savasy commited on
Commit
a2c17a2
1 Parent(s): 42c5a8e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
2
+ sa= pipeline("sentiment-analysis")
3
+
4
+ def adjust(x):
5
+ if x<0:
6
+ return 2*x+1
7
+ return 2*x-1
8
+
9
+ def sa2(s):
10
+ res= sa(s)
11
+ return [adjust(-1*r['score']) if r['label']=='negative' else adjust(r['score']) for r in res ]
12
+
13
+
14
+ import pandas as pd
15
+
16
+ import matplotlib.pyplot as plt
17
+ def grfunc(comments):
18
+ df=pd.DataFrame()
19
+ c2=[s.strip() for s in comments.split("\n") if len(s.split())>2]
20
+ df["scores"]= sa2(c2)
21
+ df.plot(kind='hist')
22
+ return plt.gcf()
23
+
24
+ import gradio as gr
25
+
26
+ iface = gr.Interface(
27
+ fn=grfunc,
28
+ inputs=gr.inputs.Textbox(placeholder="put your sentences line by line", lines=5),
29
+ outputs="plot")
30
+ iface.launch()