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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -27
app.py CHANGED
@@ -2,10 +2,10 @@ import gradio as gr
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,42 +13,39 @@ class MetamorphicPhoenix:
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()
 
2
  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 = ""
 
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()