blair-johnson commited on
Commit
63d743d
·
verified ·
1 Parent(s): 8990784

HEIC support

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -7,6 +7,8 @@ from transformers import AutoProcessor, AutoModelForDepthEstimation
7
  import tempfile
8
  from stl import mesh
9
  from sklearn.decomposition import PCA
 
 
10
 
11
  MAX_RESOLUTION = 1.5e6
12
  MODEL_ID = "depth-anything/Depth-Anything-V2-Large-hf"
@@ -16,7 +18,7 @@ model = AutoModelForDepthEstimation.from_pretrained(MODEL_ID).to(device)
16
  print("Model loaded successfully.")
17
 
18
  def create_3d_model(
19
- input_image: np.ndarray,
20
  texture_strength: float,
21
  max_z: float,
22
  min_z: float,
@@ -25,9 +27,15 @@ def create_3d_model(
25
  depth_map_smoothing: int,
26
  texture_smoothing: int
27
  ):
28
- if input_image is None: raise gr.Error("Please upload an image.")
29
  if max_z <= min_z: raise gr.Error("Max Z-height must be greater than Min Z-height.")
30
 
 
 
 
 
 
 
31
  # resize large images
32
  h, w, _ = input_image.shape
33
  if h * w > MAX_RESOLUTION:
@@ -122,7 +130,7 @@ with gr.Blocks(theme='base') as demo:
122
  gr.Markdown("# Image to 3D Relief Generator")
123
  with gr.Row():
124
  with gr.Column(scale=1):
125
- input_image = gr.Image(type="numpy", label="Upload Image")
126
  gr.Markdown("### Model Parameters")
127
  texture_strength = gr.Slider(minimum=0.0, maximum=1.0, value=0.1, step=0.001, label="Brightness Texture Strength")
128
  depth_map_smoothing = gr.Slider(minimum=0, maximum=51, value=0, step=1, label="Depth Map Smoothing", info="Smooths the base geometry. 0 = none.")
@@ -150,4 +158,4 @@ with gr.Blocks(theme='base') as demo:
150
  )
151
 
152
  if __name__ == "__main__":
153
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
7
  import tempfile
8
  from stl import mesh
9
  from sklearn.decomposition import PCA
10
+ import pillow_heif
11
+ pillow_heif.register_heif_opener()
12
 
13
  MAX_RESOLUTION = 1.5e6
14
  MODEL_ID = "depth-anything/Depth-Anything-V2-Large-hf"
 
18
  print("Model loaded successfully.")
19
 
20
  def create_3d_model(
21
+ input_filepath: str,
22
  texture_strength: float,
23
  max_z: float,
24
  min_z: float,
 
27
  depth_map_smoothing: int,
28
  texture_smoothing: int
29
  ):
30
+ if input_filepath is None: raise gr.Error("Please upload an image.")
31
  if max_z <= min_z: raise gr.Error("Max Z-height must be greater than Min Z-height.")
32
 
33
+ try:
34
+ image_pil = Image.open(input_filepath)
35
+ input_image = np.array(image_pil.convert("RGB"))
36
+ except Exception as e:
37
+ raise gr.Error(f"Could not open image file. Error: {e}")
38
+
39
  # resize large images
40
  h, w, _ = input_image.shape
41
  if h * w > MAX_RESOLUTION:
 
130
  gr.Markdown("# Image to 3D Relief Generator")
131
  with gr.Row():
132
  with gr.Column(scale=1):
133
+ input_image = gr.Image(type="filepath", label="Upload Image")
134
  gr.Markdown("### Model Parameters")
135
  texture_strength = gr.Slider(minimum=0.0, maximum=1.0, value=0.1, step=0.001, label="Brightness Texture Strength")
136
  depth_map_smoothing = gr.Slider(minimum=0, maximum=51, value=0, step=1, label="Depth Map Smoothing", info="Smooths the base geometry. 0 = none.")
 
158
  )
159
 
160
  if __name__ == "__main__":
161
+ demo.launch(server_name="0.0.0.0", server_port=7860)