Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,55 +1,39 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from pypdf import PdfReader
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 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 |
-
#
|
| 28 |
-
if assertion.lower().strip()
|
| 29 |
-
return "
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
with gr.Row():
|
| 40 |
with gr.Column():
|
| 41 |
-
gr.
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
file_uploader.change(system.ingest_document, inputs=file_uploader, outputs=fact_ledger)
|
| 46 |
-
|
| 47 |
with gr.Column():
|
| 48 |
-
gr.
|
| 49 |
-
|
| 50 |
-
|
| 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()
|