Basementup commited on
Commit
1377cde
·
verified ·
1 Parent(s): f95a38b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -44
app.py CHANGED
@@ -1,55 +1,39 @@
1
  import gradio as gr
2
  from pypdf import PdfReader
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()
 
1
  import gradio as gr
2
  from pypdf import PdfReader
3
 
4
+ def check_evidence(assertion, file_obj):
5
+ if file_obj is None or not assertion:
6
+ return "Waiting for file and assertion..."
7
+
8
+ try:
9
+ # Extract text from PDF
10
+ reader = PdfReader(file_obj.name)
11
+ evidence_text = ""
12
+ for page in reader.pages:
13
+ evidence_text += page.extract_text() or ""
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
+ # Simple, clean comparison
16
+ if assertion.lower().strip() in evidence_text.lower():
17
+ return "VERIFIED: The assertion was found in the document."
18
+ else:
19
+ return "FAILED: The assertion does not exist in the document."
20
+
21
+ except Exception as e:
22
+ return f"Error: {str(e)}"
23
 
24
+ # Minimalist Interface
25
+ with gr.Blocks() as demo:
26
+ gr.Markdown("# Universal Evidence Auditor")
27
 
28
  with gr.Row():
29
  with gr.Column():
30
+ file_input = gr.File(label="Upload PDF", file_types=[".pdf"])
31
+ claim_input = gr.Textbox(label="Assertion to Verify", placeholder="Paste the text you want to check...")
32
+ run_btn = gr.Button("Run Audit")
33
+
 
 
34
  with gr.Column():
35
+ output_text = gr.Textbox(label="Result", lines=5)
36
+
37
+ run_btn.click(check_evidence, inputs=[claim_input, file_input], outputs=output_text)
 
 
38
 
 
39
  demo.launch()