Ayush soni commited on
Commit
e98e646
·
1 Parent(s): 6034171

app.py fixwd

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -5,28 +5,28 @@ from llm_processor import load_llm_model, generate_json_from_text
5
  # Load LLM model on startup
6
  load_llm_model()
7
 
8
- def process_invoice(file):
9
- # Read file bytes
10
- image_bytes = file.read()
11
 
12
- # Step 1: Extract raw text
13
- raw_text = extract_text_from_image(image_bytes)
14
  if not raw_text or "No text detected" in raw_text:
15
  return raw_text, {"error": "No text could be extracted from the image."}
16
 
17
- # Step 2: Convert raw text → structured JSON
18
  json_data = generate_json_from_text(raw_text)
19
-
20
  return raw_text, json_data
21
 
22
 
 
23
  ### Gradio UI
24
  with gr.Blocks() as demo:
25
  gr.Markdown("# 🧾 Invoice Processing App")
26
  gr.Markdown("Upload an invoice image. The app extracts **OCR text** and generates **structured JSON**.")
27
 
28
  with gr.Row():
29
- input_file = gr.File(label="Upload Invoice Image", type="file", file_types=[".png", ".jpg", ".jpeg"])
30
 
31
  with gr.Row():
32
  raw_text_output = gr.Textbox(label="Extracted OCR Text", lines=10)
 
5
  # Load LLM model on startup
6
  load_llm_model()
7
 
8
+ def process_invoice(file_bytes):
9
+ if file_bytes is None:
10
+ return "No file uploaded", {"error": "No file uploaded"}
11
 
12
+ # Step 1: Extract text
13
+ raw_text = extract_text_from_image(file_bytes)
14
  if not raw_text or "No text detected" in raw_text:
15
  return raw_text, {"error": "No text could be extracted from the image."}
16
 
17
+ # Step 2: JSON generation
18
  json_data = generate_json_from_text(raw_text)
 
19
  return raw_text, json_data
20
 
21
 
22
+
23
  ### Gradio UI
24
  with gr.Blocks() as demo:
25
  gr.Markdown("# 🧾 Invoice Processing App")
26
  gr.Markdown("Upload an invoice image. The app extracts **OCR text** and generates **structured JSON**.")
27
 
28
  with gr.Row():
29
+ input_file = gr.File(label="Upload Invoice Image", type="binary", file_types=[".png", ".jpg", ".jpeg"])
30
 
31
  with gr.Row():
32
  raw_text_output = gr.Textbox(label="Extracted OCR Text", lines=10)