Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from datetime import datetime
|
| 3 |
+
import pytz
|
| 4 |
+
from ocr_engine import extract_weight_from_image
|
| 5 |
+
|
| 6 |
+
def process_image(img):
|
| 7 |
+
if img is None:
|
| 8 |
+
return "No image uploaded", None, None
|
| 9 |
+
|
| 10 |
+
ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%d-%m-%Y %I:%M:%S %p")
|
| 11 |
+
weight, confidence = extract_weight_from_image(img)
|
| 12 |
+
return f"{weight} g (Confidence: {confidence}%)", ist_time, img
|
| 13 |
+
|
| 14 |
+
with gr.Blocks(title="⚖️ Auto Weight Logger") as demo:
|
| 15 |
+
gr.Markdown("## ⚖️ Auto Weight Logger")
|
| 16 |
+
|
| 17 |
+
with gr.Row():
|
| 18 |
+
image_input = gr.Image(type="pil", label="📷 Upload or Capture Image")
|
| 19 |
+
output_weight = gr.Textbox(label="⚖️ Detected Weight")
|
| 20 |
+
|
| 21 |
+
with gr.Row():
|
| 22 |
+
timestamp = gr.Textbox(label="🕒 Captured At (IST)")
|
| 23 |
+
snapshot = gr.Image(label="📸 Snapshot Image")
|
| 24 |
+
|
| 25 |
+
submit = gr.Button("🔍 Detect Weight")
|
| 26 |
+
submit.click(process_image, inputs=image_input, outputs=[output_weight, timestamp, snapshot])
|
| 27 |
+
|
| 28 |
+
demo.launch()
|