savasy/SentimentHistogramForTurkish
11
1from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline2model = AutoModelForSequenceClassification.from_pretrained("savasy/bert-base-turkish-sentiment-cased")3tokenizer = AutoTokenizer.from_pretrained("savasy/bert-base-turkish-sentiment-cased")4sa= pipeline("sentiment-analysis", tokenizer=tokenizer, model=model)5 6def adjust(x):7 if x<0:8 return 2*x+19 return 2*x-110 11def 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 16def get_examples():17 #return [e for e in open("examplesTR.csv").readlines()]18 return ["Bu filmi beğenmedim\n bu filmi beğendim\n ceketin çok güzel\n bugün ne yesek"]19 20import pandas as pd21 22import matplotlib.pyplot as plt23def grfunc(comments):24 df=pd.DataFrame()25 c2=[s.strip() for s in comments.split("\n") if len(s.split())>2]26 df["scores"]= sa2(c2)27 df.plot(kind='hist')28 return plt.gcf()29 30import gradio as gr31 32iface = gr.Interface(33 fn=grfunc, 34 inputs=gr.inputs.Textbox(placeholder="put your sentences line by line", lines=5), 35 outputs="plot",36 examples=get_examples())37iface.launch()38 