logger / app.py
Sanjayraju30's picture
Update app.py
4aec32e verified
import gradio as gr
from PIL import Image
from datetime import datetime
import pytz
from ocr_engine import extract_weight
def process_image(image):
if image is None:
return "No image provided", "", None
try:
weight = extract_weight(image)
ist = pytz.timezone('Asia/Kolkata')
now_ist = datetime.now(ist).strftime("%Y-%m-%d %H:%M:%S IST")
return weight, now_ist, 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 weight image. AI detects numeric value and unit (kg or grams).")
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()