Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
| 37 |
-
"""
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
| 40 |
|
| 41 |
def interface(image):
|
| 42 |
normal_map = create_normal_map(image)
|
| 43 |
-
grayscale_image =
|
| 44 |
-
|
|
|
|
| 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=[
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|