Update app.py
Browse files
app.py
CHANGED
@@ -21,11 +21,11 @@ def display_sketch(sketch):
|
|
21 |
logging.debug(f"Image data type: {type(image_data)}")
|
22 |
logging.debug(f"Image data shape: {image_data.shape}")
|
23 |
|
24 |
-
|
25 |
-
|
26 |
|
27 |
temp_file_path = os.path.join(os.getcwd(), "output.png")
|
28 |
-
|
29 |
logging.debug(f"Image saved to: {temp_file_path}")
|
30 |
|
31 |
return temp_file_path
|
@@ -43,6 +43,7 @@ def recognize_text(image_path):
|
|
43 |
# Generate the text
|
44 |
generated_ids = model.generate(pixel_values)
|
45 |
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
|
|
46 |
return generated_text
|
47 |
except Exception as e:
|
48 |
logging.error(f"Error in recognizing text: {e}")
|
|
|
21 |
logging.debug(f"Image data type: {type(image_data)}")
|
22 |
logging.debug(f"Image data shape: {image_data.shape}")
|
23 |
|
24 |
+
# Ensure the image is in the correct format
|
25 |
+
image = Image.fromarray(image_data, 'RGBA').convert('RGB')
|
26 |
|
27 |
temp_file_path = os.path.join(os.getcwd(), "output.png")
|
28 |
+
image.save(temp_file_path)
|
29 |
logging.debug(f"Image saved to: {temp_file_path}")
|
30 |
|
31 |
return temp_file_path
|
|
|
43 |
# Generate the text
|
44 |
generated_ids = model.generate(pixel_values)
|
45 |
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
46 |
+
logging.debug(f"Recognized text: {generated_text}")
|
47 |
return generated_text
|
48 |
except Exception as e:
|
49 |
logging.error(f"Error in recognizing text: {e}")
|