vachaspathi commited on
Commit
ea92b60
·
verified ·
1 Parent(s): 0f61fc8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -18
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
- # 1. OCR & Metadata
 
 
 
 
7
  text, img, meta = ai_engine.perform_ocr(file)
8
- if not text: return None, "❌ OCR Failed / No Text Found"
9
 
10
- # 2. AI Classification (With Metadata)
 
 
 
 
 
 
 
11
  ai_output = ai_engine.extract_intelligent_json(text, meta)
12
 
13
- # 3. Execution
14
- log = f"📂 Filename: {meta.get('filename')}\n"
15
- log += f"🤖 AI Classification: {ai_output.get('doc_type')}\n"
16
- log += "----------------------------------\n"
17
-
18
- result = zoho_client.route_and_execute(ai_output)
19
 
20
- return img, log + result
 
 
 
 
 
21
 
22
- with gr.Blocks(title="Zoho Intelligent Agent") as demo:
23
- gr.Markdown("## 🧠 Zoho Autonomous Agent")
24
- gr.Markdown("The system uses **Filename + OCR Content** to decide the route.")
 
25
 
26
  with gr.Row():
27
- f_in = gr.File(label="Upload Document (Invoice, Bill, PO, Receipt)")
28
- btn = gr.Button("Analyze & Sync", variant="primary")
29
 
30
- out_img = gr.Image(label="Preview", height=300)
31
- out_res = gr.Textbox(label="Orchestrator Log", lines=8)
 
32
 
33
- btn.click(process_pipeline, f_in, [out_img, out_res])
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()