JiwonGigiShin commited on
Commit
39d2b8c
·
verified ·
1 Parent(s): 0d69898

Update app.py

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