openfree commited on
Commit
38ded30
ยท
verified ยท
1 Parent(s): 21e19d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +279 -92
app.py CHANGED
@@ -457,7 +457,8 @@ def get_random_placeholder():
457
 
458
  def update_placeholder():
459
  return gr.update(placeholder=get_random_placeholder())
460
-
 
461
  def create_main_interface():
462
  """๋ฉ”์ธ ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ ํ•จ์ˆ˜"""
463
 
@@ -480,19 +481,112 @@ def create_main_interface():
480
  with open('app.css', 'r', encoding='utf-8') as f:
481
  custom_css = f.read()
482
 
483
- demo = gr.Blocks(css=custom_css, theme=theme)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
484
 
485
  with demo:
486
  with gr.Tabs(elem_classes="main-tabs") as tabs:
487
  with gr.Tab("Visual AI Assistant", elem_id="mouse-tab", elem_classes="mouse-tab"):
488
- history = gr.State([])
489
- setting = gr.State({
490
- "system": SystemPrompt,
491
- })
492
-
493
  with ms.Application() as app:
494
  with antd.ConfigProvider():
495
- # Drawer ์ปดํฌ๋„ŒํŠธ๋“ค
 
496
  with antd.Drawer(open=False, title="AI is Creating...", placement="left", width="750px") as code_drawer:
