Basementup commited on
Commit
1c79afb
·
verified ·
1 Parent(s): f3b42fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -119
app.py CHANGED
@@ -53,14 +53,10 @@ def call_llama(prompt, max_tokens=2000):
53
  def analyse(pdf_file):
54
  if not pdf_file:
55
  return "⚠️ Please upload a PDF.", "", "", ""
56
-
57
  doc = extract_pdf_text(pdf_file)
58
-
59
  if doc.startswith("["):
60
  return doc, "", "", ""
61
-
62
  base = f"DOCUMENT:\n\n{doc}\n\n{'='*60}\n\n"
63
-
64
  r1 = call_llama(base +
65
  "You are Introbot — part of the Metabolic Phoenix Framework by Dwayne Anthony Brian Galloway.\n\n"
66
  "From this document extract:\n"
@@ -72,7 +68,6 @@ def analyse(pdf_file):
72
  "- Any statutory duties that were triggered\n\n"
73
  "Format as a clean numbered FACT LEDGER."
74
  )
75
-
76
  r2 = call_llama(base +
77
  "You are RHB 2.0 + CPF — part of the Metabolic Phoenix Framework by Dwayne Anthony Brian Galloway.\n\n"
78
  "From this document:\n"
@@ -84,7 +79,6 @@ def analyse(pdf_file):
84
  "- State what remedy is appropriate for each breach\n\n"
85
  "Be forensic. Cite statute sections."
86
  )
87
-
88
  r3 = call_llama(base +
89
  "You are Phoenix Badger — part of the Metabolic Phoenix Framework by Dwayne Anthony Brian Galloway.\n\n"
90
  "Run all four Ouroboros rings on this document:\n\n"
@@ -94,7 +88,6 @@ def analyse(pdf_file):
94
  "RING D — DRIFT CORRECTION: What internal contradictions or inconsistencies exist within the document itself?\n\n"
95
  "End with ESCALATION MAP: which bodies should receive this in priority order and why."
96
  )
97
-
98
  r4 = call_llama(
99
  f"You are Layoutbot — part of the Metabolic Phoenix Framework by Dwayne Anthony Brian Galloway.\n\n"
100
  f"DOCUMENT EXTRACT:\n{doc[:3000]}\n\n"
@@ -110,16 +103,16 @@ def analyse(pdf_file):
110
  "ESCALATION MAP — which body gets what and when\n\n"
111
  "Ms. Nala | Injectiv8 | Dwayne Anthony Brian Galloway"
112
  )
113
-
114
  return r1, r2, r3, r4
115
 
116
  def make_audio(text):
117
  if not text or not text.strip():
118
  return None
119
  try:
120
- tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
121
  tts = gTTS(text=text[:3000], lang="en", tld="co.uk", slow=False)
122
  tts.save(tmp.name)
 
123
  return tmp.name
124
  except Exception as e:
125
  return None
@@ -146,11 +139,9 @@ def save_analysis(r1, r2, r3, r4):
146
  f"{'='*60}\n\nCYCLE 4 — FULL CASE OUTPUT\n\n{r4}"
147
  )
148
  tmp = tempfile.NamedTemporaryFile(
149
- delete=False,
150
- suffix=".txt",
151
  prefix=f"MPF_Analysis_{time.strftime('%Y%m%d_%H%M')}_",
152
- mode="w",
153
- encoding="utf-8"
154
  )
155
  tmp.write(content)
156
  tmp.close()
@@ -158,90 +149,47 @@ def save_analysis(r1, r2, r3, r4):
158
 
