Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -68,6 +68,7 @@ def decode_base64_image(base64_image):
|
|
| 68 |
# Remove the Base64 prefix (if exists) and decode the image
|
| 69 |
image_data = re.sub('^data:image/.+;base64,', '', base64_image)
|
| 70 |
image = Image.open(BytesIO(base64.b64decode(image_data)))
|
|
|
|
| 71 |
return image
|
| 72 |
except Exception as e:
|
| 73 |
print(f"Error decoding image: {e}")
|
|
@@ -111,12 +112,12 @@ def process_camera_image(base64_image):
|
|
| 111 |
# Decode Base64 image
|
| 112 |
image = decode_base64_image(base64_image)
|
| 113 |
if image is None:
|
| 114 |
-
return "Error decoding the image.
|
| 115 |
|
| 116 |
# Extract text using OCR
|
| 117 |
extracted_text = extract_text(image)
|
| 118 |
if extracted_text == "Error processing the image.":
|
| 119 |
-
return extracted_text
|
| 120 |
|
| 121 |
# Match product name
|
| 122 |
product_name = match_product_name(extracted_text)
|
|
@@ -181,7 +182,7 @@ def app():
|
|
| 181 |
gr.JSON(label="Extracted Attributes"),
|
| 182 |
],
|
| 183 |
title="Camera Image Processing with OCR",
|
| 184 |
-
description="
|
| 185 |
)
|
| 186 |
demo.launch(share=True)
|
| 187 |
|
|
|
|
| 68 |
# Remove the Base64 prefix (if exists) and decode the image
|
| 69 |
image_data = re.sub('^data:image/.+;base64,', '', base64_image)
|
| 70 |
image = Image.open(BytesIO(base64.b64decode(image_data)))
|
| 71 |
+
print("Decoded image successfully.") # Debug log
|
| 72 |
return image
|
| 73 |
except Exception as e:
|
| 74 |
print(f"Error decoding image: {e}")
|
|
|
|
| 112 |
# Decode Base64 image
|
| 113 |
image = decode_base64_image(base64_image)
|
| 114 |
if image is None:
|
| 115 |
+
return {"Extracted Text": "Error decoding the image.", "Matched Product Name": "N/A", "Extracted Attributes": {}}
|
| 116 |
|
| 117 |
# Extract text using OCR
|
| 118 |
extracted_text = extract_text(image)
|
| 119 |
if extracted_text == "Error processing the image.":
|
| 120 |
+
return {"Extracted Text": extracted_text, "Matched Product Name": "N/A", "Extracted Attributes": {}}
|
| 121 |
|
| 122 |
# Match product name
|
| 123 |
product_name = match_product_name(extracted_text)
|
|
|
|
| 182 |
gr.JSON(label="Extracted Attributes"),
|
| 183 |
],
|
| 184 |
title="Camera Image Processing with OCR",
|
| 185 |
+
description="Capture an image with the camera and extract text, attributes, and product names using OCR."
|
| 186 |
)
|
| 187 |
demo.launch(share=True)
|
| 188 |
|