repo / app.py
nicolaleo's picture
Update app.py
11a889e
raw
history blame
888 Bytes
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)