Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -567,28 +567,15 @@ def update_placeholder():
|
|
567 |
return gr.update(placeholder=get_random_placeholder())
|
568 |
|
569 |
|
570 |
-
|
571 |
-
def create_main_interface():
|
572 |
-
"""๋ฉ์ธ ์ธํฐํ์ด์ค ์์ฑ ํจ์"""
|
573 |
-
|
574 |
-
async def handle_generation(query, setting, is_search):
|
575 |
-
try:
|
576 |
-
print(f"Mode: {'Web Search' if is_search else 'Generate'}") # ๋๋ฒ๊น
์ฉ
|
577 |
-
if is_search:
|
578 |
-
print("Executing search and generate...") # ๋๋ฒ๊น
์ฉ
|
579 |
-
return await execute_search_and_generate(query, setting)
|
580 |
-
else:
|
581 |
-
print("Executing normal generation...") # ๋๋ฒ๊น
์ฉ
|
582 |
-
async for result in demo_instance.generation_code(query, setting):
|
583 |
-
final_result = result
|
584 |
-
return final_result
|
585 |
-
except Exception as e:
|
586 |
-
print(f"Generation error: {str(e)}")
|
587 |
-
return ["", None, gr.update(active_key="error"), gr.update(open=False)]
|
588 |
|
589 |
-
|
|
|
|
|
|
|
|
|
|
|
590 |
try:
|
591 |
-
print(f"Executing search for query: {query}")
|
592 |
|
593 |
# ๊ฒ์ ์คํ
|
594 |
url = "https://api.serphouse.com/serp/live"
|
@@ -601,9 +588,7 @@ def create_main_interface():
|
|
601 |
"serp_type": "news",
|
602 |
"loc": "United States",
|
603 |
"page": "1",
|
604 |
-
"num": "10"
|
605 |
-
"ie": "UTF-8",
|
606 |
-
"tbm": "nws"
|
607 |
}
|
608 |
}
|
609 |
headers = {
|
@@ -611,67 +596,57 @@ def create_main_interface():
|
|
611 |
"Content-Type": "application/json"
|
612 |
}
|
613 |
|
614 |
-
print("Sending API request...") # ๋๋ฒ๊น
์ฉ
|
615 |
response = requests.post(url, headers=headers, json=payload)
|
616 |
-
print(f"API Response status: {response.status_code}") # ๋๋ฒ๊น
์ฉ
|
617 |
-
|
618 |
-
if response.status_code != 200:
|
619 |
-
print(f"API Error: {response.text}") # ๋๋ฒ๊น
์ฉ
|
620 |
-
raise Exception(f"API request failed with status {response.status_code}")
|
621 |
-
|
622 |
results = response.json()
|
623 |
-
print(f"
|
624 |
|
625 |
-
# ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ HTML๋ก
|
626 |
-
|
627 |
-
|
628 |
|
|
|
629 |
if 'results' in results:
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
for item in news_results[:5]: # ์์ 5๊ฐ ๊ฒฐ๊ณผ๋ง ์ฌ์ฉ
|
634 |
-
search_summary += f"""
|
635 |
<div class="search-item">
|
636 |
-
<h3><a href="{item
|
637 |
-
<p>{item
|
638 |
<div class="search-meta">
|
639 |
-
<span class="source">{item
|
640 |
-
<span class="time">{item
|
641 |
</div>
|
642 |
</div>
|
643 |
"""
|
644 |
-
|
645 |
|
646 |
-
# ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ํฌํจํ
|
647 |
enhanced_prompt = f"""Based on these news search results, create a comprehensive visual summary:
|
648 |
|
649 |
-
|
650 |
-
|
651 |
-
{search_summary}
|
652 |
|
653 |
Please create a visually appealing HTML response that:
|
654 |
-
1. Summarizes the key points from the news
|
655 |
-
2. Organizes information in a clear
|
656 |
-
3. Uses appropriate
|
657 |
-
4. Includes
|
658 |
-
5.
|
659 |
|
660 |
-
|
661 |
-
"""
|
662 |
|
663 |
-
print("Generating response with
|
664 |
|
665 |
# async generator๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ์ํ ์์
|
666 |
async for result in demo_instance.generation_code(enhanced_prompt, setting):
|
667 |
final_result = result
|
|
|
668 |
|
669 |
print("Response generation completed") # ๋๋ฒ๊น
์ฉ
|
670 |
return final_result
|
671 |
|
672 |
except Exception as e:
|
673 |
-
print(f"Search error: {str(e)}")
|
674 |
-
print(f"Full error details: {str(e.__class__.__name__)}: {str(e)}")
|
675 |
return [
|
676 |
"",
|
677 |
None,
|
@@ -694,7 +669,23 @@ Make sure to maintain proper HTML formatting in the response.
|
|
694 |
print(f"Error executing code: {str(e)}")
|
695 |
return None, gr.update(active_key="empty")
|
696 |
|
|
|
697 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
698 |
|
699 |
# CSS ํ์ผ ๋ด์ฉ์ ์ง์ ์ ์ฉ
|
700 |
with open('app.css', 'r', encoding='utf-8') as f:
|
|
|
567 |
return gr.update(placeholder=get_random_placeholder())
|
568 |
|
569 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
570 |
|
571 |
+
|
572 |
+
def create_main_interface():
|
573 |
+
"""๋ฉ์ธ ์ธํฐํ์ด์ค ์์ฑ ํจ์"""
|
574 |
+
|
575 |
+
#NEW - ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ํตํฉํ ์๋ต ์์ฑ ํจ์
|
576 |
+
async def execute_search_and_generate(query, setting):
|
577 |
try:
|
578 |
+
print(f"Executing search for query: {query}")
|
579 |
|
580 |
# ๊ฒ์ ์คํ
|
581 |
url = "https://api.serphouse.com/serp/live"
|
|
|
588 |
"serp_type": "news",
|
589 |
"loc": "United States",
|
590 |
"page": "1",
|
591 |
+
"num": "10"
|
|
|
|
|
592 |
}
|
593 |
}
|
594 |
headers = {
|
|
|
596 |
"Content-Type": "application/json"
|
597 |
}
|
598 |
|
|
|
599 |
response = requests.post(url, headers=headers, json=payload)
|
|
|
|
|
|
|
|
|
|
|
|
|
600 |
results = response.json()
|
601 |
+
print(f"Search results: {results}") # ๋๋ฒ๊น
์ฉ
|
602 |
|
603 |
+
# ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ HTML๋ก ๋ณํ
|
604 |
+
search_content = "```html\n<div class='search-results'>\n"
|
605 |
+
search_content += "<h2>์ต์ ๋ด์ค ๊ฒ์ ๊ฒฐ๊ณผ</h2>\n"
|
606 |
|
607 |
+
# API ์๋ต ๊ตฌ์กฐ์ ๋ง๊ฒ ์์
|
608 |
if 'results' in results:
|
609 |
+
news_items = results['results'].get('news', [])
|
610 |
+
for item in news_items[:5]:
|
611 |
+
search_content += f"""
|
|
|
|
|
612 |
<div class="search-item">
|
613 |
+
<h3><a href="{item['url']}" target="_blank">{item['title']}</a></h3>
|
614 |
+
<p>{item['snippet']}</p>
|
615 |
<div class="search-meta">
|
616 |
+
<span class="source">{item['channel']}</span>
|
617 |
+
<span class="time">{item['time']}</span>
|
618 |
</div>
|
619 |
</div>
|
620 |
"""
|
621 |
+
search_content += "</div>\n```"
|
622 |
|
623 |
+
# ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ํฌํจํ ํ๋กฌํํธ ์์ฑ
|
624 |
enhanced_prompt = f"""Based on these news search results, create a comprehensive visual summary:
|
625 |
|
626 |
+
{search_content}
|
|
|
|
|
627 |
|
628 |
Please create a visually appealing HTML response that:
|
629 |
+
1. Summarizes the key points from the news
|
630 |
+
2. Organizes information in a clear structure
|
631 |
+
3. Uses appropriate HTML formatting and styling
|
632 |
+
4. Includes relevant quotes and statistics
|
633 |
+
5. Provides proper source attribution
|
634 |
|
635 |
+
The response should be in HTML format with appropriate styling."""
|
|
|
636 |
|
637 |
+
print("Generating response with search results...") # ๋๋ฒ๊น
์ฉ
|
638 |
|
639 |
# async generator๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ์ํ ์์
|
640 |
async for result in demo_instance.generation_code(enhanced_prompt, setting):
|
641 |
final_result = result
|
642 |
+
print(f"Generated result: {final_result}") # ๋๋ฒ๊น
์ฉ
|
643 |
|
644 |
print("Response generation completed") # ๋๋ฒ๊น
์ฉ
|
645 |
return final_result
|
646 |
|
647 |
except Exception as e:
|
648 |
+
print(f"Search error: {str(e)}")
|
649 |
+
print(f"Full error details: {str(e.__class__.__name__)}: {str(e)}")
|
650 |
return [
|
651 |
"",
|
652 |
None,
|
|
|
669 |
print(f"Error executing code: {str(e)}")
|
670 |
return None, gr.update(active_key="empty")
|
671 |
|
672 |
+
|
673 |
|
674 |
+
|
675 |
+
async def handle_generation(query, setting, is_search):
|
676 |
+
try:
|
677 |
+
print(f"Mode: {'Web Search' if is_search else 'Generate'}") # ๋๋ฒ๊น
์ฉ
|
678 |
+
if is_search:
|
679 |
+
print("Executing search and generate...") # ๋๋ฒ๊น
์ฉ
|
680 |
+
return await execute_search_and_generate(query, setting)
|
681 |
+
else:
|
682 |
+
print("Executing normal generation...") # ๋๋ฒ๊น
์ฉ
|
683 |
+
async for result in demo_instance.generation_code(query, setting):
|
684 |
+
final_result = result
|
685 |
+
return final_result
|
686 |
+
except Exception as e:
|
687 |
+
print(f"Generation error: {str(e)}")
|
688 |
+
return ["", None, gr.update(active_key="error"), gr.update(open=False)]
|
689 |
|
690 |
# CSS ํ์ผ ๋ด์ฉ์ ์ง์ ์ ์ฉ
|
691 |
with open('app.css', 'r', encoding='utf-8') as f:
|