Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -567,6 +567,62 @@ def update_placeholder():
|
|
567 |
def create_main_interface():
|
568 |
"""๋ฉ์ธ ์ธํฐํ์ด์ค ์์ฑ ํจ์"""
|
569 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
570 |
def execute_code(query: str):
|
571 |
if not query or query.strip() == '':
|
572 |
return None, gr.update(active_key="empty")
|
@@ -586,7 +642,39 @@ def create_main_interface():
|
|
586 |
with open('app.css', 'r', encoding='utf-8') as f:
|
587 |
custom_css = f.read()
|
588 |
|
589 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
590 |
|
591 |
.empty-content {
|
592 |
padding: 40px !important;
|
@@ -694,15 +782,18 @@ def create_main_interface():
|
|
694 |
""", theme=theme)
|
695 |
|
696 |
|
697 |
-
|
698 |
with demo:
|
699 |
with gr.Tabs(elem_classes="main-tabs") as tabs:
|
700 |
with gr.Tab("Visual AI Assistant", elem_id="mouse-tab", elem_classes="mouse-tab"):
|
701 |
-
# SystemPrompt ์ค์ ์ ์ํ State ์ถ๊ฐ
|
702 |
setting = gr.State({
|
703 |
"system": SystemPrompt,
|
704 |
})
|
705 |
|
|
|
|
|
|
|
|
|
|
|
706 |
with ms.Application() as app:
|
707 |
with antd.ConfigProvider():
|
708 |
|
@@ -921,6 +1012,33 @@ Use the "Generate" button for basic creation, "Enhance" button for prompt improv
|
|
921 |
elem_classes="deploy-result"
|
922 |
)
|
923 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
924 |
# ์ฐ์ธก ํจ๋
|
925 |
with antd.Col(span=24, md=16):
|
926 |
with ms.Div(elem_classes="right_panel"):
|
|
|
567 |
def create_main_interface():
|
568 |
"""๋ฉ์ธ ์ธํฐํ์ด์ค ์์ฑ ํจ์"""
|
569 |
|
570 |
+
#NEW - ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ํตํฉํ ์๋ต ์์ฑ ํจ์
|
571 |
+
def execute_search_and_generate(query, setting):
|
572 |
+
try:
|
573 |
+
# ๊ฒ์ ์คํ
|
574 |
+
url = "https://api.serphouse.com/serp/live"
|
575 |
+
payload = {
|
576 |
+
"data": {
|
577 |
+
"q": query,
|
578 |
+
"domain": "google.com",
|
579 |
+
"lang": "en",
|
580 |
+
"device": "desktop",
|
581 |
+
"serp_type": "web",
|
582 |
+
"loc": "Alba,Texas,United States",
|
583 |
+
"loc_id": "1026201",
|
584 |
+
"verbatim": "0",
|
585 |
+
"gfilter": "0",
|
586 |
+
"page": "1",
|
587 |
+
"num_result": "5" # ์์ 5๊ฐ ๊ฒฐ๊ณผ๋ง ์ฌ์ฉ
|
588 |
+
}
|
589 |
+
}
|
590 |
+
headers = {
|
591 |
+
'Authorization': 'Bearer V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6',
|
592 |
+
'Content-Type': 'application/json'
|
593 |
+
}
|
594 |
+
|
595 |
+
response = requests.post(url, headers=headers, json=payload)
|
596 |
+
results = response.json()
|
597 |
+
|
598 |
+
# ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ HTML๋ก ๋ณํ
|
599 |
+
search_content = "<div class='search-summary'><h2>Search Results</h2>"
|
600 |
+
for result in results['results'][:5]: # ์์ 5๊ฐ ๊ฒฐ๊ณผ๋ง ์ฌ์ฉ
|
601 |
+
search_content += f"""
|
602 |
+
<div class="search-item">
|
603 |
+
<h3><a href="{result['url']}" target="_blank">{result['title']}</a></h3>
|
604 |
+
<p>{result['snippet']}</p>
|
605 |
+
</div>
|
606 |
+
"""
|
607 |
+
search_content += "</div>"
|
608 |
+
|
609 |
+
# ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ํฌํจํ ํ๋กฌํํธ ์์ฑ
|
610 |
+
enhanced_prompt = f"""Based on these search results, create a visually appealing and informative response:
|
611 |
+
{search_content}
|
612 |
+
|
613 |
+
Original query: {query}
|
614 |
+
|
615 |
+
Create a comprehensive visual response that incorporates relevant information from the search results.
|
616 |
+
"""
|
617 |
+
|
618 |
+
# ๊ธฐ์กด generation_code ํจ์ ํธ์ถ
|
619 |
+
return demo_instance.generation_code(enhanced_prompt, setting)
|
620 |
+
|
621 |
+
except Exception as e:
|
622 |
+
print(f"Search error: {str(e)}")
|
623 |
+
# ๊ฒ์ ์คํจ์ ๊ธฐ๋ณธ generation_code๋ก ํด๋ฐฑ
|
624 |
+
return demo_instance.generation_code(query, setting)
|
625 |
+
|
626 |
def execute_code(query: str):
|
627 |
if not query or query.strip() == '':
|
628 |
return None, gr.update(active_key="empty")
|
|
|
642 |
with open('app.css', 'r', encoding='utf-8') as f:
|
643 |
custom_css = f.read()
|
644 |
|
645 |
+
#NEW - ๊ฒ์ ๊ฒฐ๊ณผ ์คํ์ผ ์ถ๊ฐ
|
646 |
+
custom_css += """
|
647 |
+
.search-summary {
|
648 |
+
margin: 20px 0;
|
649 |
+
padding: 20px;
|
650 |
+
background: #f8f9fa;
|
651 |
+
border-radius: 10px;
|
652 |
+
}
|
653 |
+
|
654 |
+
.search-item {
|
655 |
+
margin-bottom: 15px;
|
656 |
+
padding: 15px;
|
657 |
+
border-left: 4px solid #007aff;
|
658 |
+
background: white;
|
659 |
+
border-radius: 4px;
|
660 |
+
}
|
661 |
+
|
662 |
+
.search-item h3 {
|
663 |
+
margin: 0 0 10px 0;
|
664 |
+
color: #1a0dab;
|
665 |
+
}
|
666 |
+
|
667 |
+
.search-item a {
|
668 |
+
color: inherit;
|
669 |
+
text-decoration: none;
|
670 |
+
}
|
671 |
+
|
672 |
+
.search-item p {
|
673 |
+
margin: 0;
|
674 |
+
color: #4d5156;
|
675 |
+
font-size: 14px;
|
676 |
+
line-height: 1.5;
|
677 |
+
}
|
678 |
|
679 |
.empty-content {
|
680 |
padding: 40px !important;
|
|
|
782 |
""", theme=theme)
|
783 |
|
784 |
|
|
|
785 |
with demo:
|
786 |
with gr.Tabs(elem_classes="main-tabs") as tabs:
|
787 |
with gr.Tab("Visual AI Assistant", elem_id="mouse-tab", elem_classes="mouse-tab"):
|
|
|
788 |
setting = gr.State({
|
789 |
"system": SystemPrompt,
|
790 |
})
|
791 |
|
792 |
+
#NEW - ๊ฒ์ ๋ชจ๋ ์ํ ์ถ๊ฐ
|
793 |
+
search_mode = gr.State(False)
|
794 |
+
|
795 |
+
|
796 |
+
|
797 |
with ms.Application() as app:
|
798 |
with antd.ConfigProvider():
|
799 |
|
|
|
1012 |
elem_classes="deploy-result"
|
1013 |
)
|
1014 |
|
1015 |
+
|
1016 |
+
# ๋ฒํผ ์ด๋ฒคํธ ํธ๋ค๋ฌ ์์
|
1017 |
+
btn.click(
|
1018 |
+
fn=lambda q, s, m: execute_search_and_generate(q, s) if m else demo_instance.generation_code(q, s),
|
1019 |
+
inputs=[input, setting, search_mode],
|
1020 |
+
outputs=[code_output, sandbox, state_tab, code_drawer]
|
1021 |
+
).then(
|
1022 |
+
fn=update_placeholder,
|
1023 |
+
inputs=[],
|
1024 |
+
outputs=[input]
|
1025 |
+
)
|
1026 |
+
|
1027 |
+
#NEW - ๊ฒ์ ๋ชจ๋ ํ ๊ธ ๋ฒํผ ์ถ๊ฐ
|
1028 |
+
search_toggle = antd.Button(
|
1029 |
+
"Toggle Search Mode",
|
1030 |
+
type="default",
|
1031 |
+
size="large",
|
1032 |
+
elem_classes="search-toggle-btn"
|
1033 |
+
)
|
1034 |
+
|
1035 |
+
search_toggle.click(
|
1036 |
+
fn=lambda x: not x,
|
1037 |
+
inputs=[search_mode],
|
1038 |
+
outputs=[search_mode]
|
1039 |
+
)
|
1040 |
+
|
1041 |
+
|
1042 |
# ์ฐ์ธก ํจ๋
|
1043 |
with antd.Col(span=24, md=16):
|
1044 |
with ms.Div(elem_classes="right_panel"):
|