Spaces:
Sleeping
Sleeping
Portfolio User
commited on
Commit
·
a01c7d7
1
Parent(s):
6815cfe
feat: add PWA support and medical icons
Browse files- app.py +44 -2
- pwa_assets/icon-192x192.png +0 -0
- pwa_assets/icon-512x512.png +0 -0
app.py
CHANGED
|
@@ -2,6 +2,9 @@ import gradio as gr
|
|
| 2 |
from agent.core import MedicalAgent
|
| 3 |
from data.loader import fetch_med_dialog_sample, format_dialogue_context
|
| 4 |
import os
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Globals
|
| 7 |
agent = None
|
|
@@ -36,7 +39,23 @@ def medical_chat_interface(message, history):
|
|
| 36 |
# Custom Theme
|
| 37 |
theme = gr.themes.Soft(primary_hue="blue")
|
| 38 |
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
gr.Markdown(
|
| 41 |
"""
|
| 42 |
# 🏥 Medical AI Assistant
|
|
@@ -51,5 +70,28 @@ with gr.Blocks(theme=theme, title="Medical AI Agent") as demo:
|
|
| 51 |
examples=["What are common symptoms of iron deficiency?", "Explain hypertension in simple terms."]
|
| 52 |
)
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
if __name__ == "__main__":
|
| 55 |
-
|
|
|
|
|
|
| 2 |
from agent.core import MedicalAgent
|
| 3 |
from data.loader import fetch_med_dialog_sample, format_dialogue_context
|
| 4 |
import os
|
| 5 |
+
from fastapi import FastAPI
|
| 6 |
+
from fastapi.responses import FileResponse
|
| 7 |
+
import uvicorn
|
| 8 |
|
| 9 |
# Globals
|
| 10 |
agent = None
|
|
|
|
| 39 |
# Custom Theme
|
| 40 |
theme = gr.themes.Soft(primary_hue="blue")
|
| 41 |
|
| 42 |
+
# PWA Head Tags
|
| 43 |
+
head = """
|
| 44 |
+
<link rel="manifest" href="/manifest.json">
|
| 45 |
+
<meta name="theme-color" content="#2563eb">
|
| 46 |
+
<link rel="apple-touch-icon" href="/icon-192x192.png">
|
| 47 |
+
<script>
|
| 48 |
+
if ('serviceWorker' in navigator) {
|
| 49 |
+
window.addEventListener('load', () => {
|
| 50 |
+
navigator.serviceWorker.register('/sw.js')
|
| 51 |
+
.then(reg => console.log('Service Worker registered', reg))
|
| 52 |
+
.catch(err => console.error('Service Worker registration failed', err));
|
| 53 |
+
});
|
| 54 |
+
}
|
| 55 |
+
</script>
|
| 56 |
+
"""
|
| 57 |
+
|
| 58 |
+
with gr.Blocks(theme=theme, title="Medical AI Agent", head=head) as demo:
|
| 59 |
gr.Markdown(
|
| 60 |
"""
|
| 61 |
# 🏥 Medical AI Assistant
|
|
|
|
| 70 |
examples=["What are common symptoms of iron deficiency?", "Explain hypertension in simple terms."]
|
| 71 |
)
|
| 72 |
|
| 73 |
+
# FastAPI app for serving PWA assets
|
| 74 |
+
app = FastAPI()
|
| 75 |
+
|
| 76 |
+
@app.get("/manifest.json")
|
| 77 |
+
async def manifest():
|
| 78 |
+
return FileResponse("pwa_assets/manifest.json")
|
| 79 |
+
|
| 80 |
+
@app.get("/sw.js")
|
| 81 |
+
async def sw():
|
| 82 |
+
return FileResponse("pwa_assets/sw.js", media_type="application/javascript")
|
| 83 |
+
|
| 84 |
+
@app.get("/icon-192x192.png")
|
| 85 |
+
async def icon192():
|
| 86 |
+
return FileResponse("pwa_assets/icon-192x192.png")
|
| 87 |
+
|
| 88 |
+
@app.get("/icon-512x512.png")
|
| 89 |
+
async def icon512():
|
| 90 |
+
return FileResponse("pwa_assets/icon-512x512.png")
|
| 91 |
+
|
| 92 |
+
# Mount Gradio app
|
| 93 |
+
app = gr.mount_gradio_app(app, demo, path="/")
|
| 94 |
+
|
| 95 |
if __name__ == "__main__":
|
| 96 |
+
port = int(os.environ.get("PORT", 7860))
|
| 97 |
+
uvicorn.run(app, host="0.0.0.0", port=port)
|
pwa_assets/icon-192x192.png
ADDED
|
|
pwa_assets/icon-512x512.png
ADDED
|
|