openfree commited on
Commit
21e19d9
·
verified ·
1 Parent(s): 12c7fbd

Update app-backup.py

Browse files
Files changed (1) hide show
  1. app-backup.py +159 -14
app-backup.py CHANGED
@@ -258,7 +258,7 @@ class Demo:
258
 
259
  async def generation_code(self, query: Optional[str], _setting: Dict[str, str], _history: Optional[History]):
260
  if not query or query.strip() == '':
261
- query = random.choice(DEMO_LIST)['description']
262
 
263
  if _history is None:
264
  _history = []
@@ -281,8 +281,9 @@ class Demo:
281
  openai_messages.append({"role": "user", "content": query})
282
 
283
  try:
 
284
  yield [
285
- "Generating code...",
286
  _history,
287
  None,
288
  gr.update(active_key="loading"),
@@ -294,28 +295,28 @@ class Demo:
294
  try:
295
  async for content in try_claude_api(system_message, claude_messages):
296
  yield [
297
- content,
298
  _history,
299
  None,
300
  gr.update(active_key="loading"),
301
  gr.update(open=True)
302
  ]
303
  await asyncio.sleep(0)
304
- collected_content = content
305
-
306
  except Exception as claude_error:
307
  print(f"Falling back to OpenAI API due to Claude error: {str(claude_error)}")
308
 
309
  async for content in try_openai_api(openai_messages):
310
  yield [
311
- content,
312
  _history,
313
  None,
314
  gr.update(active_key="loading"),
315
  gr.update(open=True)
316
  ]
317
  await asyncio.sleep(0)
318
- collected_content = content
319
 
320
  if collected_content:
321
  _history = messages_to_history([
@@ -325,13 +326,13 @@ class Demo:
325
  'content': collected_content
326
  }])
327
 
328
- # code_drawer를 닫도록 수정
329
  yield [
330
  collected_content,
331
  _history,
332
  send_to_sandbox(remove_code_block(collected_content)),
333
  gr.update(active_key="render"),
334
- gr.update(open=False) # code_drawer를 닫음
335
  ]
336
 
337
  else:
@@ -483,9 +484,7 @@ def create_main_interface():
483
 
484
  with demo:
485
  with gr.Tabs(elem_classes="main-tabs") as tabs:
486
- # MOUSE 탭
487
  with gr.Tab("Visual AI Assistant", elem_id="mouse-tab", elem_classes="mouse-tab"):
488
-
489
  history = gr.State([])
