bharathj16 commited on
Commit
7ec4116
1 Parent(s): 0530e27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -13
app.py CHANGED
@@ -1,20 +1,31 @@
1
- import streamlit as st
2
- from transformers import pipeline
 
3
  from PIL import Image
 
4
 
5
- pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
 
6
 
7
- st.title("Hot Dog? Or Not?")
 
8
 
9
- file_name = st.file_uploader("Upload a hot dog candidate image")
 
10
 
11
- if file_name is not None:
12
- col1, col2 = st.columns(2)
 
13
 
14
- image = Image.open(file_name)
15
- col1.image(image, use_column_width=True)
16
- predictions = pipeline(image)
 
 
 
 
17
 
18
- col2.header("Probabilities")
19
- for p in predictions:
20
- col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
 
 
1
+ from transformers import DPTImageProcessor, DPTForDepthEstimation
2
+ import torch
3
+ import numpy as np
4
  from PIL import Image
5
+ import requests
6
 
7
+ url = "http://images.cocodataset.org/val2017/000000039769.jpg"
8
+ image = Image.open(requests.get(url, stream=True).raw)
9
 
10
+ processor = DPTImageProcessor.from_pretrained("Intel/dpt-large")
11
+ model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
12
 
13
+ # prepare image for the model
14
+ inputs = processor(images=image, return_tensors="pt")
15
 
16
+ with torch.no_grad():
17
+ outputs = model(**inputs)
18
+ predicted_depth = outputs.predicted_depth
19
 
20
+ # interpolate to original size
21
+ prediction = torch.nn.functional.interpolate(
22
+ predicted_depth.unsqueeze(1),
23
+ size=image.size[::-1],
24
+ mode="bicubic",
25
+ align_corners=False,
26
+ )
27
 
28
+ # visualize the prediction
29
+ output = prediction.squeeze().cpu().numpy()
30
+ formatted = (output * 255 / np.max(output)).astype("uint8")
31
+ depth = Image.fromarray(formatted)