Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse filesFiles changed (4)
43 unmodified lines44454647484950516 unmodified lines58596061626364656667686970717243 unmodified linesdef maybe_seed(conn) -> None:"""On the demo Space (WC_SEED_DEMO=1) only, populate an empty DB with a realistic60-day decline arc so the Trends/Report tabs are non-empty on first open. Real localusers (no env var) always start with a clean log."""if os.environ.get("WC_SEED_DEMO") != "1":returnif conn.execute("SELECT COUNT(*) FROM entries").fetchone()[0] > 0:6 unmodified linesprint(f"[seed] skipped: {e}")def build_app():conn = init_db(DB_PATH)maybe_seed(conn)backend = make_backend()with gr.Blocks(title="What Changed") as demo:gr.Markdown("# What Changed\n""*A private, local tracker to show the doctor what's been happening at home. ""Not medical advice.*")build_log_tab(conn, backend)build_trends_tab(conn)build_report_tab(conn, backend)43 unmodified lines444546474849506 unmodified lines57585960616263646566676869707172737475767778798081828384858687888990919243 unmodified linesdef maybe_seed(conn) -> None:"""On the demo Space (WC_SEED_DEMO=1) only, populate an empty DB with a realistic60-day decline arc so Trends/Report are non-empty on first open."""if os.environ.get("WC_SEED_DEMO") != "1":returnif conn.execute("SELECT COUNT(*) FROM entries").fetchone()[0] > 0:6 unmodified linesprint(f"[seed] skipped: {e}")# --- Off-Brand custom look: calm health palette, Inter, branded header, no Gradio footer ---THEME = gr.themes.Soft(primary_hue="teal", secondary_hue="cyan", neutral_hue="slate",font=[gr.themes.GoogleFont("Inter"), "system-ui", "sans-serif"],)CSS = """.gradio-container {max-width: 880px !important; margin: 0 auto !important;}#wc-header {background: linear-gradient(135deg,#0d9488,#0e7490); color:#fff;padding:22px 26px; border-radius:16px; margin-bottom:6px;}#wc-header h1 {margin:0; font-size:26px; font-weight:700; color:#fff;}#wc-header p {margin:6px 0 0; opacity:.92; font-size:14px; color:#fff;}#wc-header .wc-pill {display:inline-block; background:rgba(255,255,255,.18);padding:3px 11px; border-radius:999px; font-size:12px; margin-top:11px;}footer {display:none !important;}"""HEADER = ('<div id="wc-header"><h1>📋 What Changed</h1>'"<p>A private, on-device Parkinson's diary — describe the day, and a local fine-tuned 1B ""structures it into a doctor-ready summary.</p>"'<span class="wc-pill">Runs 100% locally · fine-tuned 1B · llama.cpp · not medical advice</span>'"</div>")def build_app():conn = init_db(DB_PATH)maybe_seed(conn)backend = make_backend()with gr.Blocks(title="What Changed", theme=THEME, css=CSS) as demo:gr.HTML(HEADER)build_log_tab(conn, backend)build_trends_tab(conn)build_report_tab(conn, backend)
1 unmodified line23456789101112131415161718192021222324252627282 unmodified lines31323334353637383940414243444546474849508 unmodified lines59606162631 unmodified lineimport datetimeimport gradio as grfrom whatchanged.models import Entry, DOMAINS, EVENTSfrom whatchanged.db import upsert_entry, get_entryfrom whatchanged.inference import extract_notefrom whatchanged.trends import DOMAIN_LABELS, EVENT_LABELSdef build_log_tab(conn, backend):with gr.Tab("Log Today"):gr.Markdown("### How was today? Tap what applies — takes ~15 seconds.")date = gr.Textbox(label="Date", value=str(datetime.date.today()))sliders = {}for d in DOMAINS:sliders[d] = gr.Slider(1, 5, step=1, value=3, label=DOMAIN_LABELS[d])counters = {}for ev in EVENTS:counters[ev] = gr.Number(value=0, precision=0, label=EVENT_LABELS[ev],minimum=0)note = gr.Textbox(label="Optional note", lines=2,placeholder="e.g. more confused this evening, skipped lunch")extract_btn = gr.Button("Auto-fill from note (local AI)")save_btn = gr.Button("Save today", variant="primary")status = gr.Markdown()def do_extract(note_text, *slider_vals):data = extract_note(note_text, backend)2 unmodified linesif d in data:new[i] = data[d]counter_updates = [data.get(ev, gr.update()) for ev in EVENTS]return (*new, *counter_updates,f"Filled {len(data)} field(s) from the note. Please review.")extract_btn.click(do_extract,inputs=[note] + [sliders[d] for d in DOMAINS],outputs=[sliders[d] for d in DOMAINS] + [counters[ev] for ev in EVENTS]+ [status],)def do_save(date_val, note_text, *vals):n = len(DOMAINS)domain_vals = vals[:n]event_vals = vals[n:]def _to_int(v):return int(v) if v not in (None, "") else 08 unmodified linesdo_save,inputs=[date, note] + [sliders[d] for d in DOMAINS]+ [counters[ev] for ev in EVENTS],outputs=[status],)1 unmodified line234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253542 unmodified lines5758596061626364656667686970717273747576777879808 unmodified lines89909192931 unmodified lineimport datetimeimport gradio as grfrom whatchanged.models import Entry, DOMAINS, EVENTSfrom whatchanged.db import upsert_entryfrom whatchanged.inference import extract_notefrom whatchanged.trends import DOMAIN_LABELS, EVENT_LABELS# Plain-language anchors so a caregiver knows what each 1-5 rating means (5 = best). These# rate the *quality* of the day, not a number of hours/etc.ANCHORS = {"mobility": "1 = could barely move · 5 = moved freely & steadily","tremor": "1 = severe tremor · 5 = almost no tremor","stiffness": "1 = very stiff & rigid · 5 = loose, not stiff","mood": "1 = very low · 5 = bright & cheerful","sleep": "1 = barely slept · 5 = slept very well","alertness": "1 = very confused & foggy · 5 = sharp & clear",}def build_log_tab(conn, backend):with gr.Tab("📝 Log Today"):gr.Markdown("### Just describe the day — the on-device AI fills the form, you review.\n""Type a sentence or two about how your parent did today, then tap **Auto-fill**.")date = gr.Textbox(label="Date", value=str(datetime.date.today()))note = gr.Textbox(label="Today's note", lines=3, autofocus=True,placeholder='e.g. "Rough day — Dad froze in the doorway twice, his meds wore off ''before lunch, and he barely slept."')extract_btn = gr.Button("✨ Auto-fill from note (local AI)",variant="primary", size="lg")extract_status = gr.Markdown()gr.Markdown("#### Review & adjust")sliders = {}for d in DOMAINS:sliders[d] = gr.Slider(1, 5, step=1, value=3, label=DOMAIN_LABELS[d],info=ANCHORS[d])gr.Markdown("**Events today** — how many times each happened")counters = {}with gr.Row():for ev in EVENTS[:3]:counters[ev] = gr.Number(value=0, precision=0, label=EVENT_LABELS[ev], minimum=0)with gr.Row():for ev in EVENTS[3:]:counters[ev] = gr.Number(value=0, precision=0, label=EVENT_LABELS[ev], minimum=0)save_btn = gr.Button("Save today", variant="primary")save_status = gr.Markdown()def do_extract(note_text, *slider_vals):data = extract_note(note_text, backend)2 unmodified linesif d in data:new[i] = data[d]counter_updates = [data.get(ev, gr.update()) for ev in EVENTS]if backend is None:msg = "⚠️ The local model isn't loaded right now — enter values manually below."elif not note_text.strip():msg = "Write a note above first, then tap Auto-fill."else:msg = f"✓ Filled **{len(data)}** field(s) from your note — please review below."return (*new, *counter_updates, msg)extract_btn.click(do_extract,inputs=[note] + [sliders[d] for d in DOMAINS],outputs=[sliders[d] for d in DOMAINS] + [counters[ev] for ev in EVENTS]+ [extract_status],)def do_save(date_val, note_text, *vals):n = len(DOMAINS)domain_vals, event_vals = vals[:n], vals[n:]def _to_int(v):return int(v) if v not in (None, "") else 08 unmodified linesdo_save,inputs=[date, note] + [sliders[d] for d in DOMAINS]+ [counters[ev] for ev in EVENTS],outputs=[save_status],)
5 unmodified lines67891011125 unmodified linesdef build_report_tab(conn, backend):with gr.Tab("Doctor Report"):gr.Markdown("### Generate a one-page summary to share with the doctor.")with gr.Row():start = gr.Textbox(5 unmodified lines67891011125 unmodified linesdef build_report_tab(conn, backend):with gr.Tab("🩺 Doctor Report"):gr.Markdown("### Generate a one-page summary to share with the doctor.")with gr.Row():start = gr.Textbox(
6 unmodified lines789101112136 unmodified linesdef build_trends_tab(conn):with gr.Tab("Trends"):window = gr.Radio([7, 30, 90], value=30, label="Window (days)")refresh = gr.Button("Refresh", variant="primary")plot = gr.Plot()6 unmodified lines789101112136 unmodified linesdef build_trends_tab(conn):with gr.Tab("📈 Trends"):window = gr.Radio([7, 30, 90], value=30, label="Window (days)")refresh = gr.Button("Refresh", variant="primary")plot = gr.Plot()
app.py+27-7
whatchanged/ui/log_tab.py+47-17
whatchanged/ui/report_tab.py+1-1
whatchanged/ui/trends_tab.py+1-1