490
  setting = gr.State({
491
  "system": SystemPrompt,
@@ -493,9 +492,155 @@ def create_main_interface():
493
 
494
  with ms.Application() as app:
495
  with antd.ConfigProvider():
496
- # Drawer 컴포넌트들
497
- with antd.Drawer(open=False, title="Thinking", placement="left", width="750px") as code_drawer:
498
- code_output = legacy.Markdown()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
499
 
500
  with antd.Drawer(open=False, title="history", placement="left", width="900px") as history_drawer:
501
  history_output = legacy.Chatbot(show_label=False, flushing=False, height=960, elem_classes="history_chatbot")
 
258
 
259
  async def generation_code(self, query: Optional[str], _setting: Dict[str, str], _history: Optional[History]):
260
  if not query or query.strip() == '':
261
+ query = get_random_placeholder()
262
 
263
  if _history is None:
264
  _history = []
 
281
  openai_messages.append({"role": "user", "content": query})
282
 
283
  try:
284
+ # 로딩 시작
285
  yield [
286
+ "", # 빈 문자열로 변경 (코드 출력하지 않음)
287
  _history,
288
  None,
289
  gr.update(active_key="loading"),
 
295
  try:
296
  async for content in try_claude_api(system_message, claude_messages):
297
  yield [
298
+ "", # 빈 문자열로 변경 (코드 출력하지 않음)
299
  _history,
300
  None,
301
  gr.update(active_key="loading"),
302
  gr.update(open=True)
303
  ]
304
  await asyncio.sleep(0)
305
+ collected_content = content
306
+
307
  except Exception as claude_error:
308
  print(f"Falling back to OpenAI API due to Claude error: {str(claude_error)}")
309
 
310
  async for content in try_openai_api(openai_messages):
311
  yield [
312
+ "", # 빈 문자열로 변경 (코드 출력하지 않음)
313
  _history,
314
  None,
315
  gr.update(active_key="loading"),
316
  gr.update(open=True)
317
  ]
318
  await asyncio.sleep(0)
319
+ collected_content = content
320
 
321
  if collected_content:
322
  _history = messages_to_history([
 
326
  'content': collected_content
327
  }])
328
 
329
+ # 최종 결과만 표시
330
  yield [
331
  collected_content,
332
  _history,
333
  send_to_sandbox(remove_code_block(collected_content)),
334
  gr.update(active_key="render"),
335
+ gr.update(open=False)
336
  ]
337
 
338
  else:
 
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,
 
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">
499
+ <style>
500
+ .thinking-container {
501
+ text-align: center;
502
+ padding: 20px;
503
+ background: #f8f9fa;
504
+ border-radius: 15px;
505
+ font-family: 'Arial', sans-serif;
506
+ }
507
+
508
+ .progress-bar {
509
+ width: 100%;
510
+ height: 4px;
511
+ background: #e9ecef;
512
+ border-radius: 4px;
513
+ margin: 20px 0;
514
+ overflow: hidden;
515
+ }
516
+
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
+
524
+ .thinking-icon {
525
+ font-size: 48px;
526
+ margin: 20px 0;
527
+ animation: bounce 1s ease infinite;
528
+ }
529
+
530
+ .tip-box {
531
+ background: white;
532
+ padding: 20px;
533
+ border-radius: 10px;
534
+ box-shadow: 0 4px 12px rgba(0,0,0,0.1);
535
+ margin: 20px 0;
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;
549
+ }
550
+
551
+ .icon-grid {
552
+ display: grid;
553
+ grid-template-columns: repeat(4, 1fr);
554
+ gap: 15px;
555
+ margin: 20px 0;
556
+ }
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
+ }
564
+
565
+ @keyframes progress {
566
+ 0% { transform: translateX(-100%); }
567
+ 100% { transform: translateX(400%); }
568
+ }
569
+
570
+ @keyframes bounce {
571
+ 0%, 100% { transform: translateY(0); }
572
+ 50% { transform: translateY(-10px); }
573
+ }
574
+
575
+ @keyframes fade {
576
+ 0%, 100% { opacity: 1; }
577
+ 50% { opacity: 0.6; }
578
+ }
579
+
580
+ @keyframes pulse {
581
+ 0% { transform: scale(1); }
582
+ 50% { transform: scale(1.05); }
583
+ 100% { transform: scale(1); }
584
+ }
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
+
607
+ <script>
608
+ const tips = [
609
+ "MOUSE-I is creating responsive and interactive visualizations! 📊",
610
+ "We're applying modern design principles for the best user experience! 🎨",
611
+ "Your content will be optimized for all devices! 📱",
612
+ "Adding engaging animations to bring your data to life! ✨",
613
+ "Crafting a beautiful presentation just for you! 🎯",
614
+ "Implementing interactive elements for better engagement! 🎮",
615
+ "Optimizing colors and layout for visual appeal! 🎪",
616
+ "Creating smooth transitions and animations! 🌟"
617
+ ];
618
+
619
+ function updateTip() {
620
+ const tipElement = document.getElementById('tip-content');
621
+ if (tipElement) {
622
+ const randomTip = tips[Math.floor(Math.random() * tips.length)];
623
+ tipElement.innerHTML = randomTip;
624
+ tipElement.style.opacity = 0;
625
+ setTimeout(() => {
626
+ tipElement.style.transition = 'opacity 0.5s ease';
627
+ tipElement.style.opacity = 1;
628
+ }, 100);
629
+ }
630
+ }
631
+
632
+ updateTip();
633
+ setInterval(updateTip, 3000);
634
+ </script>
635
+ </div>
636
+ """)
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")