seawolf2357 commited on
Commit
5d9fa40
ยท
verified ยท
1 Parent(s): ed6a18e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -56
app.py CHANGED
@@ -324,6 +324,18 @@ def clear_expired_sessions():
324
  conn.commit()
325
  finally:
326
  conn.close()
 
 
 
 
 
 
 
 
 
 
 
 
327
 
328
  with gr.Blocks(css_paths="app.css",theme=theme) as demo:
329
  history = gr.State([])
@@ -331,12 +343,23 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
331
  "system": SystemPrompt,
332
  })
333
 
334
-
335
-
336
  with ms.Application() as app:
337
  with antd.ConfigProvider():
 
 
 
 
 
 
 
 
 
 
 
 
 
338
  # ๋ฉ”์ธ ์ปจํ…์ธ ๋ฅผ ์œ„ํ•œ Row
339
- with antd.Row(gutter=[32, 12]) as layout:
340
  # ์ขŒ์ธก ํŒจ๋„
341
  with antd.Col(span=24, md=8):
342
  with antd.Flex(vertical=True, gap="middle", wrap=True):
@@ -463,27 +486,22 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
463
  outputs=[input]
464
  )
465
 
466
- # Drawer ์ปดํฌ๋„ŒํŠธ๋“ค
467
- with antd.Drawer(open=False, title="code", placement="left", width="750px") as code_drawer:
468
- code_output = legacy.Markdown()
469
-
470
- with antd.Drawer(open=False, title="history", placement="left", width="900px") as history_drawer:
471
- history_output = legacy.Chatbot(show_label=False, flushing=False, height=960, elem_classes="history_chatbot")
472
-
473
  # ์šฐ์ธก ํŒจ๋„
474
  with antd.Col(span=24, md=16):
475
  with ms.Div(elem_classes="right_panel"):
476
  with antd.Flex(gap="small", elem_classes="setting-buttons"):
477
  codeBtn = antd.Button("๐Ÿง‘โ€๐Ÿ’ป view code", type="default")
478
  historyBtn = antd.Button("๐Ÿ“œ history", type="default")
479
- sessionBtn = antd.Button("๐Ÿ“š sessions", type="default") # ์„ธ์…˜ ๋ฒ„ํŠผ ์ถ”๊ฐ€
480
 
481
- # ์„ธ์…˜ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ
482
  sessionBtn.click(
483
  lambda: (gr.update(open=True), update_session_list()),
484
  inputs=[],
485
  outputs=[session_drawer, session_list]
486
  )
 
 
487
 
488
  gr.HTML('<div class="render_header"><span class="header_btn"></span><span class="header_btn"></span><span class="header_btn"></span></div>')
489
  with antd.Tabs(active_key="empty", render_tab_bar="() => null") as state_tab:
@@ -513,58 +531,49 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
513
  print(f"Error executing code: {str(e)}")
514
  return None, gr.update(active_key="empty")
515
 
516
- # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋“ค
517
- execute_btn.click(
518
- fn=execute_code,
519
- inputs=[input],
520
- outputs=[sandbox, state_tab]
521
- )
522
 
523
- codeBtn.click(lambda: gr.update(open=True),
524
- inputs=[], outputs=[code_drawer])
525
- code_drawer.close(lambda: gr.update(
526
- open=False), inputs=[], outputs=[code_drawer])
527
 
528
- historyBtn.click(history_render, inputs=[history], outputs=[history_drawer, history_output])
529
- history_drawer.close(lambda: gr.update(
530
- open=False), inputs=[], outputs=[history_drawer])
 
 
 
531
 
532
-
533
- btn.click(
534
- demo_instance.generation_code, # Demo ์ธ์Šคํ„ด์Šค์˜ ๋ฉ”์„œ๋“œ ์‚ฌ์šฉ
535
- inputs=[input, setting, history],
536
- outputs=[code_output, history, sandbox, state_tab, code_drawer]
537
- )
538
 
539
- clear_btn.click(
540
- demo_instance.clear_history, # Demo ์ธ์Šคํ„ด์Šค์˜ ๋ฉ”์„œ๋“œ ์‚ฌ์šฉ
541
- inputs=[],
542
- outputs=[history]
543
- )
544
 
 
 
 
 
 
545
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
546
 
547
 
548
- with antd.Drawer(open=False, title="Session History", placement="left", width="900px") as session_drawer:
549
- session_list = gr.Dropdown(label="Select Session", choices=[])
550
- session_history = legacy.Chatbot(show_label=False, height=960)
551
-
552
- def update_session_list():
553
- conn = sqlite3.connect('chat_history.db')
554
- c = conn.cursor()
555
- c.execute("SELECT session_id FROM sessions ORDER BY created_at DESC")
556
- sessions = [row[0] for row in c.fetchall()]
557
- conn.close()
558
- return gr.update(choices=sessions)
559
-
560
- def load_session_history(session_id):
561
- history = get_session_history(session_id)
562
- return [[p, r] for p, r, _ in history]
563
-
564
- session_list.change(load_session_history,
565
- inputs=[session_list],
566
- outputs=[session_history])
567
-
568
  if __name__ == "__main__":
