Spaces:
Running
Running
File size: 1,052 Bytes
0590b95 d55b56b 0590b95 d55b56b a4391a6 91bcc4e a4391a6 91bcc4e a4391a6 d55b56b a4391a6 136c114 a4391a6 d55b56b f32159a a4391a6 f32159a 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 |
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()
|