159
  CSS = """
160
  @import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;700;800&family=DM+Mono:wght@400;500&display=swap');
161
-
162
  :root {
163
- --bg: #030712;
164
- --surface: #0a0f1e;
165
- --surface2: #0f1629;
166
- --border: #1a2544;
167
- --accent: #00CFFF;
168
- --accent2: #FFE500;
169
- --accent3: #0066FF;
170
- --text: #E8F4FF;
171
- --muted: #4A6080;
172
- --r: 8px;
173
- }
174
-
175
- body, .gradio-container {
176
- background: var(--bg) !important;
177
- font-family: 'Syne', sans-serif !important;
178
- color: var(--text) !important;
179
- }
180
- .hdr {
181
- text-align: center;
182
- padding: 2.4rem 1rem 1.6rem;
183
- border-bottom: 1px solid var(--border);
184
- background:
185
- radial-gradient(ellipse at 30% 50%, rgba(0,102,255,0.12) 0%, transparent 60%),
186
- radial-gradient(ellipse at 70% 50%, rgba(0,207,255,0.08) 0%, transparent 60%);
187
- }
188
- .hdr h1 {
189
- font-size: 2.2rem; font-weight: 800; letter-spacing: -0.04em;
190
- background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
191
- -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin: 0 0 0.3rem;
192
- }
193
- .hdr .sub { color: var(--muted); font-family:'DM Mono',monospace; font-size:.75rem; letter-spacing:.06em; }
194
- .hdr .own { color: var(--accent2); font-family:'DM Mono',monospace; font-size:.68rem; margin-top:.3rem; letter-spacing:.1em; text-transform:uppercase; }
195
- input[type=text], textarea {
196
- background: var(--surface) !important; border: 1px solid var(--border) !important;
197
- border-radius: var(--r) !important; color: var(--text) !important;
198
- font-family: 'DM Mono', monospace !important; font-size: .86rem !important;
199
- padding: .6rem .85rem !important; transition: border-color .18s !important;
200
- }
201
- input[type=text]:focus, textarea:focus {
202
- border-color: var(--accent) !important; outline: none !important;
203
- box-shadow: 0 0 0 3px rgba(0,207,255,.12) !important;
204
- }
205
- label > span:first-child {
206
- color: var(--muted) !important; font-family: 'DM Mono', monospace !important;
207
- font-size: .7rem !important; letter-spacing: .08em !important; text-transform: uppercase !important;
208
- }
209
- button.primary {
210
- background: linear-gradient(135deg, var(--accent3), var(--accent)) !important;
211
- color: #030712 !important; border: none !important; border-radius: var(--r) !important;
212
- font-family: 'Syne', sans-serif !important; font-weight: 800 !important;
213
- font-size: .92rem !important; padding: .75rem 2.8rem !important;
214
- cursor: pointer !important; transition: opacity .15s, transform .15s !important;
215
- }
216
- button.primary:hover { opacity: .88 !important; transform: translateY(-1px) !important; }
217
- button.secondary {
218
- background: var(--surface2) !important; color: var(--accent2) !important;
219
- border: 1px solid var(--accent3) !important; border-radius: var(--r) !important;
220
- font-family: 'Syne', sans-serif !important; font-weight: 700 !important;
221
- font-size: .8rem !important; padding: .5rem 1.2rem !important; cursor: pointer !important;
222
- }
223
- button.secondary:hover { background: var(--accent3) !important; color: #030712 !important; }
224
- .out textarea {
225
- background: #020510 !important; border: 1px solid var(--border) !important;
226
- border-left: 3px solid var(--accent) !important;
227
- border-radius: 0 var(--r) var(--r) 0 !important;
228
- font-family: 'DM Mono', monospace !important; font-size: .84rem !important;
229
- line-height: 1.7 !important; color: var(--text) !important;
230
- }
231
- .gradio-accordion {
232
- background: var(--surface2) !important; border: 1px solid var(--accent2) !important;
233
- border-radius: var(--r) !important; margin-bottom: .6rem !important;
234
- }
235
- .gradio-accordion .label-wrap span {
236
- color: var(--accent2) !important; font-family: 'Syne', sans-serif !important;
237
- font-weight: 700 !important; font-size: .85rem !important; letter-spacing: .04em !important;
238
- }
239
- .gradio-accordion svg { color: var(--accent2) !important; stroke: var(--accent2) !important; }
240
- .foot {
241
- text-align: center; padding: 1.5rem; color: var(--muted);
242
- font-family: 'DM Mono', monospace; font-size: .68rem;
243
- border-top: 1px solid var(--border); margin-top: 2rem; letter-spacing: .05em;
244
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  """
246
 
247
  with gr.Blocks(css=CSS, title="Metabolic Phoenix Framework") as demo:
@@ -258,45 +206,38 @@ with gr.Blocks(css=CSS, title="Metabolic Phoenix Framework") as demo:
258
  run_btn = gr.Button("⚡ Analyse", variant="primary")
259
 
260
  with gr.Accordion("Cycle 1 — Fact Ledger", open=True):
