ethanweber commited on
Commit
02b79da
1 Parent(s): 2ae6e7b
Files changed (2) hide show
  1. app.py +3 -9
  2. requirements.txt +1 -2
app.py CHANGED
@@ -11,7 +11,6 @@ import threading
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>
@@ -62,7 +61,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, compute_segment_anything_value):
66
 
67
  images_path = "/tmp/gradio/images"
68
  processed_path = "/tmp/gradio/processed"
@@ -82,7 +81,7 @@ def process_images(input_images, compute_segment_anything_value):
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"
@@ -103,10 +102,6 @@ def toggle_labeler_visibility(visible):
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_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:
@@ -247,7 +242,6 @@ with gr.Blocks(title="Toon3D") as demo:
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"):
@@ -266,7 +260,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, compute_segment_anything_value],
270
  outputs=[processed_data_zip],
271
  )
272
 
 
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
  raise gr.Error("No images uploaded!")
62
 
63
  @spaces.GPU(duration=120)
64
+ def process_images(input_images, compute_segment_anything):
65
 
66
  images_path = "/tmp/gradio/images"
67
  processed_path = "/tmp/gradio/processed"
 
81
  download_cmd = "tnd-download-data sam --save-dir /tmp/gradio"
82
  os.system(download_cmd)
83
 
84
+ if compute_segment_anything:
85
  sam_cmd = " --compute-segment-anything"
86
  else:
87
  sam_cmd = " --no-compute-segment-anything"
 
102
  return '<iframe src="https://labeler.toon3d.studio/" style="display: block; margin: auto; width: 100%; height: 100vh;" frameborder="0"></iframe>'
103
  else:
104
  return ""
 
 
 
 
105
 
106
  def check_input_toon3d(processed_data_zip, labeled_data):
107
  if processed_data_zip is None:
 
242
  input_images = gr.File(label="Upload Images", file_count="multiple", file_types=[".jpg", "jpeg", "png"])
243
  with gr.Column():
244
  compute_segment_anything = gr.Checkbox(label="Compute Segment Anything? (slow)", value=False)
 
245
  process_data_button = gr.Button("Process Data", elem_id="process_data_button", variant="primary")
246
  processed_data_zip = gr.File(label="Processed Data", file_count="single", file_types=[".zip"], interactive=True)
247
  with gr.Row(variant="panel"):
 
260
 
261
  process_data_button.click(fn=check_input_images, inputs=[input_images]).success(
262
  fn=process_images,
263
+ inputs=[input_images, compute_segment_anything],
264
  outputs=[processed_data_zip],
265
  )
266
 
requirements.txt CHANGED
@@ -1,3 +1,2 @@
1
  toon3d==0.0.3
2
- segment_anything @ git+https://github.com/facebookresearch/segment-anything.git
3
- gradio>=4.29.0
 
1
  toon3d==0.0.3
2
+ segment_anything @ git+https://github.com/facebookresearch/segment-anything.git