Spaces:
Running
Running
feat: prompts and styles
Browse files
app.py
CHANGED
@@ -364,7 +364,14 @@ def select_example(example):
|
|
364 |
|
365 |
def generate_code(query: str):
|
366 |
if not query:
|
367 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
368 |
|
369 |
print("Starting code generation with query:", query)
|
370 |
messages = [{
|
@@ -422,18 +429,21 @@ def generate_code(query: str):
|
|
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']
|
@@ -444,11 +454,12 @@ def generate_code(query: str):
|
|
444 |
html_content = remove_code_block(content)
|
445 |
print("Extracted HTML:", html_content)
|
446 |
yield {
|
447 |
-
code_output: 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
|
@@ -467,21 +478,34 @@ def generate_code(query: str):
|
|
467 |
raise gr.Error(str(e))
|
468 |
|
469 |
css = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
470 |
.output-loading {
|
471 |
display: flex;
|
472 |
flex-direction: column;
|
473 |
align-items: center;
|
474 |
justify-content: center;
|
475 |
width: 100%;
|
476 |
-
|
477 |
-
height:
|
478 |
}
|
479 |
|
480 |
.output-html {
|
481 |
display: flex;
|
482 |
flex-direction: column;
|
483 |
width: 100%;
|
484 |
-
|
|
|
485 |
background: #fff;
|
486 |
border-radius: 8px;
|
487 |
border: 1px solid #e8e8e8;
|
@@ -489,6 +513,44 @@ css = """
|
|
489 |
overflow: hidden;
|
490 |
}
|
491 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
492 |
.render_header {
|
493 |
display: flex;
|
494 |
align-items: center;
|
@@ -581,9 +643,9 @@ css = """
|
|
581 |
|
582 |
/* Example card styles */
|
583 |
.example-card {
|
584 |
-
flex: 1 1
|
585 |
-
max-width:
|
586 |
-
margin:
|
587 |
transition: all 0.3s;
|
588 |
cursor: pointer;
|
589 |
border: 1px solid #e8e8e8;
|
@@ -631,11 +693,21 @@ css = """
|
|
631 |
align-items: center;
|
632 |
justify-content: center;
|
633 |
width: 100%;
|
634 |
-
min-height:
|
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():
|
@@ -714,7 +786,7 @@ with gr.Blocks(css=css) as demo, ms.Application(), antdx.XProvider():
|
|
714 |
chatbot.welcome_prompt_select(fn=prompt_select, outputs=[sender])
|
715 |
|
716 |
with antd.Tabs.Item(key="code", label="Code Playground (WebDev)"):
|
717 |
-
with antd.Row(gutter=[32, 12]):
|
718 |
with antd.Col(span=12):
|
719 |
with antd.Flex(vertical=True, gap="middle"):
|
720 |
code_input = antd.InputTextarea(
|
|
|
364 |
|
365 |
def generate_code(query: str):
|
366 |
if not query:
|
367 |
+
return {
|
368 |
+
code_output: gr.update(value=None),
|
369 |
+
reasoning_output: gr.update(value=None),
|
370 |
+
sandbox: gr.update(value=None),
|
371 |
+
state_tab: gr.update(active_key="empty"),
|
372 |
+
output_tabs: gr.update(active_key="reasoning", visible=False),
|
373 |
+
loading: gr.update(tip="Thinking...")
|
374 |
+
}
|
375 |
|
376 |
print("Starting code generation with query:", query)
|
377 |
messages = [{
|
|
|
429 |
if content and not loading_text == "Generating code...":
|
430 |
loading_text = "Generating code..."
|
431 |
yield {
|
432 |
+
code_output: gr.update(value=content),
|
433 |
+
reasoning_output: gr.update(value=reasoning_content + "\n"),
|
434 |
+
sandbox: gr.update(value=None),
|
435 |
state_tab: gr.update(active_key="loading"),
|
436 |
output_tabs: gr.update(active_key="reasoning", visible=True),
|
437 |
loading: gr.update(tip=loading_text)
|
438 |
}
|
439 |
else:
|
440 |
yield {
|
441 |
+
code_output: gr.update(value=content),
|
442 |
+
reasoning_output: gr.update(value=reasoning_content + "\n"),
|
443 |
+
sandbox: gr.update(value=None),
|
444 |
state_tab: gr.update(active_key="loading"),
|
445 |
+
output_tabs: gr.update(active_key="reasoning", visible=True),
|
446 |
+
loading: gr.update(tip=loading_text)
|
447 |
}
|
448 |
elif 'message' in choice:
|
449 |
message_data = choice['message']
|
|
|
454 |
html_content = remove_code_block(content)
|
455 |
print("Extracted HTML:", html_content)
|
456 |
yield {
|
457 |
+
code_output: gr.update(value=content),
|
458 |
+
reasoning_output: gr.update(value=reasoning_content + "\n"),
|
459 |
+
sandbox: gr.update(value=send_to_sandbox(html_content)),
|
460 |
state_tab: gr.update(active_key="render"),
|
461 |
+
output_tabs: gr.update(active_key="code", visible=True),
|
462 |
+
loading: gr.update(tip="Done")
|
463 |
}
|
464 |
|
465 |
# If successful, break out of retry loop
|
|
|
478 |
raise gr.Error(str(e))
|
479 |
|
480 |
css = """
|
481 |
+
/* Add styles for the main container */
|
482 |
+
.ant-tabs-content {
|
483 |
+
height: calc(100vh - 200px);
|
484 |
+
overflow: hidden;
|
485 |
+
}
|
486 |
+
|
487 |
+
.ant-tabs-tabpane {
|
488 |
+
height: 100%;
|
489 |
+
overflow-y: auto;
|
490 |
+
}
|
491 |
+
|
492 |
+
/* Modify existing styles */
|
493 |
.output-loading {
|
494 |
display: flex;
|
495 |
flex-direction: column;
|
496 |
align-items: center;
|
497 |
justify-content: center;
|
498 |
width: 100%;
|
499 |
+
height: 100%;
|
500 |
+
min-height: unset;
|
501 |
}
|
502 |
|
503 |
.output-html {
|
504 |
display: flex;
|
505 |
flex-direction: column;
|
506 |
width: 100%;
|
507 |
+
height: 100%;
|
508 |
+
min-height: unset;
|
509 |
background: #fff;
|
510 |
border-radius: 8px;
|
511 |
border: 1px solid #e8e8e8;
|
|
|
513 |
overflow: hidden;
|
514 |
}
|
515 |
|
516 |
+
.right_content {
|
517 |
+
display: flex;
|
518 |
+
flex-direction: column;
|
519 |
+
align-items: center;
|
520 |
+
justify-content: center;
|
521 |
+
width: 100%;
|
522 |
+
height: 100%;
|
523 |
+
min-height: unset;
|
524 |
+
background: #fff;
|
525 |
+
border-radius: 8px;
|
526 |
+
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
527 |
+
}
|
528 |
+
|
529 |
+
/* Add styles for the code playground container */
|
530 |
+
.code-playground-container {
|
531 |
+
height: 100%;
|
532 |
+
overflow-y: auto;
|
533 |
+
padding-right: 8px;
|
534 |
+
}
|
535 |
+
|
536 |
+
.code-playground-container::-webkit-scrollbar {
|
537 |
+
width: 6px;
|
538 |
+
}
|
539 |
+
|
540 |
+
.code-playground-container::-webkit-scrollbar-track {
|
541 |
+
background: #f1f1f1;
|
542 |
+
border-radius: 3px;
|
543 |
+
}
|
544 |
+
|
545 |
+
.code-playground-container::-webkit-scrollbar-thumb {
|
546 |
+
background: #888;
|
547 |
+
border-radius: 3px;
|
548 |
+
}
|
549 |
+
|
550 |
+
.code-playground-container::-webkit-scrollbar-thumb:hover {
|
551 |
+
background: #555;
|
552 |
+
}
|
553 |
+
|
554 |
.render_header {
|
555 |
display: flex;
|
556 |
align-items: center;
|
|
|
643 |
|
644 |
/* Example card styles */
|
645 |
.example-card {
|
646 |
+
flex: 1 1 calc(50% - 20px);
|
647 |
+
max-width: calc(50% - 20px);
|
648 |
+
margin: 6px;
|
649 |
transition: all 0.3s;
|
650 |
cursor: pointer;
|
651 |
border: 1px solid #e8e8e8;
|
|
|
693 |
align-items: center;
|
694 |
justify-content: center;
|
695 |
width: 100%;
|
696 |
+
min-height: 620px;
|
697 |
background: #fff;
|
698 |
border-radius: 8px;
|
699 |
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
700 |
}
|
701 |
+
|
702 |
+
/* Add styles for the example cards container */
|
703 |
+
.example-tabs .ant-tabs-content {
|
704 |
+
padding: 0 8px;
|
705 |
+
}
|
706 |
+
|
707 |
+
.example-tabs .ant-flex {
|
708 |
+
margin: 0 -8px;
|
709 |
+
width: calc(100% + 16px);
|
710 |
+
}
|
711 |
"""
|
712 |
|
713 |
def scroll_to_bottom():
|
|
|
786 |
chatbot.welcome_prompt_select(fn=prompt_select, outputs=[sender])
|
787 |
|
788 |
with antd.Tabs.Item(key="code", label="Code Playground (WebDev)"):
|
789 |
+
with antd.Row(gutter=[32, 12], elem_classes="code-playground-container"):
|
790 |
with antd.Col(span=12):
|
791 |
with antd.Flex(vertical=True, gap="middle"):
|
792 |
code_input = antd.InputTextarea(
|
config.py
CHANGED
@@ -3,10 +3,10 @@ DEFAULT_PROMPTS = [
|
|
3 |
"label": "π€ Logical Reasoning",
|
4 |
"children": [
|
5 |
{
|
6 |
-
"description": "A is
|
7 |
},
|
8 |
{
|
9 |
-
"description": "
|
10 |
}
|
11 |
]
|
12 |
},
|
@@ -14,10 +14,10 @@ DEFAULT_PROMPTS = [
|
|
14 |
"label": "π Knowledge Q&A",
|
15 |
"children": [
|
16 |
{
|
17 |
-
"description": "
|
18 |
},
|
19 |
{
|
20 |
-
"description": "
|
21 |
}
|
22 |
]
|
23 |
}
|
|
|
3 |
"label": "π€ Logical Reasoning",
|
4 |
"children": [
|
5 |
{
|
6 |
+
"description": "A cat is lying on a blanket because it is warm. What does 'it' refer to in this sentence?"
|
7 |
},
|
8 |
{
|
9 |
+
"description": "Snowflake : white'' - Which of the following groups of words has a relationship most similar to the relationship in the above word group? [ ''Doctor : learned'', ''Woman : gentle'', ''River : flowing'', ''Peony : wealth'' ]"
|
10 |
}
|
11 |
]
|
12 |
},
|
|
|
14 |
"label": "π Knowledge Q&A",
|
15 |
"children": [
|
16 |
{
|
17 |
+
"description": "Why are most manhole covers round?"
|
18 |
},
|
19 |
{
|
20 |
+
"description": "What is the shortest distance between the United States and Russia?"
|
21 |
}
|
22 |
]
|
23 |
}
|