openfree commited on
Commit
1c4cd1c
ยท
verified ยท
1 Parent(s): 6d46d5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +106 -115
app.py CHANGED
@@ -529,7 +529,6 @@ class Demo:
529
  try:
530
  async for content in try_claude_api(system_message, claude_messages):
531
  code = content
532
- analysis = analyze_code(code)
533
  yield [
534
  code,
535
  _history,
@@ -544,7 +543,6 @@ class Demo:
544
 
545
  async for content in try_openai_api(openai_messages):
546
  code = content
547
- analysis = analyze_code(code)
548
  yield [
549
  code,
550
  _history,
@@ -579,9 +577,6 @@ class Demo:
579
  return []
580
 
581
 
582
- # theme = gr.themes.Soft()
583
- theme='earneleh/paris'
584
-
585
  # ์˜ˆ์ œ ํ”„๋กฌํ”„ํŠธ
586
  example_prompts = [
587
  "๋งŒ๋…„๋‹ฌ๋ ฅ์„ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”. ๋…„๋„์™€ ์›”์„ ์ž…๋ ฅํ•˜๋ฉด ํ•ด๋‹น ์›”์˜ ๋‹ฌ๋ ฅ์ด ํ‘œ์‹œ๋˜๋Š” ์•ฑ์ž…๋‹ˆ๋‹ค.",
@@ -594,129 +589,125 @@ example_prompts = [
594
  # Demo ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ
595
  demo_instance = Demo()
596
 
597
- with gr.Blocks(css_paths="app.css",theme=theme) as demo:
598
  history = gr.State([])
599
  setting = gr.State({
600
  "system": SystemPrompt,
601
  })
602
 
603
- with ms.Application() as app:
604
- with antd.ConfigProvider():
605
- # Drawer ์ปดํฌ๋„ŒํŠธ๋“ค
606
- with antd.Drawer(open=False, title="code", placement="left", width="750px") as code_drawer:
607
- code_output = legacy.Markdown()
608
-
609
- with antd.Drawer(open=False, title="history", placement="left", width="900px") as history_drawer:
610
- history_output = legacy.Chatbot(show_label=False, flushing=False, height=960, elem_classes="history_chatbot")
611
-
612
- # ๋ฉ”์ธ ์ปจํ…์ธ ๋ฅผ ์œ„ํ•œ Row
613
- with antd.Row(gutter=[32, 12]) as layout:
614
- # ์ขŒ์ธก ํŒจ๋„
615
- with antd.Col(span=24, md=12):
616
- with antd.Flex(vertical=True, gap="middle", wrap=True):
617
- header = gr.HTML(f"""
618
- <div class="left_header">
619
- <img src="data:image/gif;base64,{get_image_base64('mouse.gif')}" width="360px" />
620
- <h1 style="font-size: 18px;">๊ณ ์–‘์ด๋„ ๋ฐœ๋กœ ์ฝ”๋”ฉํ•˜๋Š” 'MOUSE-II'</h2>
621
- <h1 style="font-size: 10px;">ํ”„๋กฌํ”„ํŠธ์— ์›ํ•˜๋Š” ๋‚ด์šฉ์„ ์ž…๋ ฅํ•˜๊ณ  Boost ๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํ”„๋กฌํ”„ํŠธ ์ฆ๊ฐ•์ด ๋จ. -> ๋ฐฐํฌํ•˜๊ธฐ ํด๋ฆญํ•˜๋ฉด ํ—ˆ๊น…ํŽ˜์ด์Šค๋ฅผ ํ†ตํ•ด ์›น์„œ๋น„์Šค๊ฐ€ ๋ฐฐํฌ๋ฉ๋‹ˆ๋‹ค. ๋ฌธ์˜: [email protected] </h2>
622
- </div>
623
- """)
624
-
625
- input = antd.InputTextarea(
626
- size="large",
627
- allow_clear=True,
628
- placeholder=random.choice(DEMO_LIST)['description'],
629
- height=400
630
- )
631
-
632
- gr.Examples(
633
- examples=example_prompts,
634
- inputs=input
635
- )
636
-
637
- with antd.Flex(gap="small", justify="space-between"):
638
- btn = antd.Button("Send", type="primary", size="large")
639
- boost_btn = antd.Button("Boost", type="default", size="large")
640
- clear_btn = antd.Button("ํด๋ฆฌ์–ด", type="default", size="large")
641
-
642
- # ์šฐ์ธก ํŒจ๋„
643
- with antd.Col(span=24, md=12):
644
- with ms.Div(elem_classes="right_panel"):
645
- with antd.Flex(gap="small", elem_classes="setting-buttons"):
646
- codeBtn = antd.Button("๐Ÿง‘โ€๐Ÿ’ป ์ฝ”๋“œ ๋ณด๊ธฐ", type="default")
647
- historyBtn = antd.Button("๐Ÿ“œ ํžˆ์Šคํ† ๋ฆฌ", type="default")
648
-
649
- gr.HTML('<div class="render_header"><span class="header_btn"></span><span class="header_btn"></span><span class="header_btn"></span></div>')
650
-
651
- with antd.Tabs(active_key="empty", render_tab_bar="() => null") as state_tab:
652
- with antd.Tabs.Item(key="empty"):
653
- empty = antd.Empty(description="empty input", elem_classes="right_content")
654
- with antd.Tabs.Item(key="loading"):
655
- loading = antd.Spin(True, tip="coding...", size="large", elem_classes="right_content")
656
-
657
- code_display = gr.Code(language="python", height=400)
658
-
659
- gr.HTML("<h3>๋ฐฐํฌ ์„ค์ •</h3>")
660
- hf_token = gr.Textbox(label="Hugging Face ํ† ํฐ", type="password", placeholder="hf_...")
661
- deploy_btn = antd.Button("๋ฐฐํฌํ•˜๊ธฐ", type="primary", size="large")
662
- deploy_result = gr.HTML(label="๋ฐฐํฌ ๊ฒฐ๊ณผ")
663
-
664
- # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์—ฐ๊ฒฐ
665
- btn.click(
666
- demo_instance.generation_code,
667
- inputs=[input, setting, history],
668
- outputs=[code_output, history, state_tab, code_drawer]
669
- ).then(
670
- lambda code: code,
671
- inputs=[code_output],
672
- outputs=[code_display]
673
- )
674
-
675
- boost_btn.click(
676
- fn=handle_boost,
677
- inputs=[input],
678
- outputs=[input, state_tab]
679
  )
680
-
681
- clear_btn.click(
682
- demo_instance.clear_history,
683
- inputs=[],
684
- outputs=[history]
685
  )
686
-
687
- deploy_btn.click(
688
- fn=lambda code, token: deploy_to_huggingface(remove_code_block(code), token) if code else "์ฝ”๋“œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.",
689
- inputs=[code_output, hf_token],
690
- outputs=[deploy_result]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
691
  )
 
 
 
692
 
693
- codeBtn.click(
694
- lambda: gr.update(open=True),
695
- inputs=[],
696
- outputs=[code_drawer]
697
- )
 
 
 
 
 
 
 
 
698
 
699
- code_drawer.close(
700
- lambda: gr.update(open=False),
701
- inputs=[],
702
- outputs=[code_drawer]
703
- )
704
-
705
- historyBtn.click(
706
- history_render,
707
- inputs=[history],
708
- outputs=[history_drawer, history_output]
709
- )
710
-
711
- history_drawer.close(
712
- lambda: gr.update(open=False),
713
- inputs=[],
714
- outputs=[history_drawer]
715
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
716
 
717
  if __name__ == "__main__":
718
  try:
719
- demo_instance = Demo()
720
  demo.queue(default_concurrency_limit=20).launch(ssr_mode=False)
721
  except Exception as e:
722
  print(f"Initialization error: {e}")
 
529
  try:
530
  async for content in try_claude_api(system_message, claude_messages):
531
  code = content
 
532
  yield [
533
  code,
534
  _history,
 
543
 
544
  async for content in try_openai_api(openai_messages):
545
  code = content
 
546
  yield [
547
  code,
548
  _history,
 
577
  return []
578
 
579
 
 
 
 
580
  # ์˜ˆ์ œ ํ”„๋กฌํ”„ํŠธ
581
  example_prompts = [
582
  "๋งŒ๋…„๋‹ฌ๋ ฅ์„ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”. ๋…„๋„์™€ ์›”์„ ์ž…๋ ฅํ•˜๋ฉด ํ•ด๋‹น ์›”์˜ ๋‹ฌ๋ ฅ์ด ํ‘œ์‹œ๋˜๋Š” ์•ฑ์ž…๋‹ˆ๋‹ค.",
 
589
  # Demo ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ
590
  demo_instance = Demo()
591
 
592
+ with gr.Blocks(css="body {background-color: #f7f7f7;}", theme=gr.themes.Soft()) as demo:
593
  history = gr.State([])
594
  setting = gr.State({
595
  "system": SystemPrompt,
596
  })
597
 
598
+ # ๋ฉ”์ธ ๋ ˆ์ด์•„์›ƒ
599
+ with gr.Row():
600
+ # ์ขŒ์ธก ํŒจ๋„
601
+ with gr.Column(scale=1):
602
+ gr.HTML("""
603
+ <div style="text-align: center; margin-bottom: 10px;">
604
+ <h1 style="margin-bottom: 0px;">MOUSE</h1>
605
+ <p>๊ณ ์–‘์ด๋„ ๋ฐœ๋กœ ์ฝ”๋”ฉํ•˜๋Š” 'MOUSE-II'</p>
606
+ </div>
607
+ """)
608
+
609
+ input_text = gr.Textbox(
610
+ label="์›ํ•˜๋Š” ์•ฑ ์„ค๋ช…์„ ์ž…๋ ฅํ•˜์„ธ์š”",
611
+ placeholder=random.choice(DEMO_LIST)['description'],
612
+ lines=12,
613
+ max_lines=15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
614
  )
615
+
616
+ gr.Examples(
617
+ examples=example_prompts,
618
+ inputs=input_text
 
619
  )
620
+
621
+ with gr.Row():
622
+ generate_btn = gr.Button("์ƒ์„ฑํ•˜๊ธฐ", variant="primary")
623
+ boost_btn = gr.Button("Boost", variant="secondary")
624
+ clear_btn = gr.Button("ํด๋ฆฌ์–ด", variant="secondary")
625
+
626
+ with gr.Accordion("์—ญ๋Œ€ ํ”„๋กฌํ”„ํŠธ", open=False):
627
+ history_btn = gr.Button("์ด์ „ ๊ธฐ๋ก ๋ณด๊ธฐ")
628
+ history_output = gr.Chatbot(
629
+ show_label=False,
630
+ height=400,
631
+ visible=False
632
+ )
633
+
634
+ # ์šฐ์ธก ํŒจ๋„
635
+ with gr.Column(scale=1):
636
+ with gr.Tabs():
637
+ with gr.TabItem("์ฝ”๋“œ"):
638
+ with gr.Row():
639
+ loading_indicator = gr.HTML('<div id="loading" style="display:none; text-align:center;"><p>์ฝ”๋“œ ์ƒ์„ฑ ์ค‘...</p></div>')
640
+
641
+ code_output = gr.Code(
642
+ language="python",
643
+ label="์ƒ์„ฑ๋œ ์ฝ”๋“œ",
644
+ value="",
645
+ lines=17,
646
+ height=400
647
+ )
648
+
649
+ with gr.TabItem("๋ถ„์„"):
650
+ code_analysis = gr.HTML(label="์ฝ”๋“œ ๋ถ„์„")
651
+
652
+ gr.HTML("<h3>๋ฐฐํฌ ์„ค์ •</h3>")
653
+ hf_token = gr.Textbox(
654
+ label="Hugging Face ํ† ํฐ",
655
+ type="password",
656
+ placeholder="hf_..."
657
  )
658
+
659
+ deploy_btn = gr.Button("๋ฐฐํฌํ•˜๊ธฐ", variant="primary")
660
+ deploy_result = gr.HTML(label="๋ฐฐํฌ ๊ฒฐ๊ณผ")
661
 
662
+ # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ
663
+ async def generate_code_wrapper(query, setting, history):
664
+ loading_indicator.update('<div id="loading" style="display:block; text-align:center;"><p>์ฝ”๋“œ ์ƒ์„ฑ ์ค‘...</p></div>')
665
+
666
+ result = None
667
+ analysis = ""
668
+
669
+ async for output in demo_instance.generation_code(query, setting, history):
670
+ result = output[0] # ์ฝ”๋“œ ์ถœ๋ ฅ
671
+ code_analysis_html = analyze_code(result)
672
+
673
+ loading_indicator.update('<div id="loading" style="display:none;"></div>')
674
+ return result, code_analysis_html
675
 
676
+ generate_btn.click(
677
+ fn=generate_code_wrapper,
678
+ inputs=[input_text, setting, history],
679
+ outputs=[code_output, code_analysis]
680
+ )
681
+
682
+ boost_btn.click(
683
+ fn=handle_boost,
684
+ inputs=[input_text],
685
+ outputs=[input_text, loading_indicator]
686
+ )
687
+
688
+ clear_btn.click(
689
+ fn=demo_instance.clear_history,
690
+ inputs=[],
691
+ outputs=[history]
692
+ )
693
+
694
+ deploy_btn.click(
695
+ fn=lambda code, token: deploy_to_huggingface(remove_code_block(code), token) if code else "์ฝ”๋“œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.",
696
+ inputs=[code_output, hf_token],
697
+ outputs=[deploy_result]
698
+ )
699
+
700
+ def toggle_history(history):
701
+ return gr.update(visible=True), history
702
+
703
+ history_btn.click(
704
+ fn=toggle_history,
705
+ inputs=[history],
706
+ outputs=[history_output, history_output]
707
+ )
708
 
709
  if __name__ == "__main__":
710
  try:
 
711
  demo.queue(default_concurrency_limit=20).launch(ssr_mode=False)
712
  except Exception as e:
713
  print(f"Initialization error: {e}")