Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -443,32 +443,32 @@ def main():
|
|
443 |
gr.HTML("""
|
444 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
445 |
""")
|
446 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
447 |
gr.HTML("""
|
448 |
<script>
|
449 |
-
//
|
450 |
-
window.
|
451 |
-
// 確保不會干擾到 Gradio 的客戶端程式碼
|
452 |
if ('serviceWorker' in navigator) {
|
453 |
-
navigator.serviceWorker.register('service-worker.js')
|
454 |
.then(function(registration) {
|
455 |
-
console.log('
|
456 |
-
})
|
457 |
-
.catch(function(error) {
|
458 |
-
console.error('註冊失敗:', error);
|
459 |
});
|
460 |
}
|
461 |
-
}
|
462 |
</script>
|
463 |
""")
|
464 |
|
465 |
-
gr.HTML("""
|
466 |
-
<link rel="manifest" href="manifest.json">
|
467 |
-
<link rel="apple-touch-icon" href="assets/icon-192.png">
|
468 |
-
<meta name="apple-mobile-web-app-capable" content="yes">
|
469 |
-
<meta name="apple-mobile-web-app-title" content="PawMatch AI">
|
470 |
-
""")
|
471 |
-
|
472 |
# Header HTML
|
473 |
gr.HTML("""
|
474 |
<header style='text-align: center; padding: 20px; margin-bottom: 20px;'>
|
|
|
443 |
gr.HTML("""
|
444 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
445 |
""")
|
446 |
+
|
447 |
+
# 2. 添加一個初始化檢查
|
448 |
+
gr.HTML("""
|
449 |
+
<script>
|
450 |
+
// 首先檢查 Gradio 是否正確載入
|
451 |
+
window.addEventListener('DOMContentLoaded', function() {
|
452 |
+
console.log('Gradio 初始化開始');
|
453 |
+
});
|
454 |
+
</script>
|
455 |
+
""")
|
456 |
+
|
457 |
+
# 3. 只有在確認 Gradio 正常後,才添加 PWA 功能
|
458 |
gr.HTML("""
|
459 |
<script>
|
460 |
+
// 使用一個安全的方式來添加 PWA 功能
|
461 |
+
window.gradioApp = function() {
|
|
|
462 |
if ('serviceWorker' in navigator) {
|
463 |
+
navigator.serviceWorker.register('./service-worker.js')
|
464 |
.then(function(registration) {
|
465 |
+
console.log('Service Worker 註冊成功');
|
|
|
|
|
|
|
466 |
});
|
467 |
}
|
468 |
+
};
|
469 |
</script>
|
470 |
""")
|
471 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
472 |
# Header HTML
|
473 |
gr.HTML("""
|
474 |
<header style='text-align: center; padding: 20px; margin-bottom: 20px;'>
|