Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from datetime import datetime | |
| import pytz | |
| from ocr_engine import extract_weight_from_image | |
| def process_image(img): | |
| if img is None: | |
| return "No image uploaded", None, None | |
| ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%d-%m-%Y %I:%M:%S %p") | |
| weight, confidence = extract_weight_from_image(img) | |
| return f"{weight} g (Confidence: {confidence}%)", ist_time, img | |
| with gr.Blocks(title="βοΈ Auto Weight Logger") as demo: | |
| gr.Markdown("## βοΈ Auto Weight Logger\nUpload or capture an image of a digital scale to auto-detect the weight.") | |
| with gr.Row(): | |
| image_input = gr.Image(type="pil", label="π· Upload or Capture Image") | |
| submit = gr.Button("π Detect Weight") | |
| with gr.Row(): | |
| output_weight = gr.Textbox(label="βοΈ Detected Weight") | |
| timestamp = gr.Textbox(label="π Captured At (IST)") | |
| snapshot = gr.Image(label="πΈ Snapshot Image") | |
| submit.click(process_image, inputs=image_input, outputs=[output_weight, timestamp, snapshot]) | |
| demo.launch() | |