Spaces:
Running
Running
fix: error
Browse files
README.md
CHANGED
|
@@ -10,4 +10,4 @@ pinned: false
|
|
| 10 |
license: apache-2.0
|
| 11 |
---
|
| 12 |
|
| 13 |
-
An example chatbot using [
|
|
|
|
| 10 |
license: apache-2.0
|
| 11 |
---
|
| 12 |
|
| 13 |
+
An MiniMax-M1 example chatbot using [MiniMax-M1](https://huggingface.co/spaces/MiniMaxAI/MiniMax-M1), [Gradio](https://gradio.app), [`modelscope_studio`](https://modelscope.cn/studios/modelscope/modelscope-studio).
|
app.py
CHANGED
|
@@ -357,8 +357,10 @@ def send_to_sandbox(code):
|
|
| 357 |
print("Generated iframe:", iframe)
|
| 358 |
return iframe
|
| 359 |
|
| 360 |
-
def select_example(example
|
| 361 |
-
|
|
|
|
|
|
|
| 362 |
|
| 363 |
def generate_code(query: str):
|
| 364 |
if not query:
|
|
@@ -401,6 +403,8 @@ def generate_code(query: str):
|
|
| 401 |
|
| 402 |
content = ""
|
| 403 |
reasoning_content = ""
|
|
|
|
|
|
|
| 404 |
for row in r.iter_lines():
|
| 405 |
if row.startswith(b'data:'):
|
| 406 |
data = json.loads(row[5:])
|
|
@@ -413,14 +417,24 @@ def generate_code(query: str):
|
|
| 413 |
delta = choice['delta']
|
| 414 |
content += delta.get('content', '')
|
| 415 |
reasoning_content += delta.get('reasoning_content', '')
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 424 |
elif 'message' in choice:
|
| 425 |
message_data = choice['message']
|
| 426 |
content = message_data.get('content', '')
|
|
@@ -434,7 +448,7 @@ def generate_code(query: str):
|
|
| 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)
|
| 438 |
}
|
| 439 |
|
| 440 |
# If successful, break out of retry loop
|
|
@@ -468,10 +482,47 @@ css = """
|
|
| 468 |
flex-direction: column;
|
| 469 |
width: 100%;
|
| 470 |
min-height: 680px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 471 |
}
|
| 472 |
|
| 473 |
.output-html > iframe {
|
| 474 |
flex: 1;
|
|
|
|
|
|
|
| 475 |
}
|
| 476 |
|
| 477 |
.reasoning-box {
|
|
@@ -572,6 +623,19 @@ css = """
|
|
| 572 |
.example-tabs .ant-tabs-tab-active {
|
| 573 |
font-weight: 500;
|
| 574 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 575 |
"""
|
| 576 |
|
| 577 |
def scroll_to_bottom():
|
|
@@ -685,39 +749,40 @@ with gr.Blocks(css=css) as demo, ms.Application(), antdx.XProvider():
|
|
| 685 |
)
|
| 686 |
|
| 687 |
example_card.click(
|
| 688 |
-
fn=select_example
|
|
|
|
| 689 |
outputs=[code_input]
|
| 690 |
)
|
| 691 |
|
| 692 |
with antd.Col(span=12):
|
| 693 |
with ms.Div(elem_classes="right_panel"):
|
| 694 |
-
gr.HTML('
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
) as download_btn:
|
| 703 |
-
with ms.Slot("icon"):
|
| 704 |
-
antd.Icon("DownloadOutlined")
|
| 705 |
-
download_content = gr.Text(visible=False)
|
| 706 |
-
|
| 707 |
-
view_code_btn = antd.Button(
|
| 708 |
-
"🧑💻 View Code", type="primary")
|
| 709 |
with antd.Tabs(active_key="empty", render_tab_bar="() => null") as state_tab:
|
| 710 |
with antd.Tabs.Item(key="empty"):
|
| 711 |
empty = antd.Empty(description="empty input", elem_classes="right_content")
|
| 712 |
with antd.Tabs.Item(key="loading"):
|
| 713 |
-
loading = antd.Spin(True, tip="coding...", size="large", elem_classes="output-loading")
|
| 714 |
with antd.Tabs.Item(key="render"):
|
| 715 |
sandbox = gr.HTML(elem_classes="output-html")
|
| 716 |
|
| 717 |
code_btn.click(
|
| 718 |
generate_code,
|
| 719 |
inputs=[code_input],
|
| 720 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 721 |
)
|
| 722 |
|
| 723 |
# Add auto-scroll functionality
|
|
|
|
| 357 |
print("Generated iframe:", iframe)
|
| 358 |
return iframe
|
| 359 |
|
| 360 |
+
def select_example(example):
|
| 361 |
+
if isinstance(example, dict):
|
| 362 |
+
return example.get("description", "")
|
| 363 |
+
return ""
|
| 364 |
|
| 365 |
def generate_code(query: str):
|
| 366 |
if not query:
|
|
|
|
| 403 |
|
| 404 |
content = ""
|
| 405 |
reasoning_content = ""
|
| 406 |
+
loading_text = "Thinking..."
|
| 407 |
+
|
| 408 |
for row in r.iter_lines():
|
| 409 |
if row.startswith(b'data:'):
|
| 410 |
data = json.loads(row[5:])
|
|
|
|
| 417 |
delta = choice['delta']
|
| 418 |
content += delta.get('content', '')
|
| 419 |
reasoning_content += delta.get('reasoning_content', '')
|
| 420 |
+
|
| 421 |
+
# Update loading text based on content
|
| 422 |
+
if content and not loading_text == "Generating code...":
|
| 423 |
+
loading_text = "Generating code..."
|
| 424 |
+
yield {
|
| 425 |
+
code_output: content,
|
| 426 |
+
reasoning_output: reasoning_content + "\n",
|
| 427 |
+
state_tab: gr.update(active_key="loading"),
|
| 428 |
+
output_tabs: gr.update(active_key="reasoning", visible=True),
|
| 429 |
+
loading: gr.update(tip=loading_text)
|
| 430 |
+
}
|
| 431 |
+
else:
|
| 432 |
+
yield {
|
| 433 |
+
code_output: content,
|
| 434 |
+
reasoning_output: reasoning_content + "\n",
|
| 435 |
+
state_tab: gr.update(active_key="loading"),
|
| 436 |
+
output_tabs: gr.update(active_key="reasoning", visible=True)
|
| 437 |
+
}
|
| 438 |
elif 'message' in choice:
|
| 439 |
message_data = choice['message']
|
| 440 |
content = message_data.get('content', '')
|
|
|
|
| 448 |
reasoning_output: reasoning_content + "\n",
|
| 449 |
sandbox: send_to_sandbox(html_content),
|
| 450 |
state_tab: gr.update(active_key="render"),
|
| 451 |
+
output_tabs: gr.update(active_key="code", visible=True)
|
| 452 |
}
|
| 453 |
|
| 454 |
# If successful, break out of retry loop
|
|
|
|
| 482 |
flex-direction: column;
|
| 483 |
width: 100%;
|
| 484 |
min-height: 680px;
|
| 485 |
+
background: #fff;
|
| 486 |
+
border-radius: 8px;
|
| 487 |
+
border: 1px solid #e8e8e8;
|
| 488 |
+
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
| 489 |
+
overflow: hidden;
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
.render_header {
|
| 493 |
+
display: flex;
|
| 494 |
+
align-items: center;
|
| 495 |
+
padding: 8px 16px;
|
| 496 |
+
background: #f5f5f5;
|
| 497 |
+
border-bottom: 1px solid #e8e8e8;
|
| 498 |
+
border-top-left-radius: 8px;
|
| 499 |
+
border-top-right-radius: 8px;
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
.header_btn {
|
| 503 |
+
width: 12px;
|
| 504 |
+
height: 12px;
|
| 505 |
+
border-radius: 50%;
|
| 506 |
+
margin-right: 8px;
|
| 507 |
+
display: inline-block;
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
.header_btn:nth-child(1) {
|
| 511 |
+
background: #ff5f56;
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
.header_btn:nth-child(2) {
|
| 515 |
+
background: #ffbd2e;
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
.header_btn:nth-child(3) {
|
| 519 |
+
background: #27c93f;
|
| 520 |
}
|
| 521 |
|
| 522 |
.output-html > iframe {
|
| 523 |
flex: 1;
|
| 524 |
+
border: none;
|
| 525 |
+
background: #fff;
|
| 526 |
}
|
| 527 |
|
| 528 |
.reasoning-box {
|
|
|
|
| 623 |
.example-tabs .ant-tabs-tab-active {
|
| 624 |
font-weight: 500;
|
| 625 |
}
|
| 626 |
+
|
| 627 |
+
/* Empty state styles */
|
| 628 |
+
.right_content {
|
| 629 |
+
display: flex;
|
| 630 |
+
flex-direction: column;
|
| 631 |
+
align-items: center;
|
| 632 |
+
justify-content: center;
|
| 633 |
+
width: 100%;
|
| 634 |
+
min-height: 680px;
|
| 635 |
+
background: #fff;
|
| 636 |
+
border-radius: 8px;
|
| 637 |
+
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
| 638 |
+
}
|
| 639 |
"""
|
| 640 |
|
| 641 |
def scroll_to_bottom():
|
|
|
|
| 749 |
)
|
| 750 |
|
| 751 |
example_card.click(
|
| 752 |
+
fn=select_example,
|
| 753 |
+
inputs=[gr.State(example)],
|
| 754 |
outputs=[code_input]
|
| 755 |
)
|
| 756 |
|
| 757 |
with antd.Col(span=12):
|
| 758 |
with ms.Div(elem_classes="right_panel"):
|
| 759 |
+
gr.HTML('''
|
| 760 |
+
<div class="render_header">
|
| 761 |
+
<span class="header_btn"></span>
|
| 762 |
+
<span class="header_btn"></span>
|
| 763 |
+
<span class="header_btn"></span>
|
| 764 |
+
</div>
|
| 765 |
+
''')
|
| 766 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 767 |
with antd.Tabs(active_key="empty", render_tab_bar="() => null") as state_tab:
|
| 768 |
with antd.Tabs.Item(key="empty"):
|
| 769 |
empty = antd.Empty(description="empty input", elem_classes="right_content")
|
| 770 |
with antd.Tabs.Item(key="loading"):
|
| 771 |
+
loading = antd.Spin(True, tip="Thinking and coding...", size="large", elem_classes="output-loading")
|
| 772 |
with antd.Tabs.Item(key="render"):
|
| 773 |
sandbox = gr.HTML(elem_classes="output-html")
|
| 774 |
|
| 775 |
code_btn.click(
|
| 776 |
generate_code,
|
| 777 |
inputs=[code_input],
|
| 778 |
+
outputs=[
|
| 779 |
+
code_output,
|
| 780 |
+
reasoning_output,
|
| 781 |
+
sandbox,
|
| 782 |
+
state_tab,
|
| 783 |
+
output_tabs,
|
| 784 |
+
loading
|
| 785 |
+
]
|
| 786 |
)
|
| 787 |
|
| 788 |
# Add auto-scroll functionality
|