-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlit_frontend.py
138 lines (82 loc) · 3.38 KB
/
streamlit_frontend.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import streamlit as st
import yaml
import os
import streamlit as st
import Agents
if "orchestrator" not in st.session_state:
st.session_state.orchestrator = Agents.OrchestratorAgent(model="gemini-1.5-pro-001")
st.session_state.orchestrator.start_conversation()
st.session_state.messages = [] # Initialize chat history
orchestrator = st.session_state.orchestrator
###_____________PAGE CONFIG_____________###
st.set_page_config(
page_title="Agentic Supply Chain Maintenance",
layout="wide",
initial_sidebar_state="expanded",
)
###_____________SIDEBAR_____________###
st.sidebar.title('Agentic SCM')
st.sidebar.header('', divider='blue')
st.sidebar.markdown('Leverage Agents to support with Maintenance and Logistics processes.')
st.sidebar.text("")
st.sidebar.text("")
st.sidebar.text("")
st.sidebar.header('', divider='blue')
uploaded_file = st.sidebar.file_uploader("",type=(["jpg", "jpeg", "png", "svg", "webp"]))
if st.sidebar.button("Analyze Image"):
if not uploaded_file:
st.sidebar.write("Please upload an image first.")
else:
st.chat_message("assistant").write("Thanks for uploading an image. Please wait a moment while I analyze it for you.") # Display directly
# To read file as bytes:
image = uploaded_file.getvalue()
original_filename = uploaded_file.name
filename = os.path.join(os.getcwd(), original_filename)
filename = os.path.basename(filename)
with open(filename, "wb") as f:
f.write(image)
response, response_list = orchestrator.send_message(filename)
out_dict = {
"trace": response_list,
"response": response
}
# st.session_state.messages.append({"role": "assistant", "content": out_dict}) # Add only the agent's response
# st.chat_message("assistant").json(out_dict)
st.chat_message("assistant").write(out_dict['response'])
# Expander for the trace
with st.expander("Show Trace"):
st.json(out_dict['trace'])
###_____________MAIN PAGE_____________###
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
if prompt := st.chat_input():
# st.session_state.messages.append({"role": "user", "content": prompt})
st.chat_message("user").write(prompt)
response, response_list = orchestrator.send_message(prompt)
out_dict = {
"trace": response_list,
"response": response
}
st.chat_message("assistant").write(out_dict['response'])
# Expander for the trace
with st.expander("Show Trace"):
st.json(out_dict['trace'])
st.text("")
# VISIBILITY CONFIG
if "visibility" not in st.session_state:
st.session_state.visibility = "visible"
st.session_state.disabled = False