497
  gr.HTML("""
498
  <div class="thinking-container">
@@ -502,7 +596,7 @@ def create_main_interface():
502
  padding: 20px;
503
  background: #f8f9fa;
504
  border-radius: 15px;
505
- font-family: 'Arial', sans-serif;
506
  }
507
 
508
  .progress-bar {
@@ -517,7 +611,7 @@ def create_main_interface():
517
  .progress-bar-inner {
518
  width: 30%;
519
  height: 100%;
520
- background: linear-gradient(90deg, #1890ff, #52c41a);
521
  animation: progress 2s ease-in-out infinite;
522
  }
523
 
@@ -536,13 +630,8 @@ def create_main_interface():
536
  transition: all 0.3s ease;
537
  }
538
 
539
- .tip-box:hover {
540
- transform: translateY(-5px);
541
- box-shadow: 0 6px 16px rgba(0,0,0,0.15);
542
- }
543
-
544
  .status-text {
545
- color: #1890ff;
546
  font-size: 18px;
547
  margin: 15px 0;
548
  animation: fade 1.5s ease infinite;
@@ -557,7 +646,7 @@ def create_main_interface():
557
 
558
  .icon-item {
559
  padding: 10px;
560
- background: rgba(24,144,255,0.1);
561
  border-radius: 8px;
562
  animation: pulse 2s ease infinite;
563
  }
@@ -585,22 +674,18 @@ def create_main_interface():
585
  </style>
586
 
587
  <div class="thinking-icon">๐ŸŽจ</div>
588
-
589
  <div class="status-text">Creating Your Visualization...</div>
590
-
591
  <div class="progress-bar">
592
  <div class="progress-bar-inner"></div>
593
  </div>
594
-
595
  <div class="icon-grid">
596
  <div class="icon-item">๐Ÿ“Š</div>
597
  <div class="icon-item">๐ŸŽฏ</div>
598
  <div class="icon-item">๐Ÿ’ก</div>
599
  <div class="icon-item">โœจ</div>
600
  </div>
601
-
602
  <div class="tip-box">
603
- <h3 style="color: #1890ff; margin-bottom: 10px;">Did You Know?</h3>
604
  <div id="tip-content" style="font-size: 16px; line-height: 1.6;"></div>
605
  </div>
606
 
@@ -637,86 +722,132 @@ def create_main_interface():
637
  code_output = legacy.Markdown(visible=False)
638
 
639
 
640
-
641
- with antd.Drawer(open=False, title="history", placement="left", width="900px") as history_drawer:
642
- history_output = legacy.Chatbot(show_label=False, flushing=False, height=960, elem_classes="history_chatbot")
643
-
644
-
645
- with antd.Drawer(open=False, title="history", placement="left", width="900px") as history_drawer:
646
- history_output = legacy.Chatbot(show_label=False, flushing=False, height=960, elem_classes="history_chatbot")
647
-
648
- # ๋ฉ”์ธ ์ปจํ…์ธ ๋ฅผ ์œ„ํ•œ Row
649
  with antd.Row(gutter=[32, 12]) as layout:
650
  # ์ขŒ์ธก ํŒจ๋„
651
  with antd.Col(span=24, md=8):
652
  with antd.Flex(vertical=True, gap="middle", wrap=True):
653
- # ํ—ค๋” ๋ถ€๋ถ„
654
- header = gr.HTML(f"""
655
- <div class="left_header">
656
- <img src="data:image/gif;base64,{get_image_base64('mouse.gif')}" width="360px" />
657
- <h1 style="font-size: 18px;">MOUSE-Chat: Visual AI Assistant</h1>
658
- <h1 style="font-size: 10px;">Transform your questions into stunning visual presentations. Every response is crafted with beautiful graphics, charts, and interactive elements.</h1>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
659
  </div>
660
- """)
661
-
662
-
663
 
664
  # ์ž…๋ ฅ ์˜์—ญ
665
  input = antd.InputTextarea(
666
  size="large",
667
- allow_clear=True,
668
-
669
- placeholder=get_random_placeholder()
 
 
 
 
 
 
 
670
  )
671
 
672
  # ๋ฒ„ํŠผ ๊ทธ๋ฃน
673
- with antd.Flex(gap="small", justify="space-between"):
674
- btn = antd.Button("Generate", type="primary", size="large")
675
- boost_btn = antd.Button("Enhance", type="default", size="large")
676
- deploy_btn = antd.Button("Share", type="default", size="large")
677
- clear_btn = antd.Button("Clear", type="default", size="large")
678
- historyBtn = antd.Button("๐Ÿ“œ History", type="default")
679
-
680
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
681
 
682
- deploy_result = gr.HTML(label="๋ฐฐํฌ ๊ฒฐ๊ณผ")
 
 
 
683
 
684
  # ์šฐ์ธก ํŒจ๋„
685
  with antd.Col(span=24, md=16):
686
  with ms.Div(elem_classes="right_panel"):
687
- # ์ƒ๋‹จ ๋ฒ„ํŠผ๋“ค
688
- with antd.Flex(gap="small", elem_classes="setting-buttons"):
689
- historyBtn = antd.Button("๐Ÿ“œ ํžˆ์Šคํ† ๋ฆฌ", type="default")
690
-
691
- gr.HTML('<div class="render_header"><span class="header_btn"></span><span class="header_btn"></span><span class="header_btn"></span></div>')
 
 
 
 
 
 
 
 
692
 
693
  # ํƒญ ์ปจํ…์ธ 
694
  with antd.Tabs(active_key="empty", render_tab_bar="() => null") as state_tab:
695
  with antd.Tabs.Item(key="empty"):
696
-
697
- empty = antd.Empty(description="Enter your question to begin", elem_classes="right_content")
698
-
 
 
 
 
 
 
 
 
699
  with antd.Tabs.Item(key="loading"):
700
- loading = antd.Spin(True, tip="Creating visual presentation...", size="large", elem_classes="right_content")
 
 
 
 
 
 
701
  with antd.Tabs.Item(key="render"):
702
  sandbox = gr.HTML(elem_classes="html_content")
 
703
 
704
-
705
-
706
-
707
- # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์—ฐ๊ฒฐ
708
- historyBtn.click(
709
- history_render,
710
- inputs=[history],
711
- outputs=[history_drawer, history_output]
712
- )
713
-
714
- history_drawer.close(
715
- lambda: gr.update(open=False),
716
- inputs=[],
717
- outputs=[history_drawer]
718
- )
719
-
720
  btn.click(
721
  demo_instance.generation_code,
722
  inputs=[input, setting, history],
@@ -726,18 +857,6 @@ def create_main_interface():
726
  inputs=[],
727
  outputs=[input]
728
  )
729
-
730
-
731
-
732
- clear_btn.click(
733
- fn=lambda: (
734
- demo_instance.clear_history(), # history ์ดˆ๊ธฐํ™”
735
- update_placeholder() # placeholder ์—…๋ฐ์ดํŠธ
736
- ),
737
- inputs=[],
738
- outputs=[history, input] # input๋„ ์ถœ๋ ฅ์— ์ถ”๊ฐ€
739
- )
740
-
741
 
742
  boost_btn.click(
743
  fn=handle_boost,
@@ -746,11 +865,67 @@ def create_main_interface():
746
  )
747
 
748
  deploy_btn.click(
749
- fn=lambda code: deploy_to_vercel(remove_code_block(code)) if code else "์ฝ”๋“œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.",
750
  inputs=[code_output],
751
  outputs=[deploy_result]
752
  )
753
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
754
  return demo
755
 
756
  # ๋ฉ”์ธ ์‹คํ–‰ ๋ถ€๋ถ„
@@ -758,7 +933,19 @@ if __name__ == "__main__":
758
  try:
759
  demo_instance = Demo() # Demo ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ
760
  demo = create_main_interface() # ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
761
- demo.queue(default_concurrency_limit=20).launch(server_name="0.0.0.0", server_port=7860) # ์„œ๋ฒ„ ์„ค์ • ์ถ”๊ฐ€
 
 
 
 
 
 
 
 
 
762
  except Exception as e:
763
  print(f"Initialization error: {e}")
764
- raise
 
 
 
 
457
 
458
  def update_placeholder():
459
  return gr.update(placeholder=get_random_placeholder())
460
+
461
+
462
  def create_main_interface():
463
  """๋ฉ”์ธ ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ ํ•จ์ˆ˜"""
464
 
 
481
  with open('app.css', 'r', encoding='utf-8') as f:
482
  custom_css = f.read()
483
 
484
+ demo = gr.Blocks(css=custom_css + """
485
+ .container {
486
+ background: #f0f0f0;
487
+ min-height: 100vh;
488
+ padding: 20px;
489
+ display: flex;
490
+ justify-content: center;
491
+ align-items: center;
492
+ font-family: -apple-system, BlinkMacSystemFont, sans-serif;
493
+ }
494
+
495
+ .app-window {
496
+ background: white;
497
+ border-radius: 10px;
498
+ box-shadow: 0 20px 40px rgba(0,0,0,0.1);
499
+ width: 100%;
500
+ max-width: 1400px;
501
+ overflow: hidden;
502
+ }
503
+
504
+ .window-header {
505
+ background: #f0f0f0;
506
+ padding: 12px 16px;
507
+ display: flex;
508
+ align-items: center;
509
+ border-bottom: 1px solid #e0e0e0;
510
+ }
511
+
512
+ .window-controls {
513
+ display: flex;
514
+ gap: 8px;
515
+ }
516
+
517
+ .control {
518
+ width: 12px;
519
+ height: 12px;
520
+ border-radius: 50%;
521
+ cursor: pointer;
522
+ }
523
+
524
+ .control.close { background: #ff5f57; }
525
+ .control.minimize { background: #febc2e; }
526
+ .control.maximize { background: #28c840; }
527
+
528
+ .window-title {
529
+ flex: 1;
530
+ text-align: center;
531
+ color: #333;
532
+ font-size: 14px;
533
+ font-weight: 500;
534
+ }
535
+
536
+ .main-content {
537
+ display: flex;
538
+ height: calc(100vh - 100px);
539
+ }
540
+
541
+ .left-panel {
542
+ width: 40%;
543
+ border-right: 1px solid #e0e0e0;
544
+ padding: 20px;
545
+ display: flex;
546
+ flex-direction: column;
547
+ }
548
+
549
+ .right-panel {
550
+ width: 60%;
551
+ background: #fff;
552
+ position: relative;
553
+ }
554
+
555
+ .input-area {
556
+ background: #f8f9fa;
557
+ border-radius: 10px;
558
+ padding: 20px;
559
+ margin-top: 20px;
560
+ }
561
+
562
+ .button-group {
563
+ display: flex;
564
+ gap: 10px;
565
+ margin-top: 20px;
566
+ }
567
+
568
+ .custom-button {
569
+ background: #007aff;
570
+ color: white;
571
+ border: none;
572
+ padding: 10px 20px;
573
+ border-radius: 6px;
574
+ cursor: pointer;
575
+ transition: all 0.2s;
576
+ }
577
+
578
+ .custom-button:hover {
579
+ background: #0056b3;
580
+ }
581
+ """, theme=theme)
582
 
583
  with demo:
584
  with gr.Tabs(elem_classes="main-tabs") as tabs:
585
  with gr.Tab("Visual AI Assistant", elem_id="mouse-tab", elem_classes="mouse-tab"):
 
 
 
 
 
586
  with ms.Application() as app:
587
  with antd.ConfigProvider():
588
+
589
+ # Drawer ์ปดํฌ๋„ŒํŠธ
590
  with antd.Drawer(open=False, title="AI is Creating...", placement="left", width="750px") as code_drawer:
591
  gr.HTML("""
592
  <div class="thinking-container">
 
596
  padding: 20px;
597
  background: #f8f9fa;
598
  border-radius: 15px;
599
+ font-family: -apple-system, BlinkMacSystemFont, sans-serif;
600
  }
601
 
602
  .progress-bar {
 
611
  .progress-bar-inner {
612
  width: 30%;
613
  height: 100%;
614
+ background: linear-gradient(90deg, #007aff, #28c840);
615
  animation: progress 2s ease-in-out infinite;
616
  }
617
 
 
630
  transition: all 0.3s ease;
631
  }
632
 
 
 
 
 
 
633
  .status-text {
634
+ color: #007aff;
635
  font-size: 18px;
636
  margin: 15px 0;
637
  animation: fade 1.5s ease infinite;
 
646
 
647
  .icon-item {
648
  padding: 10px;
649
+ background: rgba(0,122,255,0.1);
650
  border-radius: 8px;
651
  animation: pulse 2s ease infinite;
652
  }
 
674
  </style>
675
 
676
  <div class="thinking-icon">๐ŸŽจ</div>
 
677
  <div class="status-text">Creating Your Visualization...</div>
 
678
  <div class="progress-bar">
679
  <div class="progress-bar-inner"></div>
680
  </div>
 
681
  <div class="icon-grid">
682
  <div class="icon-item">๐Ÿ“Š</div>
683
  <div class="icon-item">๐ŸŽฏ</div>
684
  <div class="icon-item">๐Ÿ’ก</div>
685
  <div class="icon-item">โœจ</div>
686
  </div>
 
687
  <div class="tip-box">
688
+ <h3 style="color: #007aff; margin-bottom: 10px;">Did You Know?</h3>
689
  <div id="tip-content" style="font-size: 16px; line-height: 1.6;"></div>
690
  </div>
691
 
 
722
  code_output = legacy.Markdown(visible=False)
723
 
724
 
725
+ # ๋ฉ”์ธ ์ปจํ…์ธ ๋ฅผ ์œ„ํ•œ Row
 
 
 
 
 
 
 
 
726
  with antd.Row(gutter=[32, 12]) as layout:
727
  # ์ขŒ์ธก ํŒจ๋„
728
  with antd.Col(span=24, md=8):
729
  with antd.Flex(vertical=True, gap="middle", wrap=True):
730
+ # macOS ์Šคํƒ€์ผ ์œˆ๋„์šฐ ํ—ค๋”
731
+ header = gr.HTML("""
732
+ <div class="window-frame">
733
+ <div class="window-header">
734
+ <div class="window-controls">
735
+ <div class="control close"></div>
736
+ <div class="control minimize"></div>
737
+ <div class="control maximize"></div>
738
+ </div>
739
+ <div class="window-title">
740
+ <div class="window-address">
741
+ <div class="secure-icon">๐Ÿ”’</div>
742
+ <div class="url-bar">mouse-i.visualization.app</div>
743
+ </div>
744
+ </div>
745
+ </div>
746
+ <div class="app-content">
747
+ <img src="data:image/gif;base64,{}" width="360px" />
748
+ <h1 class="app-title">MOUSE-I: Visual AI Assistant</h1>
749
+ <p class="app-description">Transform your ideas into stunning visual presentations</p>
750
+ </div>
751
  </div>
752
+ """.format(get_image_base64('mouse.gif')))
 
 
753
 
754
  # ์ž…๋ ฅ ์˜์—ญ
755
  input = antd.InputTextarea(
756
  size="large",
757
+ allow_clear=True,
758
+ placeholder=get_random_placeholder(),
759
+ style={
760
+ "background": "#f8f9fa",
761
+ "border": "1px solid #e0e0e0",
762
+ "borderRadius": "10px",
763
+ "padding": "15px",
764
+ "minHeight": "150px",
765
+ "fontFamily": "-apple-system, BlinkMacSystemFont, sans-serif"
766
+ }
767
  )
768
 
769
  # ๋ฒ„ํŠผ ๊ทธ๋ฃน
770
+ with antd.Flex(gap="small", justify="flex-start"):
771
+ btn = antd.Button(
772
+ "Generate",
773
+ type="primary",
774
+ size="large",
775
+ style={
776
+ "background": "#007aff",
777
+ "borderRadius": "8px",
778
+ "boxShadow": "0 2px 4px rgba(0,0,0,0.1)"
779
+ }
780
+ )
781
+ boost_btn = antd.Button(
782
+ "Enhance",
783
+ type="default",
784
+ size="large",
785
+ style={
786
+ "borderRadius": "8px",
787
+ "border": "1px solid #007aff",
788
+ "color": "#007aff"
789
+ }
790
+ )
791
+ deploy_btn = antd.Button(
792
+ "Share",
793
+ type="default",
794
+ size="large",
795
+ style={
796
+ "borderRadius": "8px",
797
+ "border": "1px solid #28c840",
798
+ "color": "#28c840"
799
+ }
800
+ )
801
 
802
+ deploy_result = gr.HTML(
803
+ label="Share Result",
804
+ elem_classes="deploy-result"
805
+ )
806
 
807
  # ์šฐ์ธก ํŒจ๋„
808
  with antd.Col(span=24, md=16):
809
  with ms.Div(elem_classes="right_panel"):
810
+ # macOS ์Šคํƒ€์ผ ์œˆ๋„์šฐ ํ—ค๋”
811
+ gr.HTML("""
812
+ <div class="window-frame">
813
+ <div class="window-header">
814
+ <div class="window-controls">
815
+ <div class="control close"></div>
816
+ <div class="control minimize"></div>
817
+ <div class="control maximize"></div>
818
+ </div>
819
+ <div class="window-title">Preview</div>
820
+ </div>
821
+ </div>
822
+ """)
823
 
824
  # ํƒญ ์ปจํ…์ธ 
825
  with antd.Tabs(active_key="empty", render_tab_bar="() => null") as state_tab:
826
  with antd.Tabs.Item(key="empty"):
827
+ empty = antd.Empty(
828
+ description="Enter your question to begin",
829
+ elem_classes="right_content",
830
+ style={
831
+ "padding": "40px",
832
+ "background": "#f8f9fa",
833
+ "borderRadius": "10px",
834
+ "margin": "20px"
835
+ }
836
+ )
837
+
838
  with antd.Tabs.Item(key="loading"):
839
+ loading = antd.Spin(
840
+ True,
841
+ tip="Creating visual presentation...",
842
+ size="large",
843
+ elem_classes="right_content"
844
+ )
845
+
846
  with antd.Tabs.Item(key="render"):
847
  sandbox = gr.HTML(elem_classes="html_content")
848
+
849
 
850
+ # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์—ฐ๊ฒฐ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
851
  btn.click(
852
  demo_instance.generation_code,
853
  inputs=[input, setting, history],
 
857
  inputs=[],
858
  outputs=[input]
859
  )
 
 
 
 
 
 
 
 
 
 
 
 
860
 
861
  boost_btn.click(
862
  fn=handle_boost,
 
865
  )
866
 
867
  deploy_btn.click(
868
+ fn=lambda code: deploy_to_vercel(remove_code_block(code)) if code else "No code to share.",
869
  inputs=[code_output],
870
  outputs=[deploy_result]
871
  )
872
 
873
+ # ์ถ”๊ฐ€ ์Šคํƒ€์ผ ์ ์šฉ
874
+ gr.HTML("""
875
+ <style>
876
+ .app-content {
877
+ padding: 20px;
878
+ text-align: center;
879
+ }
880
+
881
+ .app-title {
882
+ font-size: 24px;
883
+ color: #333;
884
+ margin: 20px 0 10px;
885
+ font-weight: 600;
886
+ }
887
+
888
+ .app-description {
889
+ color: #666;
890
+ font-size: 14px;
891
+ margin-bottom: 30px;
892
+ }
893
+
894
+ .deploy-result {
895
+ margin-top: 20px;
896
+ padding: 15px;
897
+ background: #f8f9fa;
898
+ border-radius: 8px;
899
+ font-family: -apple-system, BlinkMacSystemFont, sans-serif;
900
+ }
901
+
902
+ .deploy-result a {
903
+ color: #007aff;
904
+ text-decoration: none;
905
+ font-weight: 500;
906
+ }
907
+
908
+ .deploy-result a:hover {
909
+ text-decoration: underline;
910
+ }
911
+
912
+ /* ๋ฐ˜์‘ํ˜• ๋””์ž์ธ์„ ์œ„ํ•œ ๋ฏธ๋””์–ด ์ฟผ๋ฆฌ */
913
+ @media (max-width: 768px) {
914
+ .window-frame {
915
+ border-radius: 0;
916
+ }
917
+
918
+ .left-panel, .right-panel {
919
+ width: 100%;
920
+ }
921
+
922
+ .main-content {
923
+ flex-direction: column;
924
+ }
925
+ }
926
+ </style>
927
+ """)
928
+
929
  return demo
930
 
931
  # ๋ฉ”์ธ ์‹คํ–‰ ๋ถ€๋ถ„
 
933
  try:
934
  demo_instance = Demo() # Demo ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ
935
  demo = create_main_interface() # ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
936
+ demo.queue(
937
+ concurrency_count=20,
938
+ status_update_rate=10,
939
+ api_open=False
940
+ ).launch(
941
+ server_name="0.0.0.0",
942
+ server_port=7860,
943
+ share=False,
944
+ debug=False
945
+ )
946
  except Exception as e:
947
  print(f"Initialization error: {e}")
948
+ raise
949
+
950
+
951
+