Spaces:
Running
Running
feat: support two tabs
Browse files
app.py
CHANGED
|
@@ -362,7 +362,7 @@ def select_example(example: dict):
|
|
| 362 |
|
| 363 |
def generate_code(query: str):
|
| 364 |
if not query:
|
| 365 |
-
return None, None, None, gr.update(active_key="empty")
|
| 366 |
|
| 367 |
print("Starting code generation with query:", query)
|
| 368 |
messages = [{
|
|
@@ -419,6 +419,7 @@ def generate_code(query: str):
|
|
| 419 |
code_output: content,
|
| 420 |
reasoning_output: reasoning_content + "\n",
|
| 421 |
state_tab: gr.update(active_key="loading"),
|
|
|
|
| 422 |
}
|
| 423 |
elif 'message' in choice:
|
| 424 |
message_data = choice['message']
|
|
@@ -433,6 +434,7 @@ def generate_code(query: str):
|
|
| 433 |
reasoning_output: reasoning_content + "\n",
|
| 434 |
sandbox: send_to_sandbox(html_content),
|
| 435 |
state_tab: gr.update(active_key="render"),
|
|
|
|
| 436 |
}
|
| 437 |
|
| 438 |
# If successful, break out of retry loop
|
|
@@ -473,21 +475,25 @@ css = """
|
|
| 473 |
}
|
| 474 |
|
| 475 |
.reasoning-box {
|
| 476 |
-
height:
|
| 477 |
overflow-y: auto;
|
| 478 |
-
padding: 8px 12px;
|
| 479 |
background-color: #f5f5f5;
|
| 480 |
border-radius: 4px;
|
| 481 |
margin-bottom: 12px;
|
| 482 |
-
font-family:
|
| 483 |
-
font-size:
|
| 484 |
line-height: 1.2;
|
| 485 |
white-space: pre-wrap;
|
| 486 |
word-break: break-word;
|
| 487 |
width: 100%;
|
| 488 |
box-sizing: border-box;
|
|
|
|
| 489 |
}
|
| 490 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 491 |
.reasoning-box::-webkit-scrollbar {
|
| 492 |
width: 6px;
|
| 493 |
}
|
|
@@ -506,7 +512,19 @@ css = """
|
|
| 506 |
background: #555;
|
| 507 |
}
|
| 508 |
|
| 509 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 510 |
scroll-behavior: smooth;
|
| 511 |
}
|
| 512 |
"""
|
|
@@ -514,10 +532,16 @@ css = """
|
|
| 514 |
def scroll_to_bottom():
|
| 515 |
return """
|
| 516 |
function() {
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 521 |
}
|
| 522 |
"""
|
| 523 |
|
|
@@ -580,26 +604,24 @@ with gr.Blocks(css=css) as demo, ms.Application(), antdx.XProvider():
|
|
| 580 |
)
|
| 581 |
chatbot.welcome_prompt_select(fn=prompt_select, outputs=[sender])
|
| 582 |
|
| 583 |
-
with antd.Tabs.Item(key="code", label="Code Playground (
|
| 584 |
with antd.Row(gutter=[32, 12]):
|
| 585 |
with antd.Col(span=12):
|
| 586 |
with antd.Flex(vertical=True, gap="middle"):
|
| 587 |
code_input = antd.InputTextarea(
|
| 588 |
size="large",
|
| 589 |
allow_clear=True,
|
| 590 |
-
placeholder="Please enter what kind of application you want"
|
| 591 |
)
|
| 592 |
code_btn = antd.Button("Generate Code", type="primary", size="large")
|
| 593 |
-
|
| 594 |
-
label="Thinking Process"
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
code_output = legacy.Markdown()
|
| 601 |
|
| 602 |
-
|
| 603 |
antd.Divider("Examples")
|
| 604 |
|
| 605 |
# Examples
|
|
@@ -646,7 +668,28 @@ with gr.Blocks(css=css) as demo, ms.Application(), antdx.XProvider():
|
|
| 646 |
code_btn.click(
|
| 647 |
generate_code,
|
| 648 |
inputs=[code_input],
|
| 649 |
-
outputs=[code_output, reasoning_output, sandbox, state_tab]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 650 |
)
|
| 651 |
|
| 652 |
if __name__ == '__main__':
|
|
|
|
| 362 |
|
| 363 |
def generate_code(query: str):
|
| 364 |
if not query:
|
| 365 |
+
return None, None, None, gr.update(active_key="empty"), gr.update(active_key="reasoning", visible=False)
|
| 366 |
|
| 367 |
print("Starting code generation with query:", query)
|
| 368 |
messages = [{
|
|
|
|
| 419 |
code_output: content,
|
| 420 |
reasoning_output: reasoning_content + "\n",
|
| 421 |
state_tab: gr.update(active_key="loading"),
|
| 422 |
+
output_tabs: gr.update(active_key="reasoning", visible=True)
|
| 423 |
}
|
| 424 |
elif 'message' in choice:
|
| 425 |
message_data = choice['message']
|
|
|
|
| 434 |
reasoning_output: reasoning_content + "\n",
|
| 435 |
sandbox: send_to_sandbox(html_content),
|
| 436 |
state_tab: gr.update(active_key="render"),
|
| 437 |
+
output_tabs: gr.update(active_key="code", visible=True) # Switch to code tab when complete
|
| 438 |
}
|
| 439 |
|
| 440 |
# If successful, break out of retry loop
|
|
|
|
| 475 |
}
|
| 476 |
|
| 477 |
.reasoning-box {
|
| 478 |
+
height: 300px;
|
| 479 |
overflow-y: auto;
|
|
|
|
| 480 |
background-color: #f5f5f5;
|
| 481 |
border-radius: 4px;
|
| 482 |
margin-bottom: 12px;
|
| 483 |
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
| 484 |
+
font-size: 14px;
|
| 485 |
line-height: 1.2;
|
| 486 |
white-space: pre-wrap;
|
| 487 |
word-break: break-word;
|
| 488 |
width: 100%;
|
| 489 |
box-sizing: border-box;
|
| 490 |
+
scroll-behavior: smooth;
|
| 491 |
}
|
| 492 |
|
| 493 |
+
.reasoning-box .ms-markdown {
|
| 494 |
+
padding: 0 12px;
|
| 495 |
+
}
|
| 496 |
+
|
| 497 |
.reasoning-box::-webkit-scrollbar {
|
| 498 |
width: 6px;
|
| 499 |
}
|
|
|
|
| 512 |
background: #555;
|
| 513 |
}
|
| 514 |
|
| 515 |
+
.markdown-container {
|
| 516 |
+
height: 300px;
|
| 517 |
+
overflow-y: auto;
|
| 518 |
+
background-color: #f5f5f5;
|
| 519 |
+
border-radius: 4px;
|
| 520 |
+
margin-bottom: 12px;
|
| 521 |
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
| 522 |
+
font-size: 14px;
|
| 523 |
+
line-height: 1.6;
|
| 524 |
+
white-space: pre-wrap;
|
| 525 |
+
word-break: break-word;
|
| 526 |
+
width: 100%;
|
| 527 |
+
box-sizing: border-box;
|
| 528 |
scroll-behavior: smooth;
|
| 529 |
}
|
| 530 |
"""
|
|
|
|
| 532 |
def scroll_to_bottom():
|
| 533 |
return """
|
| 534 |
function() {
|
| 535 |
+
setTimeout(() => {
|
| 536 |
+
const reasoningBox = document.querySelector('.reasoning-box');
|
| 537 |
+
if (reasoningBox) {
|
| 538 |
+
reasoningBox.scrollTop = reasoningBox.scrollHeight;
|
| 539 |
+
}
|
| 540 |
+
const markdownContainer = document.querySelector('.markdown-container');
|
| 541 |
+
if (markdownContainer) {
|
| 542 |
+
markdownContainer.scrollTop = markdownContainer.scrollHeight;
|
| 543 |
+
}
|
| 544 |
+
}, 100);
|
| 545 |
}
|
| 546 |
"""
|
| 547 |
|
|
|
|
| 604 |
)
|
| 605 |
chatbot.welcome_prompt_select(fn=prompt_select, outputs=[sender])
|
| 606 |
|
| 607 |
+
with antd.Tabs.Item(key="code", label="Code Playground (WebDev)"):
|
| 608 |
with antd.Row(gutter=[32, 12]):
|
| 609 |
with antd.Col(span=12):
|
| 610 |
with antd.Flex(vertical=True, gap="middle"):
|
| 611 |
code_input = antd.InputTextarea(
|
| 612 |
size="large",
|
| 613 |
allow_clear=True,
|
| 614 |
+
placeholder="Please enter what kind of application you want or choose an example below and click the button"
|
| 615 |
)
|
| 616 |
code_btn = antd.Button("Generate Code", type="primary", size="large")
|
| 617 |
+
with antd.Tabs(active_key="reasoning", visible=False) as output_tabs:
|
| 618 |
+
with antd.Tabs.Item(key="reasoning", label="🤔 Thinking Process"):
|
| 619 |
+
reasoning_output = legacy.Markdown(
|
| 620 |
+
elem_classes="reasoning-box"
|
| 621 |
+
)
|
| 622 |
+
with antd.Tabs.Item(key="code", label="💻 Generated Code"):
|
| 623 |
+
code_output = legacy.Markdown(elem_classes="markdown-container")
|
|
|
|
| 624 |
|
|
|
|
| 625 |
antd.Divider("Examples")
|
| 626 |
|
| 627 |
# Examples
|
|
|
|
| 668 |
code_btn.click(
|
| 669 |
generate_code,
|
| 670 |
inputs=[code_input],
|
| 671 |
+
outputs=[code_output, reasoning_output, sandbox, state_tab, output_tabs]
|
| 672 |
+
)
|
| 673 |
+
|
| 674 |
+
# Add auto-scroll functionality
|
| 675 |
+
reasoning_output.change(
|
| 676 |
+
fn=scroll_to_bottom,
|
| 677 |
+
inputs=[],
|
| 678 |
+
outputs=[],
|
| 679 |
+
)
|
| 680 |
+
code_output.change(
|
| 681 |
+
fn=scroll_to_bottom,
|
| 682 |
+
inputs=[],
|
| 683 |
+
outputs=[],
|
| 684 |
+
)
|
| 685 |
+
|
| 686 |
+
def on_tab_change(tab_key):
|
| 687 |
+
return gr.update(active_key=tab_key, visible=True)
|
| 688 |
+
|
| 689 |
+
output_tabs.change(
|
| 690 |
+
fn=on_tab_change,
|
| 691 |
+
inputs=[output_tabs],
|
| 692 |
+
outputs=[output_tabs],
|
| 693 |
)
|
| 694 |
|
| 695 |
if __name__ == '__main__':
|