Commit
·
c0d817f
1
Parent(s):
b22d605
update to streamlit
Browse files- app.py +20 -21
- requirements.txt +1 -1
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import
|
2 |
from modules.data_class import DataState
|
3 |
from modules.tools import data_node
|
4 |
from modules.nodes import chatbot_with_tools, human_node, maybe_exit_human_node, maybe_route_to_tools
|
@@ -33,28 +33,27 @@ graph_builder.add_edge(START, "chatbot_healthassistant")
|
|
33 |
# Compile the graph
|
34 |
graph_with_order_tools = graph_builder.compile()
|
35 |
|
36 |
-
#
|
37 |
-
|
38 |
-
|
39 |
-
history = []
|
40 |
|
41 |
-
|
42 |
-
|
|
|
43 |
|
44 |
-
|
45 |
-
for output in graph_with_order_tools.stream(state):
|
46 |
-
response = output["messages"][-1] # Extract the latest chatbot response
|
47 |
-
history.append(("User: " + user_input, "Bot: " + response))
|
48 |
|
49 |
-
|
|
|
|
|
|
|
50 |
|
51 |
-
#
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
theme="compact"
|
57 |
-
)
|
58 |
|
59 |
-
|
60 |
-
|
|
|
|
1 |
+
import streamlit as st
|
2 |
from modules.data_class import DataState
|
3 |
from modules.tools import data_node
|
4 |
from modules.nodes import chatbot_with_tools, human_node, maybe_exit_human_node, maybe_route_to_tools
|
|
|
33 |
# Compile the graph
|
34 |
graph_with_order_tools = graph_builder.compile()
|
35 |
|
36 |
+
# Streamlit UI
|
37 |
+
st.title("LangGraph Chatbot")
|
38 |
+
st.markdown("Chat with an AI-powered health assistant.")
|
|
|
39 |
|
40 |
+
# Initialize session state
|
41 |
+
if "messages" not in st.session_state:
|
42 |
+
st.session_state.messages = []
|
43 |
|
44 |
+
user_input = st.text_input("You:", key="input")
|
|
|
|
|
|
|
45 |
|
46 |
+
if st.button("Send"):
|
47 |
+
if user_input:
|
48 |
+
# Add user input to history
|
49 |
+
st.session_state.messages.append(("User", user_input))
|
50 |
|
51 |
+
# Run LangGraph chatbot
|
52 |
+
state = DataState(messages=st.session_state.messages, data={}, finished=False)
|
53 |
+
for output in graph_with_order_tools.stream(state):
|
54 |
+
response = output["messages"][-1] # Get the last chatbot response
|
55 |
+
st.session_state.messages.append(("Bot", response))
|
|
|
|
|
56 |
|
57 |
+
# Display chat history
|
58 |
+
for sender, message in st.session_state.messages:
|
59 |
+
st.write(f"**{sender}:** {message}")
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
|
2 |
aiohappyeyeballs==2.4.4
|
3 |
aiohttp==3.11.11
|
4 |
aiosignal==1.3.2
|
|
|
1 |
+
streamlit
|
2 |
aiohappyeyeballs==2.4.4
|
3 |
aiohttp==3.11.11
|
4 |
aiosignal==1.3.2
|