Spaces:
Sleeping
Sleeping
File size: 1,327 Bytes
0590b95 d55b56b 0590b95 d55b56b 0590b95 d55b56b 136c114 0590b95 d55b56b 0590b95 d55b56b |
1 2 3 4 5 6 7 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 37 38 |
import gradio as gr
from PIL import Image
from datetime import datetime
from ocr_engine import extract_weight
def process_image(image):
if image is None:
return "No image received", None, None
weight = extract_weight(image)
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
return f"{weight} grams", now, image
with gr.Blocks() as demo:
gr.Markdown("## π· Auto Weight Logger β OCR-Based Smart Scale Reader")
gr.Markdown("Upload a snapshot of a digital weight display or use webcam. The app extracts weight using OCR.")
with gr.Row():
webcam = gr.Image(source="webcam", type="pil", label="πΈ Capture from Webcam")
upload = gr.Image(source="upload", type="pil", label="π Or Upload Image")
image_input = gr.State()
def choose_image(w, u):
return w if w else u
webcam.change(fn=choose_image, inputs=[webcam, upload], outputs=image_input)
upload.change(fn=choose_image, inputs=[webcam, upload], outputs=image_input)
submit_btn = gr.Button("π Detect Weight")
weight_out = gr.Textbox(label="Detected Weight")
time_out = gr.Textbox(label="Captured At (IST)")
snapshot_out = gr.Image(label="Snapshot")
submit_btn.click(fn=process_image, inputs=image_input, outputs=[weight_out, time_out, snapshot_out])
demo.launch()
|