Spaces:
Sleeping
Sleeping
File size: 1,366 Bytes
0590b95 d55b56b 0590b95 d55b56b c1c018a d55b56b c1c018a 136c114 0590b95 c1c018a d55b56b c1c018a d55b56b c1c018a d55b56b c1c018a d55b56b c1c018a d55b56b c1c018a d55b56b c1c018a 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 |
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 provided", 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 or use webcam. The app extracts weight using OCR.")
with gr.Row():
camera_input = gr.Camera(label="πΈ Capture via Webcam", type="pil")
upload_input = gr.Image(label="π Upload Image", type="pil")
selected_image = gr.State()
def choose_latest_image(cam_img, upload_img):
return cam_img if cam_img is not None else upload_img
camera_input.change(fn=choose_latest_image, inputs=[camera_input, upload_input], outputs=selected_image)
upload_input.change(fn=choose_latest_image, inputs=[camera_input, upload_input], outputs=selected_image)
btn = gr.Button("π Detect Weight")
weight_out = gr.Textbox(label="Detected Weight")
time_out = gr.Textbox(label="Captured At (IST)")
preview = gr.Image(label="Snapshot")
btn.click(fn=process_image, inputs=selected_image, outputs=[weight_out, time_out, preview])
demo.launch()
|