Spaces:
Runtime error
Runtime error
Update app.py
Browse files67 unmodified lines68697071727337 unmodified lines11111211311411511611711811912012112258 unmodified lines18118218318418518618767 unmodified lines# Remove the Base64 prefix (if exists) and decode the imageimage_data = re.sub('^data:image/.+;base64,', '', base64_image)image = Image.open(BytesIO(base64.b64decode(image_data)))return imageexcept Exception as e:print(f"Error decoding image: {e}")37 unmodified lines# Decode Base64 imageimage = decode_base64_image(base64_image)if image is None:return "Error decoding the image. Ensure the image is captured correctly."# Extract text using OCRextracted_text = extract_text(image)if extracted_text == "Error processing the image.":return extracted_text# Match product nameproduct_name = match_product_name(extracted_text)58 unmodified linesgr.JSON(label="Extracted Attributes"),],title="Camera Image Processing with OCR",description="Use the camera to capture an image, process it with OCR, and extract product attributes.")demo.launch(share=True)67 unmodified lines6869707172737437 unmodified lines11211311411511611711811912012112212358 unmodified lines18218318418518618718867 unmodified lines# Remove the Base64 prefix (if exists) and decode the imageimage_data = re.sub('^data:image/.+;base64,', '', base64_image)image = Image.open(BytesIO(base64.b64decode(image_data)))print("Decoded image successfully.") # Debug logreturn imageexcept Exception as e:print(f"Error decoding image: {e}")37 unmodified lines# Decode Base64 imageimage = decode_base64_image(base64_image)if image is None:return {"Extracted Text": "Error decoding the image.", "Matched Product Name": "N/A", "Extracted Attributes": {}}# Extract text using OCRextracted_text = extract_text(image)if extracted_text == "Error processing the image.":return {"Extracted Text": extracted_text, "Matched Product Name": "N/A", "Extracted Attributes": {}}# Match product nameproduct_name = match_product_name(extracted_text)58 unmodified linesgr.JSON(label="Extracted Attributes"),],title="Camera Image Processing with OCR",description="Capture an image with the camera and extract text, attributes, and product names using OCR.")demo.launch(share=True)
app.py+4-3