sea45 commited on
Commit
5a34e37
·
verified ·
1 Parent(s): c800f17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -27
app.py CHANGED
@@ -1,40 +1,23 @@
1
  import gradio as gr
2
 
3
- # import torch
4
- import numpy as np
5
  from PIL import Image
6
  import requests
7
- from transformers import AutoImageProcessor, AutoModelForDepthEstimation
8
 
9
  def greet(name):
 
 
 
10
 
 
 
11
 
12
-
13
- url = "http://images.cocodataset.org/val2017/000000039769.jpg"
14
  image = Image.open(requests.get(url, stream=True).raw)
15
 
16
- image_processor = AutoImageProcessor.from_pretrained("LiheYoung/depth-anything-small-hf")
17
- model = AutoModelForDepthEstimation.from_pretrained("LiheYoung/depth-anything-small-hf")
18
-
19
- # prepare image for the model
20
- inputs = image_processor(images=image, return_tensors="pt")
21
-
22
- with torch.no_grad():
23
- outputs = model(**inputs)
24
- predicted_depth = outputs.predicted_depth
25
-
26
- # interpolate to original size
27
- prediction = torch.nn.functional.interpolate(
28
- predicted_depth.unsqueeze(1),
29
- size=image.size[::-1],
30
- mode="bicubic",
31
- align_corners=False,
32
- )
33
-
34
- # visualize the prediction
35
- output = prediction.squeeze().cpu().numpy()
36
- formatted = (output * 255 / np.max(output)).astype("uint8")
37
- depth = Image.fromarray(formatted)
38
  return name+": " + depth
39
 
40
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
 
1
  import gradio as gr
2
 
3
+ from transformers import pipeline
 
4
  from PIL import Image
5
  import requests
 
6
 
7
  def greet(name):
8
+ from transformers import pipeline
9
+ from PIL import Image
10
+ import requests
11
 
12
+ # load pipe
13
+ pipe = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-small-hf")
14
 
15
+ # load image
16
+ url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
17
  image = Image.open(requests.get(url, stream=True).raw)
18
 
19
+ # inference
20
+ depth = pipe(image)["depth"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  return name+": " + depth
22
 
23
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")