JiwonGigiShin commited on
Commit
0081c7f
Β·
verified Β·
1 Parent(s): 39d2b8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -27
app.py CHANGED
@@ -4,39 +4,41 @@ from transformers import YolosImageProcessor, YolosForObjectDetection, pipeline
4
  from PIL import Image
5
  import requests
6
 
7
- # st.title("Welcome to πŸ‡·πŸ‡Ί Translator App!πŸͺ†")
8
 
9
- # input = st.text_area("Your input here! πŸ‡¬πŸ‡§")
10
 
11
- # pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-ru-en")
12
 
13
- # st.write(pipe(input)[0]['translation_text'])
14
 
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
- )
 
4
  from PIL import Image
5
  import requests
6
 
 
7
 
 
8
 
9
+ st.title("Welcome to πŸ‡·πŸ‡Ί Translator App!πŸͺ†")
10
 
11
+ input = st.text_area("Your input here! πŸ‡¬πŸ‡§")
12
 
13
+ pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-ru-en")
14
 
15
+ st.write(pipe(input)[0]['translation_text'])
 
 
16
 
 
17
 
18
+
19
+ # url = st.text_area("Put your URL here")
20
+ # if url:
21
+ # image = Image.open(requests.get(url, stream=True).raw)
22
+
23
+ # st.image(image)
24
+
25
+ # model = YolosForObjectDetection.from_pretrained('hustvl/yolos-tiny')
26
+ # image_processor = YolosImageProcessor.from_pretrained("hustvl/yolos-tiny")
27
 
28
+ # inputs = image_processor(images=image, return_tensors="pt")
29
+ # outputs = model(**inputs)
30
 
31
+ # # model predicts bounding boxes and corresponding COCO classes
32
+ # logits = outputs.logits
33
+ # bboxes = outputs.pred_boxes
34
+ # st.image(bboxes)
35
+
36
+ # # print results
37
+ # target_sizes = torch.tensor([image.size[::-1]])
38
+ # results = image_processor.post_process_object_detection(outputs, threshold=0.9, target_sizes=target_sizes)[0]
39
+ # for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
40
+ # box = [round(i, 2) for i in box.tolist()]
41
+ # st.write(
42
+ # f"Detected {model.config.id2label[label.item()]} with confidence "
43
+ # f"{round(score.item(), 3)} at location {box}"
44
+ # )