Update app.py
Browse files
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(
|
|
|
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 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|