Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -571,8 +571,8 @@ def create_main_interface():
|
|
| 571 |
"""๋ฉ์ธ ์ธํฐํ์ด์ค ์์ฑ ํจ์"""
|
| 572 |
|
| 573 |
#NEW - ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ํตํฉํ ์๋ต ์์ฑ ํจ์
|
| 574 |
-
|
| 575 |
-
|
| 576 |
print(f"Executing search for query: {query}")
|
| 577 |
|
| 578 |
# ๊ฒ์ ์คํ
|
|
@@ -642,7 +642,7 @@ The response should be in HTML format with appropriate styling."""
|
|
| 642 |
print("Response generation completed") # ๋๋ฒ๊น
์ฉ
|
| 643 |
return final_result
|
| 644 |
|
| 645 |
-
|
| 646 |
print(f"Search error: {str(e)}")
|
| 647 |
print(f"Full error details: {str(e.__class__.__name__)}: {str(e)}")
|
| 648 |
return [
|
|
@@ -652,25 +652,24 @@ The response should be in HTML format with appropriate styling."""
|
|
| 652 |
gr.update(open=False)
|
| 653 |
]
|
| 654 |
|
| 655 |
-
|
| 656 |
-
|
| 657 |
return None, gr.update(active_key="empty")
|
| 658 |
|
| 659 |
-
|
| 660 |
if '```html' in query and '```' in query:
|
| 661 |
code = remove_code_block(query)
|
| 662 |
else:
|
| 663 |
code = query.strip()
|
| 664 |
|
| 665 |
return send_to_sandbox(code), gr.update(active_key="render")
|
| 666 |
-
|
| 667 |
print(f"Error executing code: {str(e)}")
|
| 668 |
return None, gr.update(active_key="empty")
|
| 669 |
|
| 670 |
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
try:
|
| 674 |
print(f"Mode: {'Web Search' if is_search else 'Generate'}") # ๋๋ฒ๊น
์ฉ
|
| 675 |
if is_search:
|
| 676 |
print("Executing search and generate...") # ๋๋ฒ๊น
์ฉ
|
|
@@ -680,83 +679,83 @@ The response should be in HTML format with appropriate styling."""
|
|
| 680 |
async for result in demo_instance.generation_code(query, setting):
|
| 681 |
final_result = result
|
| 682 |
return final_result
|
| 683 |
-
|
| 684 |
print(f"Generation error: {str(e)}")
|
| 685 |
return ["", None, gr.update(active_key="error"), gr.update(open=False)]
|
| 686 |
|
| 687 |
-
# CSS ํ์ผ ๋ด์ฉ์ ์ง์ ์ ์ฉ
|
| 688 |
with open('app.css', 'r', encoding='utf-8') as f:
|
| 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 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
|
| 761 |
demo = gr.Blocks(css=custom_css, theme=theme)
|
| 762 |
|
|
|
|
| 571 |
"""๋ฉ์ธ ์ธํฐํ์ด์ค ์์ฑ ํจ์"""
|
| 572 |
|
| 573 |
#NEW - ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ํตํฉํ ์๋ต ์์ฑ ํจ์
|
| 574 |
+
async def execute_search_and_generate(query, setting):
|
| 575 |
+
try:
|
| 576 |
print(f"Executing search for query: {query}")
|
| 577 |
|
| 578 |
# ๊ฒ์ ์คํ
|
|
|
|
| 642 |
print("Response generation completed") # ๋๋ฒ๊น
์ฉ
|
| 643 |
return final_result
|
| 644 |
|
| 645 |
+
except Exception as e:
|
| 646 |
print(f"Search error: {str(e)}")
|
| 647 |
print(f"Full error details: {str(e.__class__.__name__)}: {str(e)}")
|
| 648 |
return [
|
|
|
|
| 652 |
gr.update(open=False)
|
| 653 |
]
|
| 654 |
|
| 655 |
+
def execute_code(query: str):
|
| 656 |
+
if not query or query.strip() == '':
|
| 657 |
return None, gr.update(active_key="empty")
|
| 658 |
|
| 659 |
+
try:
|
| 660 |
if '```html' in query and '```' in query:
|
| 661 |
code = remove_code_block(query)
|
| 662 |
else:
|
| 663 |
code = query.strip()
|
| 664 |
|
| 665 |
return send_to_sandbox(code), gr.update(active_key="render")
|
| 666 |
+
except Exception as e:
|
| 667 |
print(f"Error executing code: {str(e)}")
|
| 668 |
return None, gr.update(active_key="empty")
|
| 669 |
|
| 670 |
|
| 671 |
+
async def handle_generation(query, setting, is_search):
|
| 672 |
+
try:
|
|
|
|
| 673 |
print(f"Mode: {'Web Search' if is_search else 'Generate'}") # ๋๋ฒ๊น
์ฉ
|
| 674 |
if is_search:
|
| 675 |
print("Executing search and generate...") # ๋๋ฒ๊น
์ฉ
|
|
|
|
| 679 |
async for result in demo_instance.generation_code(query, setting):
|
| 680 |
final_result = result
|
| 681 |
return final_result
|
| 682 |
+
except Exception as e:
|
| 683 |
print(f"Generation error: {str(e)}")
|
| 684 |
return ["", None, gr.update(active_key="error"), gr.update(open=False)]
|
| 685 |
|
| 686 |
+
# CSS ํ์ผ ๋ด์ฉ์ ์ง์ ์ ์ฉ
|
| 687 |
with open('app.css', 'r', encoding='utf-8') as f:
|
| 688 |
+
custom_css = f.read()
|
| 689 |
+
|
| 690 |
+
#NEW - ๊ฒ์ ๊ฒฐ๊ณผ ์คํ์ผ ์ถ๊ฐ
|
| 691 |
+
custom_css += """
|
| 692 |
+
.search-summary {
|
| 693 |
+
margin: 20px 0;
|
| 694 |
+
padding: 20px;
|
| 695 |
+
background: #f8f9fa;
|
| 696 |
+
border-radius: 10px;
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
.search-item {
|
| 700 |
+
margin-bottom: 15px;
|
| 701 |
+
padding: 15px;
|
| 702 |
+
border-left: 4px solid #007aff;
|
| 703 |
+
background: white;
|
| 704 |
+
border-radius: 4px;
|
| 705 |
+
}
|
| 706 |
+
|
| 707 |
+
.search-item h3 {
|
| 708 |
+
margin: 0 0 10px 0;
|
| 709 |
+
color: #1a0dab;
|
| 710 |
+
}
|
| 711 |
+
|
| 712 |
+
.search-item a {
|
| 713 |
+
color: inherit;
|
| 714 |
+
text-decoration: none;
|
| 715 |
+
}
|
| 716 |
+
|
| 717 |
+
.search-item p {
|
| 718 |
+
margin: 0;
|
| 719 |
+
color: #4d5156;
|
| 720 |
+
font-size: 14px;
|
| 721 |
+
line-height: 1.5;
|
| 722 |
+
}
|
| 723 |
+
|
| 724 |
+
.empty-content {
|
| 725 |
+
padding: 40px !important;
|
| 726 |
+
background: #f8f9fa !important;
|
| 727 |
+
border-radius: 10px !important;
|
| 728 |
+
margin: 20px !important;
|
| 729 |
+
}
|
| 730 |
+
|
| 731 |
+
.container {
|
| 732 |
+
background: #f0f0f0;
|
| 733 |
+
min-height: 100vh;
|
| 734 |
+
padding: 20px;
|
| 735 |
+
display: flex;
|
| 736 |
+
justify-content: center;
|
| 737 |
+
align-items: center;
|
| 738 |
+
font-family: -apple-system, BlinkMacSystemFont, sans-serif;
|
| 739 |
+
}
|
| 740 |
+
|
| 741 |
+
.mode-selector {
|
| 742 |
+
margin-bottom: 15px;
|
| 743 |
+
padding: 10px;
|
| 744 |
+
border-radius: 8px;
|
| 745 |
+
background: #f8f9fa;
|
| 746 |
+
}
|
| 747 |
+
|
| 748 |
+
.error-content {
|
| 749 |
+
padding: 20px;
|
| 750 |
+
background: #fff2f0;
|
| 751 |
+
border-radius: 8px;
|
| 752 |
+
border: 1px solid #ff4d4f;
|
| 753 |
+
}
|
| 754 |
+
|
| 755 |
+
.search-mode-active {
|
| 756 |
+
background-color: rgba(66,133,244,0.1);
|
| 757 |
+
}
|
| 758 |
+
"""
|
| 759 |
|
| 760 |
demo = gr.Blocks(css=custom_css, theme=theme)
|
| 761 |
|