Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,32 @@
|
|
1 |
import gradio as gr
|
2 |
-
import numpy as np
|
3 |
-
from PIL import Image
|
4 |
-
import cv2
|
5 |
-
import re
|
6 |
-
from paddleocr import PaddleOCR
|
7 |
from datetime import datetime
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
weight, texts = extract_weight_text(pre_img)
|
37 |
-
if weight and "Error" not in weight:
|
38 |
-
return f"Detected Weight: {weight} kg", datetime.now().strftime("Captured At: %Y-%m-%d %H:%M:%S"), pre_img, "\n".join(texts)
|
39 |
-
else:
|
40 |
-
return "Weight Not Detected", "", pre_img, "\n".join(texts)
|
41 |
-
|
42 |
-
gr.Interface(
|
43 |
-
fn=detect_weight,
|
44 |
-
inputs=gr.Image(type="pil", label="Upload or Capture Image"),
|
45 |
-
outputs=[
|
46 |
-
gr.Textbox(label="Weight"),
|
47 |
-
gr.Textbox(label="Timestamp"),
|
48 |
-
gr.Image(label="Preprocessed Image"),
|
49 |
-
gr.Textbox(label="Detected Text (Debug)")
|
50 |
-
],
|
51 |
-
title="Auto Weight Logger (Debug Mode)",
|
52 |
-
description="Upload a clear image of a digital scale. This version shows detected text for debugging."
|
53 |
-
).launch()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
2 |
from datetime import datetime
|
3 |
+
import pytz
|
4 |
+
from ocr_engine import extract_weight_from_image
|
5 |
|
6 |
+
def process_image(img):
|
7 |
+
if img is None:
|
8 |
+
return "No image uploaded", None, None, "No OCR output"
|
9 |
+
|
10 |
+
ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%d-%m-%Y %I:%M:%S %p")
|
11 |
+
weight, confidence, raw_text = extract_weight_from_image(img)
|
12 |
+
return f"{weight} kg (Confidence: {confidence}%)", ist_time, img, raw_text
|
13 |
+
|
14 |
+
with gr.Blocks(title="⚖️ Auto Weight Logger") as demo:
|
15 |
+
gr.Markdown("## ⚖️ Auto Weight Logger")
|
16 |
+
gr.Markdown("📷 **Upload or capture an image of a digital weight scale.** The app will auto-detect the weight in kilograms using OCR.")
|
17 |
+
|
18 |
+
with gr.Row():
|
19 |
+
image_input = gr.Image(type="pil", label="Upload / Capture Image")
|
20 |
+
output_weight = gr.Textbox(label="⚖️ Detected Weight (in kg)")
|
21 |
+
|
22 |
+
with gr.Row():
|
23 |
+
timestamp = gr.Textbox(label="🕒 Captured At (IST)")
|
24 |
+
snapshot = gr.Image(label="📸 Snapshot Image")
|
25 |
+
|
26 |
+
with gr.Row():
|
27 |
+
debug_output = gr.Textbox(label="🪵 Raw OCR Output")
|
28 |
+
|
29 |
+
submit = gr.Button("🔍 Detect Weight")
|
30 |
+
submit.click(process_image, inputs=image_input, outputs=[output_weight, timestamp, snapshot, debug_output])
|
31 |
+
|
32 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|