Spaces:
Running
on
Zero
Running
on
Zero
ethanweber
commited on
Commit
•
43383ea
1
Parent(s):
920d26b
update
Browse files
app.py
CHANGED
@@ -11,11 +11,11 @@ import threading
|
|
11 |
viewer_thread_instance = None
|
12 |
stop_event = threading.Event()
|
13 |
shared_url = None
|
14 |
-
|
15 |
|
16 |
_HEADER_ = '''
|
17 |
<h2>Toon3D: Seeing Cartoons from a New Perspective</h2>
|
18 |
-
Toon3D lifts
|
19 |
|
20 |
<div style="margin-top: 20px; font-size: 16px; line-height: 1.6;">
|
21 |
<div style="display: flex; justify-content: space-between;">
|
@@ -62,7 +62,7 @@ def check_input_images(input_images):
|
|
62 |
raise gr.Error("No images uploaded!")
|
63 |
|
64 |
@spaces.GPU(duration=120)
|
65 |
-
def process_images(input_images,
|
66 |
|
67 |
images_path = "/tmp/gradio/images"
|
68 |
processed_path = "/tmp/gradio/processed"
|
@@ -82,10 +82,10 @@ def process_images(input_images, compute_segment_anything):
|
|
82 |
download_cmd = "tnd-download-data sam --save-dir /tmp/gradio"
|
83 |
os.system(download_cmd)
|
84 |
|
85 |
-
if
|
86 |
sam_cmd = " --compute-segment-anything"
|
87 |
else:
|
88 |
-
sam_cmd = ""
|
89 |
|
90 |
# process the data
|
91 |
process_data_cmd = f"tnd-process-data initialize --dataset toon3d-dataset --input_path {images_path} --data_prefix {processed_path} --sam_checkpoint_prefix /tmp/gradio/sam-checkpoints"
|
@@ -105,8 +105,8 @@ def toggle_labeler_visibility(visible):
|
|
105 |
return ""
|
106 |
|
107 |
def set_compute_segment_anything(value):
|
108 |
-
global
|
109 |
-
|
110 |
|
111 |
def check_input_toon3d(processed_data_zip, labeled_data):
|
112 |
if processed_data_zip is None:
|
@@ -266,7 +266,7 @@ with gr.Blocks(title="Toon3D") as demo:
|
|
266 |
|
267 |
process_data_button.click(fn=check_input_images, inputs=[input_images]).success(
|
268 |
fn=process_images,
|
269 |
-
inputs=[input_images,
|
270 |
outputs=[processed_data_zip],
|
271 |
)
|
272 |
|
|
|
11 |
viewer_thread_instance = None
|
12 |
stop_event = threading.Event()
|
13 |
shared_url = None
|
14 |
+
compute_segment_anything_value = False
|
15 |
|
16 |
_HEADER_ = '''
|
17 |
<h2>Toon3D: Seeing Cartoons from a New Perspective</h2>
|
18 |
+
Toon3D lifts hand-drawn images to 3D with a piecewise-rigid deformation optimization at hand-labeled keypoints and using monocular depth as a prior. The project page is at <a href='https://toon3d.studio/' target='_blank'>https://toon3d.studio/</a> and the Toon3D Labeler is at <a href='https://labeler.toon3d.studio/' target='_blank'>https://labeler.toon3d.studio/</a>. Follow the steps below to run Toon3D!
|
19 |
|
20 |
<div style="margin-top: 20px; font-size: 16px; line-height: 1.6;">
|
21 |
<div style="display: flex; justify-content: space-between;">
|
|
|
62 |
raise gr.Error("No images uploaded!")
|
63 |
|
64 |
@spaces.GPU(duration=120)
|
65 |
+
def process_images(input_images, compute_segment_anything_value):
|
66 |
|
67 |
images_path = "/tmp/gradio/images"
|
68 |
processed_path = "/tmp/gradio/processed"
|
|
|
82 |
download_cmd = "tnd-download-data sam --save-dir /tmp/gradio"
|
83 |
os.system(download_cmd)
|
84 |
|
85 |
+
if compute_segment_anything_value:
|
86 |
sam_cmd = " --compute-segment-anything"
|
87 |
else:
|
88 |
+
sam_cmd = " --no-compute-segment-anything"
|
89 |
|
90 |
# process the data
|
91 |
process_data_cmd = f"tnd-process-data initialize --dataset toon3d-dataset --input_path {images_path} --data_prefix {processed_path} --sam_checkpoint_prefix /tmp/gradio/sam-checkpoints"
|
|
|
105 |
return ""
|
106 |
|
107 |
def set_compute_segment_anything(value):
|
108 |
+
global compute_segment_anything_value
|
109 |
+
compute_segment_anything_value = value
|
110 |
|
111 |
def check_input_toon3d(processed_data_zip, labeled_data):
|
112 |
if processed_data_zip is None:
|
|
|
266 |
|
267 |
process_data_button.click(fn=check_input_images, inputs=[input_images]).success(
|
268 |
fn=process_images,
|
269 |
+
inputs=[input_images, compute_segment_anything_value],
|
270 |
outputs=[processed_data_zip],
|
271 |
)
|
272 |
|