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