569
  init_db()
570
  clear_expired_sessions() # ๋งŒ๋ฃŒ๋œ ์„ธ์…˜ ์ •๋ฆฌ
 
324
  conn.commit()
325
  finally:
326
  conn.close()
327
+
328
+ def update_session_list():
329
+ conn = sqlite3.connect('chat_history.db')
330
+ c = conn.cursor()
331
+ c.execute("SELECT session_id FROM sessions ORDER BY created_at DESC")
332
+ sessions = [row[0] for row in c.fetchall()]
333
+ conn.close()
334
+ return gr.update(choices=sessions)
335
+
336
+ def load_session_history(session_id):
337
+ history = get_session_history(session_id)
338
+ return [[p, r] for p, r, _ in history]
339
 
340
  with gr.Blocks(css_paths="app.css",theme=theme) as demo:
341
  history = gr.State([])
 
343
  "system": SystemPrompt,
344
  })
345
 
 
 
346
  with ms.Application() as app:
347
  with antd.ConfigProvider():
348
+ # Drawer ์ปดํฌ๋„ŒํŠธ๋“ค
349
+ with antd.Drawer(open=False, title="code", placement="left", width="750px") as code_drawer:
350
+ code_output = legacy.Markdown()
351
+
352
+ with antd.Drawer(open=False, title="history", placement="left", width="900px") as history_drawer:
353
+ history_output = legacy.Chatbot(show_label=False, flushing=False, height=960, elem_classes="history_chatbot")
354
+
355
+ with antd.Drawer(open=False, title="Session History", placement="left", width="900px") as session_drawer:
356
+ session_list = gr.Dropdown(label="Select Session", choices=[])
357
+ session_history = legacy.Chatbot(show_label=False, height=960)
358
+
359
+
360
+
361
  # ๋ฉ”์ธ ์ปจํ…์ธ ๋ฅผ ์œ„ํ•œ Row
362
+ with antd.Row(gutter=[32, 12]) as layout:
363
  # ์ขŒ์ธก ํŒจ๋„
364
  with antd.Col(span=24, md=8):
365
  with antd.Flex(vertical=True, gap="middle", wrap=True):
 
486
  outputs=[input]
487
  )
488
 
 
 
 
 
 
 
 
489
  # ์šฐ์ธก ํŒจ๋„
490
  with antd.Col(span=24, md=16):
491
  with ms.Div(elem_classes="right_panel"):
492
  with antd.Flex(gap="small", elem_classes="setting-buttons"):
493
  codeBtn = antd.Button("๐Ÿง‘โ€๐Ÿ’ป view code", type="default")
494
  historyBtn = antd.Button("๐Ÿ“œ history", type="default")
495
+ sessionBtn = antd.Button("๐Ÿ“š sessions", type="default")
496
 
497
+ # ์„ธ์…˜ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ
498
  sessionBtn.click(
499
  lambda: (gr.update(open=True), update_session_list()),
500
  inputs=[],
501
  outputs=[session_drawer, session_list]
502
  )
503
+
504
+
505
 
506
  gr.HTML('<div class="render_header"><span class="header_btn"></span><span class="header_btn"></span><span class="header_btn"></span></div>')
507
  with antd.Tabs(active_key="empty", render_tab_bar="() => null") as state_tab:
 
531
  print(f"Error executing code: {str(e)}")
532
  return None, gr.update(active_key="empty")
533
 
 
 
 
 
 
 
534
 
 
 
 
 
535
 
536
+ # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋“ค
537
+ execute_btn.click(
538
+ fn=execute_code,
539
+ inputs=[input],
540
+ outputs=[sandbox, state_tab]
541
+ )
542
 
543
+ codeBtn.click(lambda: gr.update(open=True),
544
+ inputs=[], outputs=[code_drawer])
545
+ code_drawer.close(lambda: gr.update(
546
+ open=False), inputs=[], outputs=[code_drawer])
 
 
547
 
548
+ historyBtn.click(history_render, inputs=[history], outputs=[history_drawer, history_output])
549
+ history_drawer.close(lambda: gr.update(
550
+ open=False), inputs=[], outputs=[history_drawer])
 
 
551
 
552
+ sessionBtn.click(
553
+ lambda: (gr.update(open=True), update_session_list()),
554
+ inputs=[],
555
+ outputs=[session_drawer, session_list]
556
+ )
557
 
558
+ session_list.change(
559
+ load_session_history,
560
+ inputs=[session_list],
561
+ outputs=[session_history]
562
+ )
563
+
564
+ btn.click(
565
+ demo_instance.generation_code,
566
+ inputs=[input, setting, history],
567
+ outputs=[code_output, history, sandbox, state_tab, code_drawer]
568
+ )
569
+
570
+ clear_btn.click(
571
+ demo_instance.clear_history,
572
+ inputs=[],
573
+ outputs=[history]
574
+ )
575
 
576
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
577
  if __name__ == "__main__":
578
  init_db()
579
  clear_expired_sessions() # ๋งŒ๋ฃŒ๋œ ์„ธ์…˜ ์ •๋ฆฌ