Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,9 +2,10 @@ import gradio as gr
|
|
| 2 |
from pypdf import PdfReader
|
| 3 |
|
| 4 |
class MetamorphicPhoenix:
|
| 5 |
-
def
|
|
|
|
| 6 |
if file_obj is None:
|
| 7 |
-
return "
|
| 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
|
| 16 |
|
| 17 |
-
def integrity_lock(self, assertion,
|
| 18 |
-
|
|
|
|
| 19 |
return "Awaiting input..."
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
| 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
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
| 35 |
|
|
|
|
|
|
|
|
|
|
| 36 |
with gr.Column():
|
| 37 |
gr.Markdown("### 2. Forensic Audit")
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
| 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()
|