xiaosuhu1986 commited on
Commit
c0d817f
·
1 Parent(s): b22d605

update to streamlit

Browse files
Files changed (2) hide show
  1. app.py +20 -21
  2. requirements.txt +1 -1
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import gradio as gr
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
- # Function to handle conversation
37
- def chat_interface(user_input, history):
38
- if not history:
39
- history = []
40
 
41
- # Create the initial state
42
- state = DataState(messages=history, data={}, finished=False)
 
43
 
44
- # Run the chatbot
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
- return "", history # Return empty input and updated chat history
 
 
 
50
 
51
- # Launch Gradio UI
52
- iface = gr.ChatInterface(
53
- fn=chat_interface,
54
- title="LangGraph Chatbot",
55
- description="A chatbot powered by LangGraph and hosted on Hugging Face.",
56
- theme="compact"
57
- )
58
 
59
- if __name__ == "__main__":
60
- iface.launch()
 
 
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
- gradio
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