seawolf2357 commited on
Commit
6753681
ยท
verified ยท
1 Parent(s): 1801079

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -20
app.py CHANGED
@@ -16,6 +16,7 @@ import modelscope_studio.components.legacy as legacy
16
  import modelscope_studio.components.antd as antd
17
 
18
  import html
 
19
 
20
  # SystemPrompt ๋ถ€๋ถ„์„ ์ง์ ‘ ์ •์˜
21
  SystemPrompt = """๋„ˆ์˜ ์ด๋ฆ„์€ 'MOUSE'์ด๋‹ค. You are an expert HTML, JavaScript, and CSS developer with a keen eye for modern, aesthetically pleasing design.
@@ -440,6 +441,13 @@ def load_session_history(selected_session):
440
  color: #666;
441
  margin-top: 10px;
442
  }
 
 
 
 
 
 
 
443
  </style>
444
  <div class="prompt-grid">
445
  """
@@ -454,7 +462,8 @@ def load_session_history(selected_session):
454
 
455
  cards_html += f"""
456
  <div class="prompt-card"
457
- onclick="executeHistoryItem(`{escaped_prompt}`, `{escaped_response}`)">
 
458
  <div>{short_prompt}</div>
459
  <div class="timestamp">{formatted_time}</div>
460
  </div>
@@ -464,27 +473,49 @@ def load_session_history(selected_session):
464
  </div>
465
  <script>
466
  function executeHistoryItem(prompt, response) {
467
- // ์ž…๋ ฅ ํ•„๋“œ ์—…๋ฐ์ดํŠธ
468
- document.querySelector('textarea').value = prompt;
469
-
470
- // ์ฝ”๋“œ ์‹คํ–‰
471
- const code = response.includes('```html') ?
472
- response.match(/```html\\n([\\s\\S]*?)\\n```/)[1] :
473
- response;
474
-
475
- const encodedHtml = btoa(code);
476
- const dataUri = `data:text/html;charset=utf-8;base64,${encodedHtml}`;
477
-
478
- // iframe ์—…๋ฐ์ดํŠธ
479
- document.querySelector('.html_content iframe').src = dataUri;
480
-
481
- // ์„ธ์…˜ ๋“œ๋กœ์–ด ๋‹ซ๊ธฐ
482
- document.querySelector('.session-drawer').style.display = 'none';
483
-
484
- // ๋ Œ๋” ํƒญ์œผ๋กœ ๋ณ€๊ฒฝ
485
- document.querySelector('[data-testid="tab-render"]').click();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
486
  }
487
  </script>
 
488
  """
489
 
490
  return gr.HTML(value=cards_html)
 
16
  import modelscope_studio.components.antd as antd
17
 
18
  import html
19
+ import urllib.parse
20
 
21
  # SystemPrompt ๋ถ€๋ถ„์„ ์ง์ ‘ ์ •์˜
22
  SystemPrompt = """๋„ˆ์˜ ์ด๋ฆ„์€ 'MOUSE'์ด๋‹ค. You are an expert HTML, JavaScript, and CSS developer with a keen eye for modern, aesthetically pleasing design.
 
441
  color: #666;
442
  margin-top: 10px;
443
  }
444
+ .code-display {
445
+ margin-top: 20px;
446
+ padding: 20px;
447
+ background: #f5f5f5;
448
+ border-radius: 8px;
449
+ display: none;
450
+ }
451
  </style>
452
  <div class="prompt-grid">
453
  """
 
462
 
463
  cards_html += f"""
464
  <div class="prompt-card"
465
+ onclick="executeHistoryItem(decodeURIComponent('{urllib.parse.quote(escaped_prompt)}'),
466
+ decodeURIComponent('{urllib.parse.quote(escaped_response)}'))">
467
  <div>{short_prompt}</div>
468
  <div class="timestamp">{formatted_time}</div>
469
  </div>
 
473
  </div>
474
  <script>
475
  function executeHistoryItem(prompt, response) {
476
+ try {
477
+ // ์ž…๋ ฅ ํ•„๋“œ ์—…๋ฐ์ดํŠธ
478
+ const textarea = document.querySelector('textarea');
479
+ if (textarea) {
480
+ textarea.value = prompt;
481
+
482
+ // ์ฝ”๋“œ ์‹คํ–‰
483
+ let code = response;
484
+ if (response.includes('```html')) {
485
+ const match = response.match(/```html\\n([\\s\\S]*?)\\n```/);
486
+ if (match) {
487
+ code = match[1];
488
+ }
489
+ }
490
+
491
+ // Base64 ์ธ์ฝ”๋”ฉ
492
+ const encodedHtml = btoa(unescape(encodeURIComponent(code)));
493
+ const dataUri = `data:text/html;charset=utf-8;base64,${encodedHtml}`;
494
+
495
+ // iframe ์—…๋ฐ์ดํŠธ
496
+ const iframe = document.querySelector('.html_content iframe');
497
+ if (iframe) {
498
+ iframe.src = dataUri;
499
+ }
500
+
501
+ // ์„ธ์…˜ ๋“œ๋กœ์–ด ๋‹ซ๊ธฐ
502
+ const drawer = document.querySelector('.session-drawer');
503
+ if (drawer) {
504
+ drawer.style.display = 'none';
505
+ }
506
+
507
+ // ๋ Œ๋” ํƒญ์œผ๋กœ ๋ณ€๊ฒฝ
508
+ const renderTab = document.querySelector('[data-testid="tab-render"]');
509
+ if (renderTab) {
510
+ renderTab.click();
511
+ }
512
+ }
513
+ } catch (error) {
514
+ console.error('Error executing history item:', error);
515
+ }
516
  }
517
  </script>
518
+ <div class="code-display"></div>
519
  """
520
 
521
  return gr.HTML(value=cards_html)