berak commited on
Commit
cf05c5d
·
1 Parent(s): 74872a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -0
app.py CHANGED
@@ -28,7 +28,20 @@ a = np.ones((100,100,3),np.uint8)
28
  a[:,:,0]=255
29
  st.image(a)
30
 
 
 
 
 
 
 
 
 
 
 
31
 
 
 
 
32
  from transformers import SegformerFeatureExtractor, SegformerForSemanticSegmentation
33
  from PIL import Image
34
  import requests
@@ -43,3 +56,4 @@ inputs = feature_extractor(images=image, return_tensors="pt")
43
  outputs = model(**inputs)
44
  logits = outputs.logits # shape (batch_size, num_labels, height/4, width/4)
45
  st.write(logits.shape)
 
 
28
  a[:,:,0]=255
29
  st.image(a)
30
 
31
+ import requests
32
+
33
+ API_URL = "https://api-inference.huggingface.co/models/nvidia/segformer-b5-finetuned-ade-640-640"
34
+ headers = {"Authorization": "Bearer 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"}
35
+
36
+ def query(filename):
37
+ with open(filename, "rb") as f:
38
+ data = f.read()
39
+ response = requests.request("POST", API_URL, headers=headers, data=data)
40
+ return json.loads(response.content.decode("utf-8"))
41
 
42
+ output = query("cats.jpg")
43
+ st.write(output.shape)
44
+ """
45
  from transformers import SegformerFeatureExtractor, SegformerForSemanticSegmentation
46
  from PIL import Image
47
  import requests
 
56
  outputs = model(**inputs)
57
  logits = outputs.logits # shape (batch_size, num_labels, height/4, width/4)
58
  st.write(logits.shape)
59
+ """