File size: 2,559 Bytes
2a0a140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8a453ae
2a0a140
8a453ae
2a0a140
 
 
 
 
 
 
 
8a453ae
2a0a140
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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()