Spaces:
Runtime error
Runtime error
neverix
commited on
Commit
·
1d37acd
0
Parent(s):
Initial commit?
Browse files- .gitignore +2 -0
- app.py +43 -0
- requirements.txt +4 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.idea/
|
2 |
+
**/__pycache__/
|
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from PIL import Image
|
2 |
+
import gradio as gr
|
3 |
+
import numpy as np
|
4 |
+
import torch
|
5 |
+
|
6 |
+
|
7 |
+
class MidasDepth(object):
|
8 |
+
def __init__(self, model_type="DPT_Large", device=torch.device("cuda" if torch.cuda.is_available() else "cpu")):
|
9 |
+
self.device = device
|
10 |
+
self.midas = torch.hub.load("intel-isl/MiDaS", model_type).to(self.device).eval().requires_grad_(False)
|
11 |
+
self.transform = torch.hub.load("intel-isl/MiDaS", "transforms").dpt_transform
|
12 |
+
|
13 |
+
def get_depth(self, image):
|
14 |
+
if not isinstance(image, np.ndarray):
|
15 |
+
image = np.asarray(image)
|
16 |
+
if (image > 1).any():
|
17 |
+
image /= 255.
|
18 |
+
with torch.inference_mode():
|
19 |
+
batch = self.transform(image[..., :3]).to(self.device)
|
20 |
+
prediction = self.midas(batch)
|
21 |
+
prediction = torch.nn.functional.interpolate(
|
22 |
+
prediction.unsqueeze(1),
|
23 |
+
size=image.shape[:2],
|
24 |
+
mode="bicubic",
|
25 |
+
align_corners=False,
|
26 |
+
).squeeze()
|
27 |
+
return prediction.detach().cpu().numpy()
|
28 |
+
|
29 |
+
|
30 |
+
def main():
|
31 |
+
midas = MidasDepth()
|
32 |
+
interface = gr.Interface(inputs=[
|
33 |
+
gr.inputs.Image(),
|
34 |
+
gr.inputs.Text()
|
35 |
+
], outputs=[
|
36 |
+
gr.outputs.Image(),
|
37 |
+
gr.outputs.Video()
|
38 |
+
], title="DALL·E 6D", description="Lift DALL·E 2 (or any other model) into 3D!")
|
39 |
+
interface.launch()
|
40 |
+
|
41 |
+
|
42 |
+
if __name__ == '__main__':
|
43 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pytorch3d==0.6.2
|
2 |
+
transformers==4.10.3
|
3 |
+
torch==1.11.0
|
4 |
+
torchvision==0.12.0
|