File size: 888 Bytes
611d23b
 
 
e682a6d
 
 
 
 
 
 
 
 
 
 
 
 
11a889e
e682a6d
11a889e
 
 
 
e682a6d
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import streamlit as st
from transformers import pipeline

#pipe=pipeline("sentiment-analysis")
#text=st.text_area("enter the text:")
##x = st.slider('Select a value')
##st.write(x, 'squared is', x * x)

#if text:
  #out=pipe(text)
  #st.json(out)
  
from transformers import DetrFeatureExtractor, DetrForObjectDetection
from PIL import Image
import requests


url = 'http://images.cocodataset.org/val2017/000000039769.jpg'


st.write(url)

image = Image.open(requests.get(url, stream=True).raw)

feature_extractor = DetrFeatureExtractor.from_pretrained('facebook/detr-resnet-50')
model = DetrForObjectDetection.from_pretrained('facebook/detr-resnet-50')

inputs = feature_extractor(images=image, return_tensors="pt")
outputs = model(**inputs)

# model predicts bounding boxes and corresponding COCO classes
logits = outputs.logits
bboxes = outputs.pred_boxes

if bboxes:
  st.json(bboxes)