ascarlettvfx commited on
Commit
2ff1378
1 Parent(s): 660acc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -1,6 +1,11 @@
1
  import gradio as gr
2
  from PIL import Image
3
  import numpy as np
 
 
 
 
 
4
 
5
  def load_image(image):
6
  """ Convert uploaded image to grayscale. """
@@ -33,23 +38,30 @@ def create_normal_map(image):
33
 
34
  return Image.fromarray(normal_map, 'RGB')
35
 
36
- def convert_to_grayscale(image):
37
- """ Convert the normal map to a grayscale image. """
38
- grayscale_image = image.convert('L')
39
- return grayscale_image
 
 
40
 
41
  def interface(image):
42
  normal_map = create_normal_map(image)
43
- grayscale_image = convert_to_grayscale(normal_map)
44
- return normal_map, grayscale_image
 
45
 
46
  # Set up the Gradio interface
47
  iface = gr.Interface(
48
  fn=interface,
49
  inputs=gr.Image(type="pil", label="Upload Image"),
50
- outputs=[gr.Image(type="pil", label="Normal Map"), gr.Image(type="pil", label="Grayscale Image")],
51
- title="Normal Map and Grayscale Generator",
52
- description="Upload an image to generate its normal map and a grayscale version of the normal map. Both images retain the original dimensions."
 
 
 
 
53
  )
54
 
55
  iface.launch()
 
1
  import gradio as gr
2
  from PIL import Image
3
  import numpy as np
4
+ from transformers import AutoModelForImageClassification, AutoFeatureExtractor
5
+
6
+ # Load the Marigold model
7
+ feature_extractor = AutoFeatureExtractor.from_pretrained("prs-eth/marigold-depth-lcm-v1-0")
8
+ model = AutoModelForImageClassification.from_pretrained("prs-eth/marigold-depth-lcm-v1-0")
9
 
10
  def load_image(image):
11
  """ Convert uploaded image to grayscale. """
 
38
 
39
  return Image.fromarray(normal_map, 'RGB')
40
 
41
+ def estimate_depth(image):
42
+ """ Estimate depth using the Marigold model. """
43
+ inputs = feature_extractor(images=image, return_tensors="pt")
44
+ outputs = model(**inputs)
45
+ depth_map = outputs.logits # Adjust if the output tensor is named differently
46
+ return depth_map
47
 
48
  def interface(image):
49
  normal_map = create_normal_map(image)
50
+ grayscale_image = load_image(normal_map)
51
+ depth_map = estimate_depth(image)
52
+ return normal_map, grayscale_image, depth_map
53
 
54
  # Set up the Gradio interface
55
  iface = gr.Interface(
56
  fn=interface,
57
  inputs=gr.Image(type="pil", label="Upload Image"),
58
+ outputs=[
59
+ gr.Image(type="pil", label="Normal Map"),
60
+ gr.Image(type="pil", label="Grayscale Image"),
61
+ gr.Image(type="pil", label="Depth Map") # Adjust the output type if needed
62
+ ],
63
+ title="Normal Map, Grayscale, and Depth Map Generator",
64
+ description="Upload an image to generate its normal map, a grayscale version, and estimate its depth."
65
  )
66
 
67
  iface.launch()