vindruid commited on
Commit
3ab62c4
·
unverified ·
1 Parent(s): 30dffe0

clean code

Browse files
Files changed (1) hide show
  1. app.py +4 -35
app.py CHANGED
@@ -263,7 +263,7 @@ No need to say if the chart cannot be displayed, because it already handled in t
263
  You already have access to a DataFrame called `df`
264
  """)
265
 
266
-
267
  def assistant(state: AgentState) -> AgentState:
268
 
269
  schema_output = describe_schema.invoke(df)
@@ -438,38 +438,7 @@ def build_graph():
438
  react_graph = build_graph()
439
  config = {"configurable": {"thread_id": 123, "session": 100}}
440
 
441
- # --- Gradio UI ---
442
- def respond(message, chat_history):
443
- chat_history = []
444
- res = react_graph.invoke(
445
- {"messages": [HumanMessage(content=message)]}
446
- , config=config)
447
-
448
- for msg in res["messages"]:
449
- msg.pretty_print()
450
- if isinstance(msg, HumanMessage):
451
- chat_history.append({"role": "user", "content": msg.content})
452
-
453
- if isinstance(msg, AIMessage):
454
- ai_response = msg.content
455
- chat_history.append({"role": "assistant", "content": ai_response})
456
-
457
- if isinstance(msg, ToolMessage):
458
- if msg.name == "generate_plot_code":
459
- plot_result = generate_plot_from_code(msg.content)
460
- chat_history.append({"role": "assistant", "content": gr.Plot(plot_result)})
461
- chat_history.append({"role": "assistant", "content": res["plots"][-1].get("interpretation", " ")})
462
-
463
- if msg.name == "enhance_plot_code":
464
- plot_result = generate_plot_from_code(msg.content)
465
- chat_history.append({"role": "assistant", "content": gr.Plot(plot_result)})
466
-
467
- time.sleep(1)
468
- return "", chat_history
469
-
470
-
471
- my_theme = gr.Theme.from_hub("NoCrypt/miku")
472
-
473
  def to_snake_case(name):
474
  return name.lower().replace(' ', '_').replace('-', '_')
475
 
@@ -576,7 +545,6 @@ def refresh_graph():
576
  global config
577
  config = {"configurable": {"thread_id": str(uuid.uuid4()), "session": str(uuid.uuid4())}}
578
 
579
- # --- Gradio UI ---
580
  def respond(message, chat_history):
581
  chat_history = []
582
  res = react_graph.invoke(
@@ -604,7 +572,8 @@ def respond(message, chat_history):
604
  time.sleep(1)
605
  return "", chat_history
606
 
607
- # Layout
 
608
  with gr.Blocks(theme=my_theme) as demo:
609
  demo.load(refresh_graph, inputs=None, outputs=None)
610
 
 
263
  You already have access to a DataFrame called `df`
264
  """)
265
 
266
+ #--- Assistant Functions ---
267
  def assistant(state: AgentState) -> AgentState:
268
 
269
  schema_output = describe_schema.invoke(df)
 
438
  react_graph = build_graph()
439
  config = {"configurable": {"thread_id": 123, "session": 100}}
440
 
441
+ # --- Data Exploration Functions ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
442
  def to_snake_case(name):
443
  return name.lower().replace(' ', '_').replace('-', '_')
444
 
 
545
  global config
546
  config = {"configurable": {"thread_id": str(uuid.uuid4()), "session": str(uuid.uuid4())}}
547
 
 
548
  def respond(message, chat_history):
549
  chat_history = []
550
  res = react_graph.invoke(
 
572
  time.sleep(1)
573
  return "", chat_history
574
 
575
+ # --- Gradio UI ---
576
+ my_theme = gr.Theme.from_hub("NoCrypt/miku")
577
  with gr.Blocks(theme=my_theme) as demo:
578
  demo.load(refresh_graph, inputs=None, outputs=None)
579