Spaces:
Runtime error
Runtime error
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline | |
sa= pipeline("sentiment-analysis") | |
def adjust(x): | |
if x<0: | |
return 2*x+1 | |
return 2*x-1 | |
def sa2(s): | |
res= sa(s) | |
return [adjust(-1*r['score']) if r['label']=='negative' else adjust(r['score']) for r in res ] | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
def grfunc(comments): | |
df=pd.DataFrame() | |
c2=[s.strip() for s in comments.split("\n") if len(s.split())>2] | |
df["scores"]= sa2(c2) | |
df.plot(kind='hist') | |
return plt.gcf() | |
import gradio as gr | |
iface = gr.Interface( | |
fn=grfunc, | |
inputs=gr.inputs.Textbox(placeholder="put your sentences line by line", lines=5), | |
outputs="plot") | |
iface.launch() | |