Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,27 +15,28 @@ import requests
|
|
| 15 |
st.title("Imag")
|
| 16 |
|
| 17 |
url = st.text_area("Put your URL here")
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
| 15 |
st.title("Imag")
|
| 16 |
|
| 17 |
url = st.text_area("Put your URL here")
|
| 18 |
+
if url:
|
| 19 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 20 |
+
|
| 21 |
+
st.image(image)
|
| 22 |
+
|
| 23 |
+
model = YolosForObjectDetection.from_pretrained('hustvl/yolos-tiny')
|
| 24 |
+
image_processor = YolosImageProcessor.from_pretrained("hustvl/yolos-tiny")
|
| 25 |
+
|
| 26 |
+
inputs = image_processor(images=image, return_tensors="pt")
|
| 27 |
+
outputs = model(**inputs)
|
| 28 |
+
|
| 29 |
+
# model predicts bounding boxes and corresponding COCO classes
|
| 30 |
+
logits = outputs.logits
|
| 31 |
+
bboxes = outputs.pred_boxes
|
| 32 |
+
st.image(bboxes)
|
| 33 |
+
|
| 34 |
+
# print results
|
| 35 |
+
target_sizes = torch.tensor([image.size[::-1]])
|
| 36 |
+
results = image_processor.post_process_object_detection(outputs, threshold=0.9, target_sizes=target_sizes)[0]
|
| 37 |
+
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
|
| 38 |
+
box = [round(i, 2) for i in box.tolist()]
|
| 39 |
+
st.write(
|
| 40 |
+
f"Detected {model.config.id2label[label.item()]} with confidence "
|
| 41 |
+
f"{round(score.item(), 3)} at location {box}"
|
| 42 |
+
)
|