Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ import os
|
|
6 |
|
7 |
import gradio as gr
|
8 |
import requests
|
9 |
-
|
10 |
from func_timeout import FunctionTimedOut, func_timeout
|
11 |
from tqdm import tqdm
|
12 |
|
@@ -402,9 +402,14 @@ def img_to_code_img(sketchpad_img):
|
|
402 |
# img.save(f)
|
403 |
|
404 |
# img = sketchpad_img['layers'][0]
|
405 |
-
|
406 |
-
|
407 |
-
|
|
|
|
|
|
|
|
|
|
|
408 |
# image_array = 255 - image_array[:,:,3]
|
409 |
|
410 |
# height, width = image_array.shape
|
@@ -466,6 +471,9 @@ def main():
|
|
466 |
for file in files:
|
467 |
if file.endswith(".png"):
|
468 |
example_input_images.append(os.path.join(root, file))
|
|
|
|
|
|
|
469 |
|
470 |
canvas = gr.Sketchpad(canvas_size=(512,512), brush=Brush(colors=["black"], default_size=2, color_mode='fixed'))
|
471 |
with gr.Blocks(theme=theme) as demo:
|
@@ -478,8 +486,10 @@ def main():
|
|
478 |
with gr.Column(scale=1):
|
479 |
canvas.render()
|
480 |
submit_button = gr.Button("Generate Programs")
|
|
|
|
|
481 |
with gr.Column(min_width=60):
|
482 |
-
gr.Examples(
|
483 |
with gr.Column(scale=6):
|
484 |
output_gallery = gr.Gallery(
|
485 |
label="Generated Images", show_label=True, elem_id="gallery"
|
|
|
6 |
|
7 |
import gradio as gr
|
8 |
import requests
|
9 |
+
from openai import OpenAI
|
10 |
from func_timeout import FunctionTimedOut, func_timeout
|
11 |
from tqdm import tqdm
|
12 |
|
|
|
402 |
# img.save(f)
|
403 |
|
404 |
# img = sketchpad_img['layers'][0]
|
405 |
+
if np.all(sketchpad_img['background']==0):
|
406 |
+
img = sketchpad_img['layers'][0]
|
407 |
+
image_array = np.array(img)
|
408 |
+
image_array = 255 - image_array[:,:,3]
|
409 |
+
else:
|
410 |
+
img = sketchpad_img['composite']
|
411 |
+
image_array = np.array(img)
|
412 |
+
image_array = image_array[:,:,0]
|
413 |
# image_array = 255 - image_array[:,:,3]
|
414 |
|
415 |
# height, width = image_array.shape
|
|
|
471 |
for file in files:
|
472 |
if file.endswith(".png"):
|
473 |
example_input_images.append(os.path.join(root, file))
|
474 |
+
SHOWN_SAMPLES = [58, 63, 73, 82, 90, 98]
|
475 |
+
shown_example_input_images = [f"demo_example/img_{i}.png" for i in SHOWN_SAMPLES]
|
476 |
+
rest_of_example_images = [path for path in example_input_images if path not in shown_example_input_images]
|
477 |
|
478 |
canvas = gr.Sketchpad(canvas_size=(512,512), brush=Brush(colors=["black"], default_size=2, color_mode='fixed'))
|
479 |
with gr.Blocks(theme=theme) as demo:
|
|
|
486 |
with gr.Column(scale=1):
|
487 |
canvas.render()
|
488 |
submit_button = gr.Button("Generate Programs")
|
489 |
+
with gr.Accordion("More Examples"):
|
490 |
+
gr.Examples(rest_of_example_images, inputs=canvas, label='Example Input')
|
491 |
with gr.Column(min_width=60):
|
492 |
+
gr.Examples(shown_example_input_images, inputs=canvas, label='Example Input')
|
493 |
with gr.Column(scale=6):
|
494 |
output_gallery = gr.Gallery(
|
495 |
label="Generated Images", show_label=True, elem_id="gallery"
|