Spaces:
Sleeping
Sleeping
| 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 | |
| try: | |
| weight = extract_weight(image) | |
| timestamp = datetime.now().astimezone().strftime("%Y-%m-%d %H:%M:%S %Z") | |
| return f"{weight} grams", timestamp, image | |
| except Exception as e: | |
| return f"Error: {str(e)}", "", None | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## π· Auto Weight Logger β Hugging Face OCR Edition") | |
| gr.Markdown("Upload a digital scale image. Detects weight using a transformer-based OCR model.") | |
| image_input = gr.Image(type="pil", label="π Upload or Capture Image") | |
| detect_btn = gr.Button("π Detect Weight") | |
| weight_out = gr.Textbox(label="Detected Weight") | |
| time_out = gr.Textbox(label="Captured At (IST)") | |
| snapshot = gr.Image(label="Snapshot") | |
| detect_btn.click(fn=process_image, inputs=image_input, outputs=[weight_out, time_out, snapshot]) | |
| demo.launch() | |