261
- out1 = gr.Textbox(label="", lines=12, elem_classes=["out"])
262
  rb1_btn = gr.Button("🔊 Read Cycle 1", variant="secondary")
263
- audio1 = gr.Audio(label="", autoplay=True, visible=False)
264
 
265
  with gr.Accordion("Cycle 2 — Compliance Analysis", open=False):
266
- out2 = gr.Textbox(label="", lines=12, elem_classes=["out"])
267
  rb2_btn = gr.Button("🔊 Read Cycle 2", variant="secondary")
268
- audio2 = gr.Audio(label="", autoplay=True, visible=False)
269
 
270
  with gr.Accordion("Cycle 3 — Ouroboros Loops", open=False):
271
- out3 = gr.Textbox(label="", lines=12, elem_classes=["out"])
272
  rb3_btn = gr.Button("🔊 Read Cycle 3", variant="secondary")
273
- audio3 = gr.Audio(label="", autoplay=True, visible=False)
274
 
275
  with gr.Accordion("Cycle 4 — Full Case Output", open=False):
276
- out4 = gr.Textbox(label="", lines=12, elem_classes=["out"])
277
  rb4_btn = gr.Button("🔊 Read Cycle 4", variant="secondary")
278
- audio4 = gr.Audio(label="", autoplay=True, visible=False)
279
 
280
  rball_btn = gr.Button("🔊 Read Full Analysis", variant="primary")
281
- audio_all = gr.Audio(label="Full Analysis Audio", autoplay=True, visible=False)
282
 
283
- save_btn = gr.Button("💾 Save & Download Analysis", variant="secondary")
284
- dl_file = gr.File(label="Download your analysis", visible=False)
285
- save_msg = gr.Markdown("")
286
 
287
  run_btn.click(analyse, inputs=[pdf_input], outputs=[out1, out2, out3, out4])
288
-
289
- rb1_btn.click(read_cycle1, inputs=[out1], outputs=[audio1]).then(
290
- lambda: gr.update(visible=True), outputs=[audio1])
291
- rb2_btn.click(read_cycle2, inputs=[out2], outputs=[audio2]).then(
292
- lambda: gr.update(visible=True), outputs=[audio2])
293
- rb3_btn.click(read_cycle3, inputs=[out3], outputs=[audio3]).then(
294
- lambda: gr.update(visible=True), outputs=[audio3])
295
- rb4_btn.click(read_cycle4, inputs=[out4], outputs=[audio4]).then(
296
- lambda: gr.update(visible=True), outputs=[audio4])
297
- rball_btn.click(read_all, inputs=[out1, out2, out3, out4], outputs=[audio_all]).then(
298
- lambda: gr.update(visible=True), outputs=[audio_all])
299
-
300
  save_btn.click(save_analysis, inputs=[out1, out2, out3, out4], outputs=[dl_file, save_msg])
301
 
