Team Ai
Apppublic

savasy/SentimentHistogramForEnglish

sourceHugging Faceupdated 5y agoView on Hugging Face
2likes
app.py31 linesDownload Raw Back to root
1from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline2sa= pipeline("sentiment-analysis")3 4def adjust(x):5  if x<0:6    return 2*x+17  return 2*x-18 9def 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  14import pandas as pd15 16import matplotlib.pyplot as plt17def 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 24import gradio as gr25 26iface = gr.Interface(27  fn=grfunc, 28  inputs=gr.inputs.Textbox(placeholder="put your sentences line by line", lines=5), 29  outputs="plot")30iface.launch()31