falba commited on
Commit
b049d04
1 Parent(s): 7455f5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -49,22 +49,27 @@ def yolo_and_trocr(image_input, save):
49
  # Saving the info in a dictionary
50
  if save:
51
  data_dict = ast.literal_eval(decoded_text)
52
- with open(f"{data_dict['Address']}.json", "w") as file:
 
53
  current_datetime = datetime.now()
54
  timestamp = current_datetime.strftime("%Y-%m-%d %H:%M:%S")
55
  data_dict['Last_Reading'] = {f'{timestamp}': f'{text}'}
56
- json.dump(data_dict, file, indent=4)
57
 
58
-
59
- return image, text, decoded_text
60
 
61
  except Exception as e:
62
  return "", f"Your input is invalid: {str(e)}", f"Try Again: Make sure the meter and QR code are clearly captured"
63
 
64
  app = gr.Interface(
65
  fn=yolo_and_trocr,
66
- inputs=[gr.File(label="Input: Water Meter Image"), gr.Checkbox(label="Save")],
67
- outputs=[gr.Image(label='Output: Water Meter Photo'), gr.Textbox(label="Output: Water Meter Reading"), gr.Textbox(label="Output: QR Code Detection")],
 
 
 
 
68
  title="Water Meter Reading with YOLO and OCR"
69
  )
70
 
 
49
  # Saving the info in a dictionary
50
  if save:
51
  data_dict = ast.literal_eval(decoded_text)
52
+ file_path = f"{data_dict['Address']}.json"
53
+ with open(file_path, "w") as file:
54
  current_datetime = datetime.now()
55
  timestamp = current_datetime.strftime("%Y-%m-%d %H:%M:%S")
56
  data_dict['Last_Reading'] = {f'{timestamp}': f'{text}'}
57
+ return image, text, decoded_text, file_path
58
 
59
+ else:
60
+ return image, text, decoded_text, None
61
 
62
  except Exception as e:
63
  return "", f"Your input is invalid: {str(e)}", f"Try Again: Make sure the meter and QR code are clearly captured"
64
 
65
  app = gr.Interface(
66
  fn=yolo_and_trocr,
67
+ inputs=[gr.File(label="Input: Water Meter Image"),
68
+ gr.Checkbox(label="Save")],
69
+ outputs=[gr.Image(label='Output: Water Meter Photo'),
70
+ gr.Textbox(label="Output: Water Meter Reading"),
71
+ gr.Textbox(label="Output: QR Code Detection"),
72
+ gr.File(label="Output: Saved Data")],
73
  title="Water Meter Reading with YOLO and OCR"
74
  )
75