Update app.py
Browse files
app.py
CHANGED
@@ -317,7 +317,7 @@ async def try_openai_api(openai_messages):
|
|
317 |
raise e
|
318 |
|
319 |
def history_render(history: History):
|
320 |
-
return
|
321 |
|
322 |
def remove_code_block(text):
|
323 |
text = re.sub(r'```[python|html]?\n', '', text)
|
@@ -403,10 +403,10 @@ def boost_prompt(prompt: str) -> str:
|
|
403 |
def handle_boost(prompt: str):
|
404 |
try:
|
405 |
boosted_prompt = boost_prompt(prompt)
|
406 |
-
return boosted_prompt
|
407 |
except Exception as e:
|
408 |
print(f"Boost ์ฒ๋ฆฌ ์ค ์ค๋ฅ: {str(e)}")
|
409 |
-
return prompt
|
410 |
|
411 |
# ๋ฐฐํฌ ๊ด๋ จ ํจ์ ์ถ๊ฐ
|
412 |
def generate_space_name():
|
@@ -519,9 +519,7 @@ class Demo:
|
|
519 |
try:
|
520 |
yield [
|
521 |
"Generating code...",
|
522 |
-
_history
|
523 |
-
gr.update(active_key="loading"),
|
524 |
-
gr.update(open=True)
|
525 |
]
|
526 |
await asyncio.sleep(0)
|
527 |
|
@@ -531,9 +529,7 @@ class Demo:
|
|
531 |
code = content
|
532 |
yield [
|
533 |
code,
|
534 |
-
_history
|
535 |
-
gr.update(active_key="loading"),
|
536 |
-
gr.update(open=True)
|
537 |
]
|
538 |
await asyncio.sleep(0)
|
539 |
collected_content = code
|
@@ -545,9 +541,7 @@ class Demo:
|
|
545 |
code = content
|
546 |
yield [
|
547 |
code,
|
548 |
-
_history
|
549 |
-
gr.update(active_key="loading"),
|
550 |
-
gr.update(open=True)
|
551 |
]
|
552 |
await asyncio.sleep(0)
|
553 |
collected_content = code
|
@@ -562,9 +556,7 @@ class Demo:
|
|
562 |
|
563 |
yield [
|
564 |
collected_content,
|
565 |
-
_history
|
566 |
-
gr.update(active_key="empty"),
|
567 |
-
gr.update(open=True)
|
568 |
]
|
569 |
else:
|
570 |
raise ValueError("No content was generated from either API")
|
@@ -589,7 +581,7 @@ example_prompts = [
|
|
589 |
# Demo ์ธ์คํด์ค ์์ฑ
|
590 |
demo_instance = Demo()
|
591 |
|
592 |
-
with gr.Blocks(css="body {background-color: #f7f7f7;}"
|
593 |
history = gr.State([])
|
594 |
setting = gr.State({
|
595 |
"system": SystemPrompt,
|
@@ -609,8 +601,7 @@ with gr.Blocks(css="body {background-color: #f7f7f7;}", theme=gr.themes.Soft())
|
|
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(
|
@@ -627,8 +618,7 @@ with gr.Blocks(css="body {background-color: #f7f7f7;}", theme=gr.themes.Soft())
|
|
627 |
history_btn = gr.Button("์ด์ ๊ธฐ๋ก ๋ณด๊ธฐ")
|
628 |
history_output = gr.Chatbot(
|
629 |
show_label=False,
|
630 |
-
|
631 |
-
visible=False
|
632 |
)
|
633 |
|
634 |
# ์ฐ์ธก ํจ๋
|
@@ -641,9 +631,7 @@ with gr.Blocks(css="body {background-color: #f7f7f7;}", theme=gr.themes.Soft())
|
|
641 |
code_output = gr.Code(
|
642 |
language="python",
|
643 |
label="์์ฑ๋ ์ฝ๋",
|
644 |
-
|
645 |
-
lines=17,
|
646 |
-
height=400
|
647 |
)
|
648 |
|
649 |
with gr.TabItem("๋ถ์"):
|
@@ -664,13 +652,13 @@ with gr.Blocks(css="body {background-color: #f7f7f7;}", theme=gr.themes.Soft())
|
|
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(
|
@@ -682,7 +670,7 @@ with gr.Blocks(css="body {background-color: #f7f7f7;}", theme=gr.themes.Soft())
|
|
682 |
boost_btn.click(
|
683 |
fn=handle_boost,
|
684 |
inputs=[input_text],
|
685 |
-
outputs=[input_text
|
686 |
)
|
687 |
|
688 |
clear_btn.click(
|
@@ -697,13 +685,10 @@ with gr.Blocks(css="body {background-color: #f7f7f7;}", theme=gr.themes.Soft())
|
|
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=
|
705 |
inputs=[history],
|
706 |
-
outputs=[history_output
|
707 |
)
|
708 |
|
709 |
if __name__ == "__main__":
|
|
|
317 |
raise e
|
318 |
|
319 |
def history_render(history: History):
|
320 |
+
return history
|
321 |
|
322 |
def remove_code_block(text):
|
323 |
text = re.sub(r'```[python|html]?\n', '', text)
|
|
|
403 |
def handle_boost(prompt: str):
|
404 |
try:
|
405 |
boosted_prompt = boost_prompt(prompt)
|
406 |
+
return boosted_prompt
|
407 |
except Exception as e:
|
408 |
print(f"Boost ์ฒ๋ฆฌ ์ค ์ค๋ฅ: {str(e)}")
|
409 |
+
return prompt
|
410 |
|
411 |
# ๋ฐฐํฌ ๊ด๋ จ ํจ์ ์ถ๊ฐ
|
412 |
def generate_space_name():
|
|
|
519 |
try:
|
520 |
yield [
|
521 |
"Generating code...",
|
522 |
+
_history
|
|
|
|
|
523 |
]
|
524 |
await asyncio.sleep(0)
|
525 |
|
|
|
529 |
code = content
|
530 |
yield [
|
531 |
code,
|
532 |
+
_history
|
|
|
|
|
533 |
]
|
534 |
await asyncio.sleep(0)
|
535 |
collected_content = code
|
|
|
541 |
code = content
|
542 |
yield [
|
543 |
code,
|
544 |
+
_history
|
|
|
|
|
545 |
]
|
546 |
await asyncio.sleep(0)
|
547 |
collected_content = code
|
|
|
556 |
|
557 |
yield [
|
558 |
collected_content,
|
559 |
+
_history
|
|
|
|
|
560 |
]
|
561 |
else:
|
562 |
raise ValueError("No content was generated from either API")
|
|
|
581 |
# Demo ์ธ์คํด์ค ์์ฑ
|
582 |
demo_instance = Demo()
|
583 |
|
584 |
+
with gr.Blocks(css="body {background-color: #f7f7f7;}") as demo:
|
585 |
history = gr.State([])
|
586 |
setting = gr.State({
|
587 |
"system": SystemPrompt,
|
|
|
601 |
input_text = gr.Textbox(
|
602 |
label="์ํ๋ ์ฑ ์ค๋ช
์ ์
๋ ฅํ์ธ์",
|
603 |
placeholder=random.choice(DEMO_LIST)['description'],
|
604 |
+
lines=12
|
|
|
605 |
)
|
606 |
|
607 |
gr.Examples(
|
|
|
618 |
history_btn = gr.Button("์ด์ ๊ธฐ๋ก ๋ณด๊ธฐ")
|
619 |
history_output = gr.Chatbot(
|
620 |
show_label=False,
|
621 |
+
type="messages"
|
|
|
622 |
)
|
623 |
|
624 |
# ์ฐ์ธก ํจ๋
|
|
|
631 |
code_output = gr.Code(
|
632 |
language="python",
|
633 |
label="์์ฑ๋ ์ฝ๋",
|
634 |
+
lines=17
|
|
|
|
|
635 |
)
|
636 |
|
637 |
with gr.TabItem("๋ถ์"):
|
|
|
652 |
loading_indicator.update('<div id="loading" style="display:block; text-align:center;"><p>์ฝ๋ ์์ฑ ์ค...</p></div>')
|
653 |
|
654 |
result = None
|
|
|
655 |
|
656 |
async for output in demo_instance.generation_code(query, setting, history):
|
657 |
result = output[0] # ์ฝ๋ ์ถ๋ ฅ
|
|
|
658 |
|
659 |
+
code_analysis_html = analyze_code(result)
|
660 |
loading_indicator.update('<div id="loading" style="display:none;"></div>')
|
661 |
+
|
662 |
return result, code_analysis_html
|
663 |
|
664 |
generate_btn.click(
|
|
|
670 |
boost_btn.click(
|
671 |
fn=handle_boost,
|
672 |
inputs=[input_text],
|
673 |
+
outputs=[input_text]
|
674 |
)
|
675 |
|
676 |
clear_btn.click(
|
|
|
685 |
outputs=[deploy_result]
|
686 |
)
|
687 |
|
|
|
|
|
|
|
688 |
history_btn.click(
|
689 |
+
fn=history_render,
|
690 |
inputs=[history],
|
691 |
+
outputs=[history_output]
|
692 |
)
|
693 |
|
694 |
if __name__ == "__main__":
|