Update app.py
Browse files
app.py
CHANGED
@@ -6,24 +6,26 @@ import logging
|
|
6 |
logging.basicConfig(level=logging.DEBUG)
|
7 |
|
8 |
def display_sketch(sketch):
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
fig, ax = plt.subplots()
|
16 |
-
ax.imshow(image_data, cmap='gray')
|
17 |
plt.axis('off')
|
18 |
plt.savefig("/mnt/data/output.png", bbox_inches='tight')
|
19 |
return "/mnt/data/output.png"
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
23 |
|
24 |
with gr.Blocks() as demo:
|
25 |
-
sketchpad = gr.Sketchpad(label="Draw Something"
|
26 |
output_image = gr.Image(label="Your Sketch")
|
27 |
-
|
|
|
28 |
|
29 |
demo.launch()
|
|
|
6 |
logging.basicConfig(level=logging.DEBUG)
|
7 |
|
8 |
def display_sketch(sketch):
|
9 |
+
logging.debug(f"Received sketch data: {sketch}")
|
10 |
+
|
11 |
+
if isinstance(sketch, dict) and "image" in sketch:
|
12 |
+
image_data = sketch["image"]
|
13 |
+
logging.debug(f"Image data type: {type(image_data)}")
|
14 |
+
logging.debug(f"Image data shape: {np.array(image_data).shape}")
|
15 |
|
16 |
+
plt.imshow(image_data, cmap='gray')
|
|
|
|
|
17 |
plt.axis('off')
|
18 |
plt.savefig("/mnt/data/output.png", bbox_inches='tight')
|
19 |
return "/mnt/data/output.png"
|
20 |
+
else:
|
21 |
+
error_message = f"Unexpected sketch data format: {type(sketch)}"
|
22 |
+
logging.error(error_message)
|
23 |
+
return error_message
|
24 |
|
25 |
with gr.Blocks() as demo:
|
26 |
+
sketchpad = gr.Sketchpad(label="Draw Something")
|
27 |
output_image = gr.Image(label="Your Sketch")
|
28 |
+
submit_btn = gr.Button("Submit")
|
29 |
+
submit_btn.click(display_sketch, inputs=sketchpad, outputs=output_image)
|
30 |
|
31 |
demo.launch()
|