Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files134 unmodified lines13513613713813914075 unmodified lines2162172182192202212222232242252262272282292302312322332342352361 unmodified line23823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030118 unmodified lines3203213223233243253262 unmodified lines329330331332333334134 unmodified linestmp.close()return tmp.name, "β Ready to download."CSS = """@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;700;800&family=DM+Mono:wght@400;500&display=swap');75 unmodified linesfont-weight: 700 !important; font-size: .85rem !important; letter-spacing: .04em !important;}.gradio-accordion svg { color: var(--accent2) !important; stroke: var(--accent2) !important; }.readback {background: var(--surface2);border: 1px solid var(--accent3);border-radius: var(--r);padding: 1rem;margin: .8rem 0;}.readback p {color: var(--muted);font-family: 'DM Mono', monospace;font-size: .75rem;margin: 0 0 .6rem;letter-spacing: .05em;text-transform: uppercase;}.foot {text-align: center; padding: 1.5rem; color: var(--muted);font-family: 'DM Mono', monospace; font-size: .68rem;1 unmodified line}"""READBACK_JS = """<div class="readback"><p>π Read Back</p><div style="display:flex;gap:.6rem;flex-wrap:wrap"><button onclick="readCycle(1)" style="background:#0f1629;color:#FFE500;border:1px solid #0066FF;border-radius:8px;padding:.4rem .9rem;font-family:Syne,sans-serif;font-weight:700;font-size:.78rem;cursor:pointer">βΆ Cycle 1</button><button onclick="readCycle(2)" style="background:#0f1629;color:#FFE500;border:1px solid #0066FF;border-radius:8px;padding:.4rem .9rem;font-family:Syne,sans-serif;font-weight:700;font-size:.78rem;cursor:pointer">βΆ Cycle 2</button><button onclick="readCycle(3)" style="background:#0f1629;color:#FFE500;border:1px solid #0066FF;border-radius:8px;padding:.4rem .9rem;font-family:Syne,sans-serif;font-weight:700;font-size:.78rem;cursor:pointer">βΆ Cycle 3</button><button onclick="readCycle(4)" style="background:#0f1629;color:#FFE500;border:1px solid #0066FF;border-radius:8px;padding:.4rem .9rem;font-family:Syne,sans-serif;font-weight:700;font-size:.78rem;cursor:pointer">βΆ Cycle 4</button><button onclick="readAll()" style="background:linear-gradient(135deg,#0066FF,#00CFFF);color:#030712;border:none;border-radius:8px;padding:.4rem .9rem;font-family:Syne,sans-serif;font-weight:800;font-size:.78rem;cursor:pointer">βΆ Read All</button><button onclick="stopReading()" style="background:#0f1629;color:#ff4444;border:1px solid #ff4444;border-radius:8px;padding:.4rem .9rem;font-family:Syne,sans-serif;font-weight:700;font-size:.78rem;cursor:pointer">β Stop</button></div></div><script>function getTextFromCycle(n) {const textareas = document.querySelectorAll('textarea');const cycleTextareas = Array.from(textareas).filter(t => t.value && t.value.trim().length > 0);if (cycleTextareas[n-1]) return cycleTextareas[n-1].value;return '';}function speak(text) {if (!text) { alert('No content to read β run the analysis first.'); return; }window.speechSynthesis.cancel();const chunks = text.match(/.{1,200}/g) || [];let i = 0;function nextChunk() {if (i >= chunks.length) return;const u = new SpeechSynthesisUtterance(chunks[i]);u.rate = 0.95;u.pitch = 1;u.lang = 'en-GB';u.onend = () => { i++; nextChunk(); };window.speechSynthesis.speak(u);}nextChunk();}function readCycle(n) {speak(getTextFromCycle(n));}function readAll() {const textareas = document.querySelectorAll('textarea');const all = Array.from(textareas).map(t => t.value).filter(v => v && v.trim().length > 0).join('\n\n --- \n\n');speak(all);}function stopReading() {window.speechSynthesis.cancel();}</script>"""with gr.Blocks(css=CSS, title="Metabolic Phoenix Framework") as demo:gr.HTML("""<div class="hdr">18 unmodified lineswith gr.Accordion("Cycle 4 β Full Case Output", open=False):out4 = gr.Textbox(label="", lines=12, elem_classes=["out"])gr.HTML(READBACK_JS)save_btn = gr.Button("πΎ Save & Download Analysis", variant="secondary")dl_file = gr.File(label="Download your analysis", visible=False)2 unmodified linesrun_btn.click(analyse, inputs=[pdf_input], outputs=[out1, out2, out3, out4])save_btn.click(save_analysis, inputs=[out1, out2, out3, out4], outputs=[dl_file, save_msg])gr.HTML("""<div class="foot">THE METABOLIC PHOENIX FRAMEWORK Β· Injectiv8 Β· Ms. Nala134 unmodified lines13513613713813914014114214314414514675 unmodified lines2222232242252262271 unmodified line22923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127218 unmodified lines2912922932942952962972982993003013023033042 unmodified lines307308309310311312313314315316317318319134 unmodified linestmp.close()return tmp.name, "β Ready to download."def read_cycle(text):return text or ""def stop_reading():return ""CSS = """@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;700;800&family=DM+Mono:wght@400;500&display=swap');75 unmodified linesfont-weight: 700 !important; font-size: .85rem !important; letter-spacing: .04em !important;}.gradio-accordion svg { color: var(--accent2) !important; stroke: var(--accent2) !important; }.foot {text-align: center; padding: 1.5rem; color: var(--muted);font-family: 'DM Mono', monospace; font-size: .68rem;1 unmodified line}"""JS = """function setupReadback() {window.mpfSpeak = function(text) {if (!text || !text.trim()) {alert('No content yet β run the analysis first.');return;}window.speechSynthesis.cancel();const chunks = text.match(/.{1,200}/g) || [];let i = 0;function next() {if (i >= chunks.length) return;const u = new SpeechSynthesisUtterance(chunks[i]);u.rate = 0.95;u.lang = 'en-GB';u.onend = () => { i++; next(); };window.speechSynthesis.speak(u);}next();};window.mpfStop = function() {window.speechSynthesis.cancel();};window.mpfReadAll = function() {const areas = document.querySelectorAll('textarea');const text = Array.from(areas).map(a => a.value).filter(v => v && v.trim()).join('\n\n---\n\n');window.mpfSpeak(text);};window.mpfReadCycle = function(n) {const areas = document.querySelectorAll('textarea');const filled = Array.from(areas).filter(a => a.value && a.value.trim());if (filled[n-1]) window.mpfSpeak(filled[n-1].value);else alert('Cycle ' + n + ' is empty β run the analysis first.');};}"""with gr.Blocks(css=CSS, js=JS, title="Metabolic Phoenix Framework") as demo:gr.HTML("""<div class="hdr">18 unmodified lineswith gr.Accordion("Cycle 4 β Full Case Output", open=False):out4 = gr.Textbox(label="", lines=12, elem_classes=["out"])# ββ Read Back Controls ββββββββββββββββββββββββββββββββββββββββwith gr.Row():rb1_btn = gr.Button("π Cycle 1", variant="secondary")rb2_btn = gr.Button("π Cycle 2", variant="secondary")rb3_btn = gr.Button("π Cycle 3", variant="secondary")rb4_btn = gr.Button("π Cycle 4", variant="secondary")rball_btn = gr.Button("π Read All", variant="primary")stop_btn = gr.Button("β Stop", variant="secondary")save_btn = gr.Button("πΎ Save & Download Analysis", variant="secondary")dl_file = gr.File(label="Download your analysis", visible=False)2 unmodified linesrun_btn.click(analyse, inputs=[pdf_input], outputs=[out1, out2, out3, out4])save_btn.click(save_analysis, inputs=[out1, out2, out3, out4], outputs=[dl_file, save_msg])rb1_btn.click(None, inputs=[], outputs=[], js="() => window.mpfReadCycle(1)")rb2_btn.click(None, inputs=[], outputs=[], js="() => window.mpfReadCycle(2)")rb3_btn.click(None, inputs=[], outputs=[], js="() => window.mpfReadCycle(3)")rb4_btn.click(None, inputs=[], outputs=[], js="() => window.mpfReadCycle(4)")rball_btn.click(None, inputs=[], outputs=[], js="() => window.mpfReadAll()")stop_btn.click(None, inputs=[], outputs=[], js="() => window.mpfStop()")gr.HTML("""<div class="foot">THE METABOLIC PHOENIX FRAMEWORK Β· Injectiv8 Β· Ms. Nala
app.py+56-71