Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
|
|
|
| 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 |
-
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 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"),
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|