piky commited on
Commit
998fc2d
·
verified ·
1 Parent(s): 4bf9f20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -1,7 +1,8 @@
 
1
  import requests
 
2
 
3
  import torch
4
- from PIL import Image
5
  from transformers import AutoProcessor, AutoModelForZeroShotObjectDetection
6
 
7
  model_id = "IDEA-Research/grounding-dino-tiny"
@@ -10,11 +11,19 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
10
  processor = AutoProcessor.from_pretrained(model_id)
11
  model = AutoModelForZeroShotObjectDetection.from_pretrained(model_id).to(device)
12
 
13
- image_url = "http://images.cocodataset.org/val2017/000000039769.jpg"
14
- image = Image.open(requests.get(image_url, stream=True).raw)
 
 
 
 
 
 
 
 
15
  # Check for cats and remote controls
16
  # VERY important: text queries need to be lowercased + end with a dot
17
- text = "a cat. a remote control."
18
 
19
  inputs = processor(images=image, text=text, return_tensors="pt").to(device)
20
  with torch.no_grad():
 
1
+ from io import BytesIO
2
  import requests
3
+ from PIL import Image
4
 
5
  import torch
 
6
  from transformers import AutoProcessor, AutoModelForZeroShotObjectDetection
7
 
8
  model_id = "IDEA-Research/grounding-dino-tiny"
 
11
  processor = AutoProcessor.from_pretrained(model_id)
12
  model = AutoModelForZeroShotObjectDetection.from_pretrained(model_id).to(device)
13
 
14
+ image_url = "https://pub-44a464d4394a43d6834ffdc08038cb38.r2.dev/static/img/guess_a_capsule.jpeg"
15
+
16
+ headers = {
17
+ "User-Agent": "Mozilla/5.0"
18
+ }
19
+
20
+ response = requests.get(image_url)
21
+ response.raise_for_status()
22
+
23
+ image = Image.open(BytesIO(response.content)).convert("RGB")
24
  # Check for cats and remote controls
25
  # VERY important: text queries need to be lowercased + end with a dot
26
+ text = "a capsule."
27
 
28
  inputs = processor(images=image, text=text, return_tensors="pt").to(device)
29
  with torch.no_grad():