import streamlit as st from dotenv import load_dotenv import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from model import LLMChain_test from multipleCommentOutputs import multiple_comment_outputs with st.sidebar: st.title('🤗💬 LLM summary') st.markdown(''' ## About This app is an LLM-powered chatbot built using: - [Streamlit](https://streamlit.io/) - [LangChain](https://python.langchain.com/) - [OpenAI](https://platform.openai.com/docs/models) LLM model ''') # add_vertical_space(5) st.write('Made by bin') def main(): st.header("Starbucks Summary") option = st.selectbox("Choose mode", ['single','multiple'], index=0, key=None) print(option) if option == 'single': query = st.text_input("Input a piece of text to provide an evaluation:") if query: st.write(LLMChain_test(query)) else: query = st.text_input("Input the number of items that require an evaluation (multiples of 10):") if query: csv_file = 'example.csv' res = multiple_comment_outputs(csv_file,int(query)) data = res.get('data',[]) positive = res.get('positive','') negative = res.get('negative','') neutral = res.get('neutral','') summary = res.get('summary','') pd_input = [] for item in data: for _,value in item.items(): pd_input.append([value.get('comment',''),value.get('emotion',''),value.get('description','')]) df = pd.DataFrame(pd_input, columns=['comment', 'emotion', 'description']) st.table(df) value = [positive, negative, neutral] labels = ["positive", "negative" ,"neutral"] pd_image_input = {'emotion':labels,'value':value} df_image = pd.DataFrame(pd_image_input, columns=['emotion', 'value']) # seaborn 调色板 pal_ = list(sns.color_palette(palette='plasma_r',n_colors=len(labels)).as_hex()) # 饼图 fig = plt.figure(figsize=(10, 10)) plt.rcParams.update({'font.size': 16}) plt.pie(df_image.value, labels=df_image.emotion, colors=pal_, autopct='%1.1f%%', pctdistance=0.9) plt.legend(bbox_to_anchor=(1, 1), loc=2, frameon=False) st.pyplot(fig) # 增加总结信息 st.write(summary) if __name__ == '__main__': load_dotenv() main()