openfree commited on
Commit
d940931
ยท
verified ยท
1 Parent(s): 52e7e4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -83
app.py CHANGED
@@ -571,8 +571,8 @@ def create_main_interface():
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,7 +642,7 @@ The response should be in HTML format with appropriate styling."""
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,25 +652,24 @@ The response should be in HTML format with appropriate styling."""
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
-
672
- async def handle_generation(query, setting, is_search):
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
- except Exception as e:
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
- custom_css = f.read()
690
-
691
- #NEW - ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ์Šคํƒ€์ผ ์ถ”๊ฐ€
692
- custom_css += """
693
- .search-summary {
694
- margin: 20px 0;
695
- padding: 20px;
696
- background: #f8f9fa;
697
- border-radius: 10px;
698
- }
699
-
700
- .search-item {
701
- margin-bottom: 15px;
702
- padding: 15px;
703
- border-left: 4px solid #007aff;
704
- background: white;
705
- border-radius: 4px;
706
- }
707
-
708
- .search-item h3 {
709
- margin: 0 0 10px 0;
710
- color: #1a0dab;
711
- }
712
-
713
- .search-item a {
714
- color: inherit;
715
- text-decoration: none;
716
- }
717
-
718
- .search-item p {
719
- margin: 0;
720
- color: #4d5156;
721
- font-size: 14px;
722
- line-height: 1.5;
723
- }
724
-
725
- .empty-content {
726
- padding: 40px !important;
727
- background: #f8f9fa !important;
728
- border-radius: 10px !important;
729
- margin: 20px !important;
730
- }
731
-
732
- .container {
733
- background: #f0f0f0;
734
- min-height: 100vh;
735
- padding: 20px;
736
- display: flex;
737
- justify-content: center;
738
- align-items: center;
739
- font-family: -apple-system, BlinkMacSystemFont, sans-serif;
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
 
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