ccareaga commited on
Commit
8a26694
1 Parent(s): 43b01fb

space running locally on cpu

Browse files
Files changed (1) hide show
  1. app.py +16 -18
app.py CHANGED
@@ -1,41 +1,39 @@
1
  import gradio as gr
 
2
 
3
- from chrislib.general import uninvert, view
4
 
5
  from intrinsic.pipeline import load_models, run_pipeline
6
 
7
- # load the intrinsic models
8
- intrinsic_models = load_models('v2')
9
 
10
  def generate_pipeline(models):
11
 
12
- def pipeline_func(image):
13
- return run_pipeline(models, image, device='cuda')
14
 
15
  return pipeline_func
16
 
17
 
18
- run_pipeline = generate_pipeline(intrinsic_models)
19
 
20
  def process_image(image):
21
  print(image.shape)
 
22
 
23
- # Process the image with your model pipeline
24
- result = run_pipeline(image)
25
 
26
- out_keys = ['hr_alb', 'dif_shd', 'pos_res']
27
- # Create a list to store output images
28
- output_images = []
29
- for k in out_keys:
30
- output_images.append(result[k])
31
-
32
- return output_images
33
 
34
  interface = gr.Interface(
35
  fn=process_image,
36
- inputs=gr.inputs.Image(type="numpy"),
37
- outputs=gr.outputs.Image(type="numpy", label="Output Images", tool="editor"),
 
 
 
 
38
  live=True
39
  )
40
 
41
- interface.launch()
 
1
  import gradio as gr
2
+ import numpy as np
3
 
4
+ from chrislib.general import uninvert, invert, view, view_scale
5
 
6
  from intrinsic.pipeline import load_models, run_pipeline
7
 
8
+ intrinsic_models = load_models('v2', device='cpu')
 
9
 
10
  def generate_pipeline(models):
11
 
12
+ def pipeline_func(image, **kwargs):
13
+ return run_pipeline(models, image, **kwargs)
14
 
15
  return pipeline_func
16
 
17
 
18
+ pipeline_func = generate_pipeline(intrinsic_models)
19
 
20
  def process_image(image):
21
  print(image.shape)
22
+ image = image.astype(np.single) / 255.
23
 
24
+ result = pipeline_func(image, device='cpu')
 
25
 
26
+ return [view(result['hr_alb']), 1 - invert(result['dif_shd']), view_scale(result['pos_res'])]
 
 
 
 
 
 
27
 
28
  interface = gr.Interface(
29
  fn=process_image,
30
+ inputs=gr.components.Image(type="numpy"),
31
+ outputs=[
32
+ gr.components.Image(type='numpy', label="Albedo"),
33
+ gr.components.Image(type='numpy', label="Diffuse Shading"),
34
+ gr.components.Image(type='numpy', label="Residual"),
35
+ ],
36
  live=True
37
  )
38
 
39
+ interface.launch()