Basementup commited on
Commit
f95a38b
·
verified ·
1 Parent(s): 9f9c7cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -25
app.py CHANGED
@@ -3,49 +3,53 @@ from pypdf import PdfReader
3
 
4
  class MetamorphicPhoenix:
5
  def ingest_document(self, file_obj):
6
- # Organ 1: Sensory Cortex - PDF Perception
7
  if file_obj is None:
8
  return "No file detected."
9
  try:
10
- reader = PdfReader(file_obj.name)
11
- text = ""
12
- for page in reader.pages:
13
- text += page.extract_text() or ""
14
- return text.strip()
 
 
 
 
15
  except Exception as e:
16
- return f"Sensory Error: {str(e)}"
17
 
18
- def audit_logic(self, assertion, evidence):
19
- # Organ 3: Compliance Spine - Busted Logic
20
- if not assertion or not evidence:
21
- return "Awaiting data input..."
22
 
23
- # Pure text comparison - No emojis to break the code
24
- if assertion.lower().strip() not in evidence.lower():
25
- return "RESULT: BUSTED. Falsehood Matrix Detected. Assertion not in evidence."
26
- return "RESULT: VERIFIED. Assertion matches the Fact Ledger."
27
 
28
- # Initialize Organism
29
  system = MetamorphicPhoenix()
30
 
31
- # --- CLEAN INTERFACE ---
32
- with gr.Blocks(title="Metamorphic Phoenix") as demo:
33
  gr.Markdown("# THE METAMORPHIC PHOENIX")
34
- gr.Markdown("Universal Regulatory AI Architecture")
35
 
36
  with gr.Row():
37
  with gr.Column():
38
  gr.Markdown("### 1. Sensory Intake")
39
- file_input = gr.File(label="Upload PDF Evidence", file_types=[".pdf"])
40
- fact_ledger = gr.Textbox(label="Extracted Facts", lines=10, interactive=False)
41
- file_input.change(system.ingest_document, inputs=file_input, outputs=fact_ledger)
 
42
 
43
  with gr.Column():
44
  gr.Markdown("### 2. Forensic Audit")
45
- claim_input = gr.Textbox(label="Institutional Assertion")
46
  audit_btn = gr.Button("Execute Integrity Lock")
47
  result_output = gr.Textbox(label="Audit Outcome")
48
- audit_btn.click(system.audit_logic, inputs=[claim_input, fact_ledger], outputs=result_output)
49
 
50
- # CRITICAL: Keeps the heart beating
51
  demo.launch()
 
3
 
4
  class MetamorphicPhoenix:
5
  def ingest_document(self, file_obj):
6
+ # [span_7](start_span)[span_8](start_span)Organ 1: Sensory Cortex - PDF/Text Perception[span_7](end_span)[span_8](end_span)
7
  if file_obj is None:
8
  return "No file detected."
9
  try:
10
+ if file_obj.name.lower().endswith('.pdf'):
11
+ reader = PdfReader(file_obj.name)
12
+ text = ""
13
+ for page in reader.pages:
14
+ text += page.extract_text() or ""
15
+ return text.strip()
16
+ else:
17
+ with open(file_obj.name, 'r', encoding='utf-8') as f:
18
+ return f.read().strip()
19
  except Exception as e:
20
+ return f"Metabolic Error: {str(e)}"
21
 
22
+ def audit_logic(self, assertion, evidence_ledger):
23
+ # [span_9](start_span)[span_10](start_span)Organ 3: Compliance Spine (RHB 2.0) - Busted Trigger[span_9](end_span)[span_10](end_span)
24
+ if not assertion or not evidence_ledger:
25
+ return "Awaiting input for Integrity Lock..."
26
 
27
+ # [span_11](start_span)[span_12](start_span)Deterministic check: Is the claim physically in the evidence?[span_11](end_span)[span_12](end_span)
28
+ if assertion.lower().strip() not in evidence_ledger.lower():
29
+ return "🔴 BUSTED: Falsehood Matrix Detected. Assertion is NOT in the evidence."
30
+ return "🟢 VERIFIED: Assertion matches the Fact Ledger."
31
 
32
+ # [span_13](start_span)Initialize Organism[span_13](end_span)
33
  system = MetamorphicPhoenix()
34
 
35
+ with gr.Blocks(title="Metamorphic Phoenix Universal") as demo:
 
36
  gr.Markdown("# THE METAMORPHIC PHOENIX")
37
+ [span_14](start_span)gr.Markdown("Unified Regulatory AI Architecture[span_14](end_span)")
38
 
39
  with gr.Row():
40
  with gr.Column():
41
  gr.Markdown("### 1. Sensory Intake")
42
+ # [span_15](start_span)PDF Uploader replaces 'dry text' boxes[span_15](end_span)
43
+ file_uploader = gr.File(label="Upload Receipts (PDF or TXT)", file_types=[".pdf", ".txt"])
44
+ fact_ledger = gr.Textbox(label="Extracted Fact Ledger", lines=12, interactive=False)
45
+ file_uploader.change(system.ingest_document, inputs=file_uploader, outputs=fact_ledger)
46
 
47
  with gr.Column():
48
  gr.Markdown("### 2. Forensic Audit")
49
+ assertion_input = gr.Textbox(label="Institutional Assertion", placeholder="Paste what they claimed here...")
50
  audit_btn = gr.Button("Execute Integrity Lock")
51
  result_output = gr.Textbox(label="Audit Outcome")
52
+ audit_btn.click(system.audit_logic, inputs=[assertion_input, fact_ledger], outputs=result_output)
53
 
54
+ # [span_16](start_span)CRITICAL: Bootstrap command to keep the Space 'Running'[span_16](end_span)
55
  demo.launch()