302
  gr.HTML("""
 
53
  def analyse(pdf_file):
54
  if not pdf_file:
55
  return "⚠️ Please upload a PDF.", "", "", ""
 
56
  doc = extract_pdf_text(pdf_file)
 
57
  if doc.startswith("["):
58
  return doc, "", "", ""
 
59
  base = f"DOCUMENT:\n\n{doc}\n\n{'='*60}\n\n"
 
60
  r1 = call_llama(base +
61
  "You are Introbot — part of the Metabolic Phoenix Framework by Dwayne Anthony Brian Galloway.\n\n"
62
  "From this document extract:\n"
 
68
  "- Any statutory duties that were triggered\n\n"
69
  "Format as a clean numbered FACT LEDGER."
70
  )
 
71
  r2 = call_llama(base +
72
  "You are RHB 2.0 + CPF — part of the Metabolic Phoenix Framework by Dwayne Anthony Brian Galloway.\n\n"
73
  "From this document:\n"
 
79
  "- State what remedy is appropriate for each breach\n\n"
80
  "Be forensic. Cite statute sections."
81
  )
 
82
  r3 = call_llama(base +
83
  "You are Phoenix Badger — part of the Metabolic Phoenix Framework by Dwayne Anthony Brian Galloway.\n\n"
84
  "Run all four Ouroboros rings on this document:\n\n"
 
88
  "RING D — DRIFT CORRECTION: What internal contradictions or inconsistencies exist within the document itself?\n\n"
89
  "End with ESCALATION MAP: which bodies should receive this in priority order and why."
90
  )
 
91
  r4 = call_llama(
92
  f"You are Layoutbot — part of the Metabolic Phoenix Framework by Dwayne Anthony Brian Galloway.\n\n"
93
  f"DOCUMENT EXTRACT:\n{doc[:3000]}\n\n"
 
103
  "ESCALATION MAP — which body gets what and when\n\n"
104
  "Ms. Nala | Injectiv8 | Dwayne Anthony Brian Galloway"
105
  )
 
106
  return r1, r2, r3, r4
107
 
108
  def make_audio(text):
109
  if not text or not text.strip():
110
  return None
111
  try:
112
+ tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3", dir="/tmp")
113
  tts = gTTS(text=text[:3000], lang="en", tld="co.uk", slow=False)
114
  tts.save(tmp.name)
115
+ tmp.close()
116
  return tmp.name
117
  except Exception as e:
118
  return None
 
139
  f"{'='*60}\n\nCYCLE 4 — FULL CASE OUTPUT\n\n{r4}"
140
  )
141
  tmp = tempfile.NamedTemporaryFile(
142
+ delete=False, suffix=".txt",
 
143
  prefix=f"MPF_Analysis_{time.strftime('%Y%m%d_%H%M')}_",
144
+ mode="w", encoding="utf-8"
 
145
  )
146
  tmp.write(content)
147
  tmp.close()
 
149
 
150
  CSS = """
151
  @import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;700;800&family=DM+Mono:wght@400;500&display=swap');
 
152
  :root {
153
+ --bg: #030712; --surface: #0a0f1e; --surface2: #0f1629;
154
+ --border: #1a2544; --accent: #00CFFF; --accent2: #FFE500;
155
+ --accent3: #0066FF; --text: #E8F4FF; --muted: #4A6080; --r: 8px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  }
157
+ body, .gradio-container { background:var(--bg)!important; font-family:'Syne',sans-serif!important; color:var(--text)!important; }
158
+ .hdr { text-align:center; padding:2.4rem 1rem 1.6rem; border-bottom:1px solid var(--border);
159
+ background: radial-gradient(ellipse at 30% 50%, rgba(0,102,255,0.12) 0%, transparent 60%),
160
+ radial-gradient(ellipse at 70% 50%, rgba(0,207,255,0.08) 0%, transparent 60%); }
161
+ .hdr h1 { font-size:2.2rem; font-weight:800; letter-spacing:-0.04em;
162
+ background:linear-gradient(135deg,var(--accent) 0%,var(--accent2) 100%);
163
+ -webkit-background-clip:text; -webkit-text-fill-color:transparent; margin:0 0 0.3rem; }
164
+ .hdr .sub { color:var(--muted); font-family:'DM Mono',monospace; font-size:.75rem; letter-spacing:.06em; }
165
+ .hdr .own { color:var(--accent2); font-family:'DM Mono',monospace; font-size:.68rem; margin-top:.3rem; letter-spacing:.1em; text-transform:uppercase; }
166
+ input[type=text], textarea { background:var(--surface)!important; border:1px solid var(--border)!important;
167
+ border-radius:var(--r)!important; color:var(--text)!important; font-family:'DM Mono',monospace!important;
168
+ font-size:.86rem!important; padding:.6rem .85rem!important; transition:border-color .18s!important; }
169
+ input[type=text]:focus, textarea:focus { border-color:var(--accent)!important; outline:none!important;
170
+ box-shadow:0 0 0 3px rgba(0,207,255,.12)!important; }
171
+ label > span:first-child { color:var(--muted)!important; font-family:'DM Mono',monospace!important;
172
+ font-size:.7rem!important; letter-spacing:.08em!important; text-transform:uppercase!important; }
173
+ button.primary { background:linear-gradient(135deg,var(--accent3),var(--accent))!important;
174
+ color:#030712!important; border:none!important; border-radius:var(--r)!important;
175
+ font-family:'Syne',sans-serif!important; font-weight:800!important; font-size:.92rem!important;
176
+ padding:.75rem 2.8rem!important; cursor:pointer!important; transition:opacity .15s,transform .15s!important; }
177
+ button.primary:hover { opacity:.88!important; transform:translateY(-1px)!important; }
178
+ button.secondary { background:var(--surface2)!important; color:var(--accent2)!important;
179
+ border:1px solid var(--accent3)!important; border-radius:var(--r)!important;
180
+ font-family:'Syne',sans-serif!important; font-weight:700!important; font-size:.8rem!important;
181
+ padding:.5rem 1.2rem!important; cursor:pointer!important; }
182
+ button.secondary:hover { background:var(--accent3)!important; color:#030712!important; }
183
+ .out textarea { background:#020510!important; border:1px solid var(--border)!important;
184
+ border-left:3px solid var(--accent)!important; border-radius:0 var(--r) var(--r) 0!important;
185
+ font-family:'DM Mono',monospace!important; font-size:.84rem!important; line-height:1.7!important; color:var(--text)!important; }
186
+ .gradio-accordion { background:var(--surface2)!important; border:1px solid var(--accent2)!important;
187
+ border-radius:var(--r)!important; margin-bottom:.6rem!important; }
188
+ .gradio-accordion .label-wrap span { color:var(--accent2)!important; font-family:'Syne',sans-serif!important;
189
+ font-weight:700!important; font-size:.85rem!important; letter-spacing:.04em!important; }
190
+ .gradio-accordion svg { color:var(--accent2)!important; stroke:var(--accent2)!important; }
191
+ .foot { text-align:center; padding:1.5rem; color:var(--muted); font-family:'DM Mono',monospace;
192
+ font-size:.68rem; border-top:1px solid var(--border); margin-top:2rem; letter-spacing:.05em; }
193
  """
194
 
195
  with gr.Blocks(css=CSS, title="Metabolic Phoenix Framework") as demo:
 
206
  run_btn = gr.Button("⚡ Analyse", variant="primary")
207
 
208
  with gr.Accordion("Cycle 1 — Fact Ledger", open=True):
209
+ out1 = gr.Textbox(label="", lines=12, elem_classes=["out"])
210
  rb1_btn = gr.Button("🔊 Read Cycle 1", variant="secondary")
211
+ audio1 = gr.Audio(label="Cycle 1 Audio", autoplay=True)
212
 
213
  with gr.Accordion("Cycle 2 — Compliance Analysis", open=False):
214
+ out2 = gr.Textbox(label="", lines=12, elem_classes=["out"])
215
  rb2_btn = gr.Button("🔊 Read Cycle 2", variant="secondary")
216
+ audio2 = gr.Audio(label="Cycle 2 Audio", autoplay=True)
217
 
218
  with gr.Accordion("Cycle 3 — Ouroboros Loops", open=False):
219
+ out3 = gr.Textbox(label="", lines=12, elem_classes=["out"])
220
  rb3_btn = gr.Button("🔊 Read Cycle 3", variant="secondary")
221
+ audio3 = gr.Audio(label="Cycle 3 Audio", autoplay=True)
222
 
223
  with gr.Accordion("Cycle 4 — Full Case Output", open=False):
224
+ out4 = gr.Textbox(label="", lines=12, elem_classes=["out"])
225
  rb4_btn = gr.Button("🔊 Read Cycle 4", variant="secondary")
226
+ audio4 = gr.Audio(label="Cycle 4 Audio", autoplay=True)
227
 
228
  rball_btn = gr.Button("🔊 Read Full Analysis", variant="primary")
229
+ audio_all = gr.Audio(label="Full Analysis Audio", autoplay=True)
230
 
231
+ save_btn = gr.Button("💾 Save & Download Analysis", variant="secondary")
232
+ dl_file = gr.File(label="Download your analysis", visible=False)
233
+ save_msg = gr.Markdown("")
234
 
235
  run_btn.click(analyse, inputs=[pdf_input], outputs=[out1, out2, out3, out4])
236
+ rb1_btn.click(read_cycle1, inputs=[out1], outputs=[audio1])
237
+ rb2_btn.click(read_cycle2, inputs=[out2], outputs=[audio2])
238
+ rb3_btn.click(read_cycle3, inputs=[out3], outputs=[audio3])
239
+ rb4_btn.click(read_cycle4, inputs=[out4], outputs=[audio4])
240
+ rball_btn.click(read_all, inputs=[out1, out2, out3, out4], outputs=[audio_all])
 
 
 
 
 
 
 
241
  save_btn.click(save_analysis, inputs=[out1, out2, out3, out4], outputs=[dl_file, save_msg])
242
 
243
  gr.HTML("""