Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -437,75 +437,9 @@ def show_details_html(choice, previous_output, initial_state):
|
|
| 437 |
print(error_msg)
|
| 438 |
return format_hint_html(error_msg), gr.update(visible=True), initial_state
|
| 439 |
|
| 440 |
-
def get_pwa_html():
|
| 441 |
-
"""
|
| 442 |
-
創建一個不依賴外部模組的 PWA 設定
|
| 443 |
-
通過直接嵌入所需的代碼來避免模組載入問題
|
| 444 |
-
"""
|
| 445 |
-
return """
|
| 446 |
-
<!DOCTYPE html>
|
| 447 |
-
<meta charset="UTF-8">
|
| 448 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 449 |
-
<meta name="apple-mobile-web-app-capable" content="yes">
|
| 450 |
-
|
| 451 |
-
<!-- 直接在頁面中定義需要的功能,避免外部模組載入 -->
|
| 452 |
-
<script>
|
| 453 |
-
// 在 DOMContentLoaded 之前初始化,避免與其他腳本衝突
|
| 454 |
-
(function() {
|
| 455 |
-
// 定義我們自己的啟動函數,不依賴外部模組
|
| 456 |
-
function initializeApp() {
|
| 457 |
-
// PWA 相關設定
|
| 458 |
-
const config = {
|
| 459 |
-
name: 'PawMatch AI',
|
| 460 |
-
short_name: 'PawMatch',
|
| 461 |
-
display: 'standalone'
|
| 462 |
-
};
|
| 463 |
-
|
| 464 |
-
try {
|
| 465 |
-
// 使用內聯方式創建 manifest
|
| 466 |
-
const manifestData = new Blob(
|
| 467 |
-
[JSON.stringify(config)],
|
| 468 |
-
{type: 'application/json'}
|
| 469 |
-
);
|
| 470 |
-
|
| 471 |
-
// 在文檔準備好之後再添加 manifest
|
| 472 |
-
document.addEventListener('DOMContentLoaded', function() {
|
| 473 |
-
const link = document.createElement('link');
|
| 474 |
-
link.rel = 'manifest';
|
| 475 |
-
link.href = URL.createObjectURL(manifestData);
|
| 476 |
-
document.head.appendChild(link);
|
| 477 |
-
});
|
| 478 |
-
} catch(e) {
|
| 479 |
-
console.log('PWA initialization failed:', e);
|
| 480 |
-
}
|
| 481 |
-
}
|
| 482 |
-
|
| 483 |
-
// 立即執行初始化
|
| 484 |
-
initializeApp();
|
| 485 |
-
})();
|
| 486 |
-
</script>
|
| 487 |
-
|
| 488 |
-
<!-- 確保基本的移動端支援 -->
|
| 489 |
-
<style>
|
| 490 |
-
:root {
|
| 491 |
-
--safe-area-top: env(safe-area-inset-top);
|
| 492 |
-
--safe-area-bottom: env(safe-area-inset-bottom);
|
| 493 |
-
}
|
| 494 |
-
|
| 495 |
-
body {
|
| 496 |
-
margin: 0;
|
| 497 |
-
padding: var(--safe-area-top) 0 var(--safe-area-bottom) 0;
|
| 498 |
-
-webkit-overflow-scrolling: touch;
|
| 499 |
-
}
|
| 500 |
-
</style>
|
| 501 |
-
"""
|
| 502 |
-
|
| 503 |
-
|
| 504 |
def main():
|
| 505 |
with gr.Blocks(css=get_css_styles()) as iface:
|
| 506 |
|
| 507 |
-
gr.HTML(get_pwa_html())
|
| 508 |
-
|
| 509 |
# Header HTML
|
| 510 |
gr.HTML("""
|
| 511 |
<header style='text-align: center; padding: 20px; margin-bottom: 20px;'>
|
|
@@ -583,8 +517,6 @@ def main():
|
|
| 583 |
</div>
|
| 584 |
''')
|
| 585 |
|
| 586 |
-
gr.HTML("</body></html>")
|
| 587 |
-
|
| 588 |
return iface
|
| 589 |
|
| 590 |
if __name__ == "__main__":
|
|
|
|
| 437 |
print(error_msg)
|
| 438 |
return format_hint_html(error_msg), gr.update(visible=True), initial_state
|
| 439 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
def main():
|
| 441 |
with gr.Blocks(css=get_css_styles()) as iface:
|
| 442 |
|
|
|
|
|
|
|
| 443 |
# Header HTML
|
| 444 |
gr.HTML("""
|
| 445 |
<header style='text-align: center; padding: 20px; margin-bottom: 20px;'>
|
|
|
|
| 517 |
</div>
|
| 518 |
''')
|
| 519 |
|
|
|
|
|
|
|
| 520 |
return iface
|
| 521 |
|
| 522 |
if __name__ == "__main__":
|