Spaces:
Running
Running
Portfolio User
commited on
Commit
·
6815cfe
1
Parent(s):
1f1b45b
Update app with full PWA functionality
Browse files- android_app/main.py +32 -0
- pwa_assets/sw.js +21 -0
android_app/main.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import flet as ft
|
| 2 |
+
|
| 3 |
+
def main(page: ft.Page):
|
| 4 |
+
page.title = "Medi-Agent Mobile"
|
| 5 |
+
page.theme_mode = ft.ThemeMode.LIGHT
|
| 6 |
+
page.window_width = 400
|
| 7 |
+
page.window_height = 800
|
| 8 |
+
page.padding = 0
|
| 9 |
+
|
| 10 |
+
# Your Hugging Face Space URL
|
| 11 |
+
# We use the direct "embed" version for a cleaner mobile look
|
| 12 |
+
HF_URL = "https://rafi11223-mediagent.hf.space"
|
| 13 |
+
|
| 14 |
+
# Native Mobile UI Components
|
| 15 |
+
def on_window_event(e):
|
| 16 |
+
if e.data == "close":
|
| 17 |
+
page.window_destroy()
|
| 18 |
+
|
| 19 |
+
# The WebView component that holds the AI Agent
|
| 20 |
+
webview = ft.WebView(
|
| 21 |
+
HF_URL,
|
| 22 |
+
expand=True,
|
| 23 |
+
on_page_started=lambda _: print("Loading Medi-Agent..."),
|
| 24 |
+
on_page_ended=lambda _: print("Medi-Agent Ready!"),
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
page.add(webview)
|
| 28 |
+
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
# To run locally for testing: flet run android_app/main.py
|
| 31 |
+
# To build APK: flet build apk
|
| 32 |
+
ft.app(target=main)
|
pwa_assets/sw.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const CACHE_NAME = 'medi-agent-v1';
|
| 2 |
+
const ASSETS = [
|
| 3 |
+
'/',
|
| 4 |
+
'/manifest.json'
|
| 5 |
+
];
|
| 6 |
+
|
| 7 |
+
self.addEventListener('install', (event) => {
|
| 8 |
+
event.waitUntil(
|
| 9 |
+
caches.open(CACHE_NAME).then((cache) => {
|
| 10 |
+
return cache.addAll(ASSETS);
|
| 11 |
+
})
|
| 12 |
+
);
|
| 13 |
+
});
|
| 14 |
+
|
| 15 |
+
self.addEventListener('fetch', (event) => {
|
| 16 |
+
event.respondWith(
|
| 17 |
+
caches.match(event.request).then((response) => {
|
| 18 |
+
return response || fetch(event.request);
|
| 19 |
+
})
|
| 20 |
+
);
|
| 21 |
+
});
|