CoolFace
Apppublic

Anthos23/hummus

sourceHugging Faceupdated 5y agoView on Hugging Face
1likes
app.py39 linesDownload Raw Back to root
1import streamlit as st2from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer, TextClassificationPipeline3import operator4import matplotlib.pyplot as plt5import pandas as pd6 7def get_sentiment(out):8  d = dict()9  for k in out:10    print(k)11    label = k['label']12    score = k['score']13    d[label] = score14 15  winning_lab = max(d.items(), key=operator.itemgetter(1))[0]16  winning_score = d[winning_lab]17 18  df = pd.DataFrame.from_dict(d, orient = 'index')19  return  df #winning_lab, winning_score20  21model_name =  "mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis"22model = AutoModelForSequenceClassification.from_pretrained(model_name)23tokenizer = AutoTokenizer.from_pretrained(model_name)24 25pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer, return_all_scores=True)26text = st.text_area(f'Ciao! This app uses {model_name}.\nEnter your text  to test it ❤️')27 28 29if text:30  out = pipe(text)31  df = get_sentiment(out[0])32  fig, ax = plt.subplots()33  c = ['#C34A36', '#FFC75F', '#008F7A']34  ax.bar(df.index, df[0], color=c, width=0.4)35  36  st.pyplot(fig)37  38  #st.json(get_sentiment(out[0][0]))39