Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,51 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import ai_engine
|
| 3 |
import zoho_client
|
|
|
|
| 4 |
|
| 5 |
def process_pipeline(file):
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
text, img, meta = ai_engine.perform_ocr(file)
|
| 8 |
-
if not text: return None, "❌ OCR Failed / No Text Found"
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
ai_output = ai_engine.extract_intelligent_json(text, meta)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
log += "----------------------------------\n"
|
| 17 |
-
|
| 18 |
-
result = zoho_client.route_and_execute(ai_output)
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
gr.Markdown("
|
|
|
|
| 25 |
|
| 26 |
with gr.Row():
|
| 27 |
-
f_in = gr.File(label="Upload Document
|
| 28 |
-
btn = gr.Button("
|
| 29 |
|
| 30 |
-
out_img = gr.Image(label="
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
-
btn.click(process_pipeline, f_in, [out_img,
|
| 34 |
|
| 35 |
if __name__ == "__main__":
|
| 36 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import ai_engine
|
| 3 |
import zoho_client
|
| 4 |
+
import time
|
| 5 |
|
| 6 |
def process_pipeline(file):
|
| 7 |
+
logs = ""
|
| 8 |
+
|
| 9 |
+
# 1. OCR (Yield immediate feedback)
|
| 10 |
+
logs += "👁️ Scanning Document (OCR)...\n"
|
| 11 |
+
yield None, logs
|
| 12 |
text, img, meta = ai_engine.perform_ocr(file)
|
|
|
|
| 13 |
|
| 14 |
+
if not text:
|
| 15 |
+
logs += "❌ OCR Failed. No text found.\n"
|
| 16 |
+
yield None, logs
|
| 17 |
+
return
|
| 18 |
+
|
| 19 |
+
# 2. AI Extraction
|
| 20 |
+
logs += "🧠 AI Analyzing & Classifying...\n"
|
| 21 |
+
yield img, logs
|
| 22 |
ai_output = ai_engine.extract_intelligent_json(text, meta)
|
| 23 |
|
| 24 |
+
logs += f"🤖 Detected: {ai_output.get('doc_type')}\n"
|
| 25 |
+
logs += "----------------------------------\n"
|
| 26 |
+
yield img, logs
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
# 3. Orchestration (Consuming the Stream)
|
| 29 |
+
# We loop through the generator from zoho_client
|
| 30 |
+
for update in zoho_client.route_and_execute(ai_output):
|
| 31 |
+
logs += update # Append new log line
|
| 32 |
+
yield img, logs # Update UI
|
| 33 |
+
time.sleep(0.2) # Tiny visual delay for readability
|
| 34 |
|
| 35 |
+
# UI Setup
|
| 36 |
+
with gr.Blocks(title="Zoho Agentic") as demo:
|
| 37 |
+
gr.Markdown("## ⚡ Zoho Agentic Orchestrator (Live Stream)")
|
| 38 |
+
gr.Markdown("Upload a file. Watch the Agent resolve dependencies in real-time.")
|
| 39 |
|
| 40 |
with gr.Row():
|
| 41 |
+
f_in = gr.File(label="Upload Document")
|
| 42 |
+
btn = gr.Button("Start Processing", variant="primary")
|
| 43 |
|
| 44 |
+
out_img = gr.Image(label="Document View", height=400)
|
| 45 |
+
# Using a Code block for logs looks cooler/cleaner
|
| 46 |
+
out_log = gr.Code(label="Agent Execution Logs", language="shell")
|
| 47 |
|
| 48 |
+
btn.click(process_pipeline, f_in, [out_img, out_log])
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|
| 51 |
demo.launch()
|