DrishtiSharma commited on
Commit
2ef9839
·
verified ·
1 Parent(s): 92d35f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -26
app.py CHANGED
@@ -38,6 +38,7 @@ def search(query: str):
38
 
39
  tools = [search, multiply]
40
  tool_map = {tool.name: tool for tool in tools}
 
41
  model_with_tools = model.bind_tools(tools)
42
 
43
  # Define Agent State class
@@ -104,43 +105,38 @@ def render_graph_nx():
104
  st.pyplot(plt)
105
 
106
  # Streamlit UI
107
- st.title("Blah Blah Demo")
108
  st.write("Compare results **with and without human intervention** in the workflow.")
109
 
110
  # Sidebar for configuration
111
  st.sidebar.header("Configuration")
112
  st.session_state['human_loop'] = st.sidebar.checkbox("Enable Human-in-the-Loop", value=False)
113
 
114
- # Input and comparison mode
115
  prompt = st.text_input("Enter your question:", "What is 24 * 365?")
116
  if st.button("Run Workflow"):
117
  st.subheader("Execution Results")
118
 
119
- # Without human-in-the-loop
120
- st.markdown("### Without Human-in-the-Loop")
121
- st.session_state['human_loop'] = False
122
- start_time = time.time()
123
- try:
124
- intermediate_outputs = []
125
- for s in compiled_app.stream({"messages": [prompt]}):
126
- intermediate_outputs.append(s)
127
- st.write("Response:", intermediate_outputs[-1]['messages'][0])
128
- except Exception as e:
129
- st.error(f"Error: {e}")
130
- st.write(f"Execution Time: {time.time() - start_time:.2f} seconds")
131
-
132
- # With human-in-the-loop
133
- st.markdown("### With Human-in-the-Loop")
134
- st.session_state['human_loop'] = True
135
- start_time = time.time()
136
- try:
137
  intermediate_outputs = []
138
- for s in compiled_app.stream({"messages": [prompt]}):
139
- intermediate_outputs.append(s)
140
- st.write("Response:", intermediate_outputs[-1]['messages'][0])
141
- except Exception as e:
142
- st.error(f"Error: {e}")
143
- st.write(f"Execution Time: {time.time() - start_time:.2f} seconds")
 
 
 
 
 
 
 
 
 
144
 
145
  # Display Workflow Graph
146
  st.subheader("Workflow Graph")
 
38
 
39
  tools = [search, multiply]
40
  tool_map = {tool.name: tool for tool in tools}
41
+
42
  model_with_tools = model.bind_tools(tools)
43
 
44
  # Define Agent State class
 
105
  st.pyplot(plt)
106
 
107
  # Streamlit UI
108
+ st.title("LLM Tool Workflow Demo")
109
  st.write("Compare results **with and without human intervention** in the workflow.")
110
 
111
  # Sidebar for configuration
112
  st.sidebar.header("Configuration")
113
  st.session_state['human_loop'] = st.sidebar.checkbox("Enable Human-in-the-Loop", value=False)
114
 
115
+ # Input prompt
116
  prompt = st.text_input("Enter your question:", "What is 24 * 365?")
117
  if st.button("Run Workflow"):
118
  st.subheader("Execution Results")
119
 
120
+ # Run workflow without and with human-in-the-loop
121
+ for human_loop in [False, True]:
122
+ st.markdown(f"### {'With' if human_loop else 'Without'} Human-in-the-Loop")
123
+ st.session_state['human_loop'] = human_loop
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  intermediate_outputs = []
125
+ start_time = time.time()
126
+
127
+ try:
128
+ # Collect intermediate outputs
129
+ for s in compiled_app.stream({"messages": [prompt]}):
130
+ intermediate_outputs.append(s)
131
+
132
+ # Extract final response
133
+ response = intermediate_outputs[-1]['messages'][0].content
134
+ st.write("Response:", response)
135
+ except Exception as e:
136
+ st.error(f"Error: {e}")
137
+
138
+ st.write(f"Execution Time: {time.time() - start_time:.2f} seconds")
139
+ st.write("---")
140
 
141
  # Display Workflow Graph
142
  st.subheader("Workflow Graph")