Update app.py
Browse files
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(
|
| 598 |
history = gr.State([])
|
| 599 |
setting = gr.State({
|
| 600 |
"system": SystemPrompt,
|
| 601 |
})
|
| 602 |
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 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 ๋ฒํผ ํด๋ฆญ์ ํ๋กฌํํธ ์ฆ๊ฐ์ด ๋จ. -> ๋ฐฐํฌํ๊ธฐ ํด๋ฆญํ๋ฉด ํ๊น
ํ์ด์ค๋ฅผ ํตํด ์น์๋น์ค๊ฐ ๋ฐฐํฌ๋ฉ๋๋ค. ๋ฌธ์: arxivgpt@gmail.com </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 |
-
|
| 682 |
-
|
| 683 |
-
inputs=
|
| 684 |
-
outputs=[history]
|
| 685 |
)
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 691 |
)
|
|
|
|
|
|
|
|
|
|
| 692 |
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 698 |
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 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}")
|