File size: 2,999 Bytes
72b06f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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


def app_chat():
            
    # Chat code (user input, agent responses, etc.)
    if "messages" not in st.session_state:
        st.session_state.messages = []
    
    for message in st.session_state.messages:
        with st.chat_message(message["role"]):
            st.markdown(message["content"])
    
    with st.chat_message("assistant"):
        st.markdown("Hello there! How can I assist you today?")
    
    if user_message := st.chat_input("Enter message"):
        st.chat_message("user").markdown(user_message)
        st.session_state.messages.append({"role": "user", "content": user_message})
    
        selected_tools = [tool_loader.tools[idx] for idx, checkbox in enumerate(tool_checkboxes) if checkbox]
        # Handle submission with the selected inference URL
        response = handle_submission(user_message, selected_tools, url_endpoint)
    
        with st.chat_message("assistant"):
            if response is None:
                st.warning("The agent's response is None. Please try again. Generate an image of a flying horse.")
            elif isinstance(response, Image.Image):
                st.image(response)
            elif isinstance(response, AudioSegment):
                st.audio(response)
            elif isinstance(response, int):
                st.markdown(response)
            elif isinstance(response, str):
                if "emojified_text" in response:
                    st.markdown(f"{response['emojified_text']}")
                else:
                    st.markdown(response)
            elif isinstance(response, list):
                for item in response:
                    st.markdown(item)  # Assuming the list contains strings
            elif isinstance(response, pd.DataFrame):
                st.dataframe(response)
            elif isinstance(response, pd.Series):
                st.table(response.iloc[0:10])
            elif isinstance(response, dict):
                st.json(response)
            elif isinstance(response, st.graphics_altair.AltairChart):
                st.altair_chart(response)
            elif isinstance(response, st.graphics_bokeh.BokehChart):
                st.bokeh_chart(response)
            elif isinstance(response, st.graphics_graphviz.GraphvizChart):
                st.graphviz_chart(response)
            elif isinstance(response, st.graphics_plotly.PlotlyChart):
                st.plotly_chart(response)
            elif isinstance(response, st.graphics_pydeck.PydeckChart):
                st.pydeck_chart(response)
            elif isinstance(response, matplotlib.figure.Figure):
                st.pyplot(response)
            elif isinstance(response, streamlit.graphics_vega_lite.VegaLiteChart):
                st.vega_lite_chart(response)
            else:
                st.warning("Unrecognized response type. Please try again. e.g. Generate an image of a flying horse.")
    
        st.session_state.messages.append({"role": "assistant", "content": response})