tedlasai commited on
Commit
94fad85
·
1 Parent(s): add1478
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -23,7 +23,7 @@ pipe, device = load_model(args)
23
  OUTPUT_DIR = Path("/tmp/output_stacks")
24
  OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
25
 
26
-
27
  def generate_vstack_from_image(image: Image.Image, input_focal_position: int, num_inference_steps: int) -> str:
28
  """
29
  Wrapper for Gradio. Takes an image and returns a video path.
@@ -46,7 +46,9 @@ def generate_vstack_from_image(image: Image.Image, input_focal_position: int, nu
46
  pipe.to(args.device)
47
  batch = convert_to_batch(args.image_path, input_focal_position=input_focal_position)
48
  output_frames, focal_stack_num = inference_on_image(args, batch, pipeline, device)
49
- write_output(OUTPUT_DIR, output_frames, focal_stack_num, batch['icc_profile'])
 
 
50
 
51
  if not os.path.exists(output_path):
52
  raise gr.Error("Video generation failed: output file not found.")
@@ -65,7 +67,7 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
65
  - 🌐 **Project page:** <https://learn2refocus.github.io/>
66
  - 💻 **Code:** <https://github.com/tedlasai/learn2refocus/>
67
 
68
- Upload an image specify the input focal position. Near - 5cm, Far - Infinity. Then, click "Generate stack" to generate a focal stack.
69
  """
70
  )
71
 
 
23
  OUTPUT_DIR = Path("/tmp/output_stacks")
24
  OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
25
 
26
+ @spaces.GPU(timeout=300, duration=80)
27
  def generate_vstack_from_image(image: Image.Image, input_focal_position: int, num_inference_steps: int) -> str:
28
  """
29
  Wrapper for Gradio. Takes an image and returns a video path.
 
46
  pipe.to(args.device)
47
  batch = convert_to_batch(args.image_path, input_focal_position=input_focal_position)
48
  output_frames, focal_stack_num = inference_on_image(args, batch, pipeline, device)
49
+ save_dir = os.path.join(OUTPUT_DIR, batch['name'])
50
+
51
+ write_output(save_dir, output_frames, focal_stack_num, batch['icc_profile'])
52
 
53
  if not os.path.exists(output_path):
54
  raise gr.Error("Video generation failed: output file not found.")
 
67
  - 🌐 **Project page:** <https://learn2refocus.github.io/>
68
  - 💻 **Code:** <https://github.com/tedlasai/learn2refocus/>
69
 
70
+ Upload an image specify the input focal position (these values correspond to iPhone API positions, but approximately linear in diopters (inverse meters): 0 - 5cm, 8 - Infinity). Then, click "Generate stack" to generate a focal stack.
71
  """
72
  )
73