freealise commited on
Commit
0b6c6a0
·
verified ·
1 Parent(s): 72add58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -76,7 +76,7 @@ def findNormals(gray_depth, format):
76
 
77
  load_svg="""
78
  async(img, dpt)=>{
79
- document.getElementById('inimage').outerHTML = '<image id="inimage" crossorigin="anonymous" href="' + img['composite'] + '" x="0" y="0" height="100%" width="100%" style="filter: url(#displacementFilter)"/>';
80
  document.getElementById('feimage').outerHTML = '<feImage id="feimage" crossorigin="anonymous" width="100%" height="100%" x="0" y="0" result="10_MAP" href="' + dpt + '"/>';
81
  }
82
  """
@@ -110,7 +110,8 @@ with gr.Blocks(js=js, css=css) as demo:
110
  input_image = gr.ImageEditor(label="Input Image", layers=True, sources=('upload', 'clipboard'), show_download_button=True, type="numpy", interactive=True, transforms=(None,), eraser=gr.Eraser(), brush=gr.Brush(default_size=1, colors=['black', '#505050', '#a0a0a0', 'white']), elem_id="img-display-input")
111
  with gr.Tab("Depth"):
112
  depth_image_slider = ImageSlider(label="Depth Map with Slider View", elem_id='img-display-output', position=0.5)
113
- gray_depth_file = gr.File(label="Grayscale depth map", elem_id="download",)
 
114
  submit = gr.Button(value="Compute Depth")
115
  svg = gr.HTML("""
116
  <svg id='svg'
@@ -128,7 +129,7 @@ with gr.Blocks(js=js, css=css) as demo:
128
  </svg>
129
  """)
130
  scale = gr.Slider(label="Scale", minimum="-128", maximum="128", value="0", step="1", elem_id="scale")
131
- gray_depth_file.change(fn=None, inputs=[input_image, gray_depth_file], outputs=None, js=load_svg)
132
  with gr.Tab("Normals"):
133
  normals_out = gr.Image(label="Normal map", interactive=False)
134
  format_normals = gr.Radio(choices=["directx", "opengl"])
@@ -158,14 +159,18 @@ with gr.Blocks(js=js, css=css) as demo:
158
  tmp_gray_depth = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
159
  gray_depth.save(tmp_gray_depth.name)
160
 
161
- return [(original_image, colored_depth), tmp_gray_depth.name, tmp_raw_depth.name]
 
 
162
 
163
- submit.click(on_submit, inputs=[input_image], outputs=[depth_image_slider, gray_depth_file, raw_file])
 
 
164
 
165
  example_files = os.listdir('assets/drawn_examples')
166
  example_files.sort()
167
  example_files = [os.path.join('assets/drawn_examples', filename) for filename in example_files]
168
- examples = gr.Examples(examples=example_files, inputs=[input_image], outputs=[depth_image_slider, gray_depth_file, raw_file], fn=on_submit)
169
 
170
 
171
  if __name__ == '__main__':
 
76
 
77
  load_svg="""
78
  async(img, dpt)=>{
79
+ document.getElementById('inimage').outerHTML = '<image id="inimage" crossorigin="anonymous" href="' + img + '" x="0" y="0" height="100%" width="100%" style="filter: url(#displacementFilter)"/>';
80
  document.getElementById('feimage').outerHTML = '<feImage id="feimage" crossorigin="anonymous" width="100%" height="100%" x="0" y="0" result="10_MAP" href="' + dpt + '"/>';
81
  }
82
  """
 
110
  input_image = gr.ImageEditor(label="Input Image", layers=True, sources=('upload', 'clipboard'), show_download_button=True, type="numpy", interactive=True, transforms=(None,), eraser=gr.Eraser(), brush=gr.Brush(default_size=1, colors=['black', '#505050', '#a0a0a0', 'white']), elem_id="img-display-input")
111
  with gr.Tab("Depth"):
112
  depth_image_slider = ImageSlider(label="Depth Map with Slider View", elem_id='img-display-output', position=0.5)
113
+ orig_image_file = gr.File(label="Original image", elem_id="original")
114
+ gray_depth_file = gr.File(label="Grayscale depth map", elem_id="download")
115
  submit = gr.Button(value="Compute Depth")
116
  svg = gr.HTML("""
117
  <svg id='svg'
 
129
  </svg>
130
  """)
131
  scale = gr.Slider(label="Scale", minimum="-128", maximum="128", value="0", step="1", elem_id="scale")
132
+ gray_depth_file.change(fn=None, inputs=[orig_image_file, gray_depth_file], outputs=None, js=load_svg)
133
  with gr.Tab("Normals"):
134
  normals_out = gr.Image(label="Normal map", interactive=False)
135
  format_normals = gr.Radio(choices=["directx", "opengl"])
 
159
  tmp_gray_depth = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
160
  gray_depth.save(tmp_gray_depth.name)
161
 
162
+ orig_image = Image.fromarray(image)
163
+ tmp_orig_image = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
164
+ orig_image.save(tmp_orig_image.name)
165
 
166
+ return [(original_image, colored_depth), tmp_orig_image.name, tmp_gray_depth.name, tmp_raw_depth.name]
167
+
168
+ submit.click(on_submit, inputs=[input_image], outputs=[depth_image_slider, orig_image_file, gray_depth_file, raw_file])
169
 
170
  example_files = os.listdir('assets/drawn_examples')
171
  example_files.sort()
172
  example_files = [os.path.join('assets/drawn_examples', filename) for filename in example_files]
173
+ examples = gr.Examples(examples=example_files, inputs=[input_image], outputs=[depth_image_slider, orig_image_file, gray_depth_file, raw_file], fn=on_submit)
174
 
175
 
176
  if __name__ == '__main__':