Anshini commited on
Commit
b1302ea
ยท
verified ยท
1 Parent(s): a05cd8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -33
app.py CHANGED
@@ -235,41 +235,15 @@ st.markdown("""
235
  st.title("๐Ÿง MitraVerse")
236
 
237
  # st.set_page_config(page_title="Tool Button Executor", layout="wide")
238
- st.title("๐Ÿง  Agent Tools โ€“ Run by Button")
239
 
240
  # User input for all tools
241
- user_prompt = st.text_area("๐Ÿ“ Enter your prompt / code / query:")
242
 
243
  # Columns for button layout
244
  col1, col2, col3 = st.columns(3)
245
 
246
- # Execution section
247
- if col1.button("โš™๏ธ Run Python Code"):
248
- if user_prompt:
249
- with st.spinner("Executing your Python code..."):
250
- result = execute_python_code.invoke({"code": user_prompt})
251
- st.success("โœ… Output:")
252
- st.code(result, language="python")
253
- else:
254
- st.warning("Please enter Python code in the input box.")
255
-
256
- if col2.button("๐ŸŒ Web Search"):
257
- if user_prompt:
258
- with st.spinner("Searching the web..."):
259
- result = web_search.invoke({"query": user_prompt})
260
- st.success("๐Ÿ”Ž Search Result:")
261
- st.write(result)
262
- else:
263
- st.warning("Please enter a search query.")
264
-
265
- if col3.button("๐Ÿง  Deep Think"):
266
- if user_prompt:
267
- with st.spinner("Thinking deeply..."):
268
- result = deep_think.invoke({"prompt": user_prompt})
269
- st.success("๐Ÿง  Reasoned Output:")
270
- st.write(result)
271
- else:
272
- st.warning("Please enter a prompt.")
273
 
274
  # Initialize session
275
  if "thread_id" not in st.session_state:
@@ -294,13 +268,54 @@ if "latest_code" in st.session_state:
294
 
295
 
296
  # Custom Chat Input Box UI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
  with st.container():
298
  with st.form("chat_form", clear_on_submit=True):
299
  st.markdown('<div id="floating-container">', unsafe_allow_html=True)
300
  st.markdown('</div>', unsafe_allow_html=True)
301
- user_input = st.text_input("Ask me", label_visibility="collapsed", placeholder="Ask me Anything")
302
 
303
- submitted = st.form_submit_button(label = "Send")
 
304
 
305
  if submitted and user_input:
306
  st.session_state.chat_history.append(HumanMessage(content=user_input))
@@ -323,16 +338,51 @@ with st.container():
323
  st.session_state.chat_history.append(
324
  AIMessage(content="**๐Ÿงช Code Execution Result:**\n\n" + result["execution_result"])
325
  )
326
-
327
  if result.get("explanation"):
328
  st.session_state.latest_explanation = result["explanation"]
329
  st.session_state.chat_history.append(
330
- # AIMessage(content="**๐Ÿ” Code Explanation:**\n\n" + result["explanation"])
331
  AIMessage(content="**๐Ÿ” Code Explanation:**\n\n```\n" + result["explanation"] + "\n```")
332
  )
333
 
334
  elif result.get("messages"):
335
  st.session_state.chat_history.append(result["messages"][-1])
 
336
  st.rerun()
337
  st.markdown("<script>window.scrollTo(0, document.body.scrollHeight);</script>", unsafe_allow_html=True)
338
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  st.title("๐Ÿง MitraVerse")
236
 
237
  # st.set_page_config(page_title="Tool Button Executor", layout="wide")
238
+ # st.title("๐Ÿง  Agent Tools โ€“ Run by Button")
239
 
240
  # User input for all tools
241
+ # user_prompt = st.text_area("๐Ÿ“ Enter your prompt / code / query:")
242
 
243
  # Columns for button layout
244
  col1, col2, col3 = st.columns(3)
245
 
246
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
 
248
  # Initialize session
249
  if "thread_id" not in st.session_state:
 
268
 
269
 
270
  # Custom Chat Input Box UI
271
+ # with st.container():
272
+ # with st.form("chat_form", clear_on_submit=True):
273
+ # st.markdown('<div id="floating-container">', unsafe_allow_html=True)
274
+ # st.markdown('</div>', unsafe_allow_html=True)
275
+ # user_input = st.text_input("Ask me", label_visibility="collapsed", placeholder="Ask me Anything")
276
+
277
+ # submitted = st.form_submit_button(label = "Send")
278
+
279
+ # if submitted and user_input:
280
+ # st.session_state.chat_history.append(HumanMessage(content=user_input))
281
+
282
+ # config = {"configurable": {"thread_id": st.session_state.thread_id}}
283
+ # state_input = {
284
+ # "messages": st.session_state.chat_history,
285
+ # "input": user_input,
286
+ # }
287
+
288
+ # result = graph.invoke(state_input, config=config)
289
+
290
+ # if result.get("code"):
291
+ # st.session_state.latest_code = result["code"]
292
+ # st.session_state.chat_history.append(
293
+ # AIMessage(content="**๐Ÿ’ป Generated Code:**\n\n```python\n" + result["code"] + "\n```")
294
+ # )
295
+
296
+ # if result.get("execution_result"):
297
+ # st.session_state.chat_history.append(
298
+ # AIMessage(content="**๐Ÿงช Code Execution Result:**\n\n" + result["execution_result"])
299
+ # )
300
+
301
+ # if result.get("explanation"):
302
+ # st.session_state.latest_explanation = result["explanation"]
303
+ # st.session_state.chat_history.append(
304
+ # # AIMessage(content="**๐Ÿ” Code Explanation:**\n\n" + result["explanation"])
305
+ # AIMessage(content="**๐Ÿ” Code Explanation:**\n\n```\n" + result["explanation"] + "\n```")
306
+ # )
307
+
308
+ # elif result.get("messages"):
309
+ # st.session_state.chat_history.append(result["messages"][-1])
310
+ # st.rerun()
311
+ # st.markdown("<script>window.scrollTo(0, document.body.scrollHeight);</script>", unsafe_allow_html=True)
312
  with st.container():
313
  with st.form("chat_form", clear_on_submit=True):
314
  st.markdown('<div id="floating-container">', unsafe_allow_html=True)
315
  st.markdown('</div>', unsafe_allow_html=True)
 
316
 
317
+ user_input = st.text_input("Ask me", label_visibility="collapsed", placeholder="Ask me Anything")
318
+ submitted = st.form_submit_button(label="Send")
319
 
320
  if submitted and user_input:
321
  st.session_state.chat_history.append(HumanMessage(content=user_input))
 
338
  st.session_state.chat_history.append(
339
  AIMessage(content="**๐Ÿงช Code Execution Result:**\n\n" + result["execution_result"])
340
  )
341
+
342
  if result.get("explanation"):
343
  st.session_state.latest_explanation = result["explanation"]
344
  st.session_state.chat_history.append(
 
345
  AIMessage(content="**๐Ÿ” Code Explanation:**\n\n```\n" + result["explanation"] + "\n```")
346
  )
347
 
348
  elif result.get("messages"):
349
  st.session_state.chat_history.append(result["messages"][-1])
350
+
351
  st.rerun()
352
  st.markdown("<script>window.scrollTo(0, document.body.scrollHeight);</script>", unsafe_allow_html=True)
353
 
354
+ # ================================
355
+ # TOOL BUTTONS SECTION
356
+ # ================================
357
+ col1, col2, col3 = st.columns(3)
358
+
359
+ user_prompt = st.session_state.get("latest_code", "") or user_input # fallback to user_input if needed
360
+
361
+ with st.container():
362
+ if col1.button("โš™๏ธ Run Python Code"):
363
+ if user_prompt:
364
+ with st.spinner("Executing your Python code..."):
365
+ result = execute_python_code.invoke({"code": user_prompt})
366
+ st.success("โœ… Output:")
367
+ st.code(result, language="python")
368
+ else:
369
+ st.warning("Please enter Python code in the input box.")
370
+
371
+ if col2.button("๐ŸŒ Web Search"):
372
+ if user_prompt:
373
+ with st.spinner("Searching the web..."):
374
+ result = web_search.invoke({"query": user_prompt})
375
+ st.success("๐Ÿ”Ž Search Result:")
376
+ st.write(result)
377
+ else:
378
+ st.warning("Please enter a search query.")
379
+
380
+ if col3.button("๐Ÿง  Deep Think"):
381
+ if user_prompt:
382
+ with st.spinner("Thinking deeply..."):
383
+ result = deep_think.invoke({"prompt": user_prompt})
384
+ st.success("๐Ÿง  Reasoned Output:")
385
+ st.write(result)
386
+ else:
387
+ st.warning("Please enter a prompt.")
388
+