ethanweber commited on
Commit
920d26b
1 Parent(s): a344ed1

gradio update

Browse files
Files changed (2) hide show
  1. app.py +18 -3
  2. requirements.txt +1 -1
app.py CHANGED
@@ -11,6 +11,7 @@ import threading
11
  viewer_thread_instance = None
12
  stop_event = threading.Event()
13
  shared_url = None
 
14
 
15
  _HEADER_ = '''
16
  <h2>Toon3D: Seeing Cartoons from a New Perspective</h2>
@@ -61,7 +62,7 @@ def check_input_images(input_images):
61
  raise gr.Error("No images uploaded!")
62
 
63
  @spaces.GPU(duration=120)
64
- def process_images(input_images):
65
 
66
  images_path = "/tmp/gradio/images"
67
  processed_path = "/tmp/gradio/processed"
@@ -81,8 +82,15 @@ def process_images(input_images):
81
  download_cmd = "tnd-download-data sam --save-dir /tmp/gradio"
82
  os.system(download_cmd)
83
 
 
 
 
 
 
84
  # process the data
85
  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"
 
 
86
  os.system(process_data_cmd)
87
 
88
  zip_folder = "/tmp/gradio/processed/toon3d-dataset"
@@ -95,6 +103,10 @@ def toggle_labeler_visibility(visible):
95
  return '<iframe src="https://labeler.toon3d.studio/" style="display: block; margin: auto; width: 100%; height: 100vh;" frameborder="0"></iframe>'
96
  else:
97
  return ""
 
 
 
 
98
 
99
  def check_input_toon3d(processed_data_zip, labeled_data):
100
  if processed_data_zip is None:
@@ -233,7 +245,10 @@ with gr.Blocks(title="Toon3D") as demo:
233
  gr.Markdown(_HEADER_)
234
  with gr.Row(variant="panel"):
235
  input_images = gr.File(label="Upload Images", file_count="multiple", file_types=[".jpg", "jpeg", "png"])
236
- process_data_button = gr.Button("Process Data", elem_id="process_data_button", variant="primary")
 
 
 
237
  processed_data_zip = gr.File(label="Processed Data", file_count="single", file_types=[".zip"], interactive=True)
238
  with gr.Row(variant="panel"):
239
  labeler_visible = gr.Checkbox(label="Show Labeler", value=False)
@@ -251,7 +266,7 @@ with gr.Blocks(title="Toon3D") as demo:
251
 
252
  process_data_button.click(fn=check_input_images, inputs=[input_images]).success(
253
  fn=process_images,
254
- inputs=[input_images],
255
  outputs=[processed_data_zip],
256
  )
257
 
 
11
  viewer_thread_instance = None
12
  stop_event = threading.Event()
13
  shared_url = None
14
+ compute_segment_anything = False
15
 
16
  _HEADER_ = '''
17
  <h2>Toon3D: Seeing Cartoons from a New Perspective</h2>
 
62
  raise gr.Error("No images uploaded!")
63
 
64
  @spaces.GPU(duration=120)
65
+ def process_images(input_images, compute_segment_anything):
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:
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"
92
+ process_data_cmd += sam_cmd
93
+ print(process_data_cmd)
94
  os.system(process_data_cmd)
95
 
96
  zip_folder = "/tmp/gradio/processed/toon3d-dataset"
 
103
  return '<iframe src="https://labeler.toon3d.studio/" style="display: block; margin: auto; width: 100%; height: 100vh;" frameborder="0"></iframe>'
104
  else:
105
  return ""
106
+
107
+ def set_compute_segment_anything(value):
108
+ global compute_segment_anything
109
+ compute_segment_anything = value
110
 
111
  def check_input_toon3d(processed_data_zip, labeled_data):
112
  if processed_data_zip is None:
 
245
  gr.Markdown(_HEADER_)
246
  with gr.Row(variant="panel"):
247
  input_images = gr.File(label="Upload Images", file_count="multiple", file_types=[".jpg", "jpeg", "png"])
248
+ with gr.Column():
249
+ compute_segment_anything = gr.Checkbox(label="Compute Segment Anything? (slow)", value=False)
250
+ compute_segment_anything.change(set_compute_segment_anything, inputs=[compute_segment_anything])
251
+ process_data_button = gr.Button("Process Data", elem_id="process_data_button", variant="primary")
252
  processed_data_zip = gr.File(label="Processed Data", file_count="single", file_types=[".zip"], interactive=True)
253
  with gr.Row(variant="panel"):
254
  labeler_visible = gr.Checkbox(label="Show Labeler", value=False)
 
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],
270
  outputs=[processed_data_zip],
271
  )
272
 
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
- toon3d==0.0.2
2
  segment_anything @ git+https://github.com/facebookresearch/segment-anything.git
 
1
+ toon3d==0.0.3
2
  segment_anything @ git+https://github.com/facebookresearch/segment-anything.git