Sanjayraju30 commited on
Commit
1757fdb
Β·
verified Β·
1 Parent(s): c1c018a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -14
app.py CHANGED
@@ -12,25 +12,15 @@ def process_image(image):
12
 
13
  with gr.Blocks() as demo:
14
  gr.Markdown("## πŸ“· Auto Weight Logger β€” OCR-Based Smart Scale Reader")
15
- gr.Markdown("Upload a snapshot or use webcam. The app extracts weight using OCR.")
16
 
17
- with gr.Row():
18
- camera_input = gr.Camera(label="πŸ“Έ Capture via Webcam", type="pil")
19
- upload_input = gr.Image(label="πŸ“ Upload Image", type="pil")
20
-
21
- selected_image = gr.State()
22
-
23
- def choose_latest_image(cam_img, upload_img):
24
- return cam_img if cam_img is not None else upload_img
25
-
26
- camera_input.change(fn=choose_latest_image, inputs=[camera_input, upload_input], outputs=selected_image)
27
- upload_input.change(fn=choose_latest_image, inputs=[camera_input, upload_input], outputs=selected_image)
28
 
29
  btn = gr.Button("πŸš€ Detect Weight")
30
  weight_out = gr.Textbox(label="Detected Weight")
31
  time_out = gr.Textbox(label="Captured At (IST)")
32
- preview = gr.Image(label="Snapshot")
33
 
34
- btn.click(fn=process_image, inputs=selected_image, outputs=[weight_out, time_out, preview])
35
 
36
  demo.launch()
 
12
 
13
  with gr.Blocks() as demo:
14
  gr.Markdown("## πŸ“· Auto Weight Logger β€” OCR-Based Smart Scale Reader")
15
+ gr.Markdown("Upload an image or capture from webcam. The app will extract the weight using OCR.")
16
 
17
+ image_input = gr.Image(type="pil", label="πŸ“Έ Upload or Capture Image (Webcam works in some browsers)")
 
 
 
 
 
 
 
 
 
 
18
 
19
  btn = gr.Button("πŸš€ Detect Weight")
20
  weight_out = gr.Textbox(label="Detected Weight")
21
  time_out = gr.Textbox(label="Captured At (IST)")
22
+ snapshot_out = gr.Image(label="Snapshot")
23
 
24
+ btn.click(fn=process_image, inputs=image_input, outputs=[weight_out, time_out, snapshot_out])
25
 
26
  demo.launch()