Basementup commited on
Commit
adcb9c5
·
verified ·
1 Parent(s): e8f2761

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -17
app.py CHANGED
@@ -2,9 +2,10 @@ import gradio as gr
2
  from pypdf import PdfReader
3
 
4
  class MetamorphicPhoenix:
5
- def ingest_pdf(self, file_obj):
 
6
  if file_obj is None:
7
- return "No file uploaded."
8
  try:
9
  reader = PdfReader(file_obj.name)
10
  text = ""
@@ -12,32 +13,42 @@ class MetamorphicPhoenix:
12
  text += page.extract_text() or ""
13
  return text.strip()
14
  except Exception as e:
15
- return f"Error reading PDF: {str(e)}"
16
 
17
- def integrity_lock(self, assertion, evidence):
18
- if not assertion or not evidence:
 
19
  return "Awaiting input..."
20
- if assertion.lower().strip() not in evidence.lower():
21
- return "🔴 BUSTED: Assertion not found in evidence ledger."
22
- return "🟢 VERIFIED: Assertion matches evidence."
 
 
23
 
 
24
  system = MetamorphicPhoenix()
25
 
26
  with gr.Blocks(title="Metamorphic Phoenix") as demo:
27
- gr.Markdown("# METAMORPHIC PHOENIX: UNIVERSAL REGULATORY AI")
28
 
29
  with gr.Row():
30
  with gr.Column():
31
- gr.Markdown("### 1. Sensory Intake (PDF)")
32
- file_input = gr.File(label="Upload PDF Evidence", file_types=[".pdf"])
33
- evidence_box = gr.Textbox(label="Extracted Facts", lines=10)
34
- file_input.change(system.ingest_pdf, inputs=file_input, outputs=evidence_box)
 
35
 
 
 
 
36
  with gr.Column():
37
  gr.Markdown("### 2. Forensic Audit")
38
- claim_input = gr.Textbox(label="Institutional Claim / Assertion")
39
- run_btn = gr.Button("Trigger Integrity Lock")
40
- result_box = gr.Textbox(label="Result")
41
- run_btn.click(system.integrity_lock, inputs=[claim_input, evidence_box], outputs=result_box)
 
42
 
 
43
  demo.launch()
 
2
  from pypdf import PdfReader
3
 
4
  class MetamorphicPhoenix:
5
+ def process_pdf(self, file_obj):
6
+ # Organ 1: Sensory Cortex - Converts PDF to Atomic Facts
7
  if file_obj is None:
8
+ return ""
9
  try:
10
  reader = PdfReader(file_obj.name)
11
  text = ""
 
13
  text += page.extract_text() or ""
14
  return text.strip()
15
  except Exception as e:
16
+ return f"Metabolic Error (PDF): {str(e)}"
17
 
18
+ def integrity_lock(self, assertion, evidence_ledger):
19
+ # Organ 3: Compliance Spine (RHB 2.0) - The 'Busted' Trigger
20
+ if not assertion or not evidence_ledger:
21
  return "Awaiting input..."
22
+
23
+ # Exact mathematical comparison for Zero-Hallucination
24
+ if assertion.lower().strip() not in evidence_ledger.lower():
25
+ return "🔴 BUSTED: Falsehood Matrix Detected. Assertion not in the evidence."
26
+ return "🟢 VERIFIED: Assertion matches the Fact Ledger."
27
 
28
+ # Initialize the Framework
29
  system = MetamorphicPhoenix()
30
 
31
  with gr.Blocks(title="Metamorphic Phoenix") as demo:
32
+ gr.Markdown("# THE METAMORPHIC PHOENIX: UNIVERSAL REGULATORY AI")
33
 
34
  with gr.Row():
35
  with gr.Column():
36
+ gr.Markdown("### 1. Sensory Intake")
37
+ # Upgrade: This replaces the 'dry text' box with a File Uploader
38
+ file_input = gr.File(label="Upload Receipts (PDF)", file_types=[".pdf"])
39
+ # Hidden or visible box to hold the extracted facts
40
+ fact_ledger = gr.Textbox(label="Extracted Fact Ledger", lines=10, interactive=False)
41
 
42
+ # Link the file upload to the PDF reader
43
+ file_input.change(system.process_pdf, inputs=file_input, outputs=fact_ledger)
44
+
45
  with gr.Column():
46
  gr.Markdown("### 2. Forensic Audit")
47
+ assertion_input = gr.Textbox(label="Institutional Assertion", placeholder="Paste the claim here...")
48
+ audit_btn = gr.Button("Trigger Integrity Lock")
49
+ result_output = gr.Textbox(label="Outcome")
50
+
51
+ audit_btn.click(system.integrity_lock, inputs=[assertion_input, fact_ledger], outputs=result_output)
52
 
53
+ # CRITICAL: Keeps the Space alive on Hugging Face
54
  demo.launch()