Ermond commited on
Commit
daa0506
1 Parent(s): fbbef9f

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +8 -13
  2. app.py +32 -0
  3. requirements.txt +4 -0
README.md CHANGED
@@ -1,13 +1,8 @@
1
- ---
2
- title: Image Object Detection
3
- emoji: 💻
4
- colorFrom: purple
5
- colorTo: red
6
- sdk: gradio
7
- sdk_version: 4.36.1
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ title: Image Object Detection
2
+ emoji: 🚀
3
+ colorFrom: green
4
+ colorTo: indigo
5
+ sdk: gradio
6
+ sdk_version: 4.28.3
7
+ app_file: app.py
8
+ pinned: false
 
 
 
 
 
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from base64 import b64decode
2
+ from io import BytesIO
3
+
4
+ import gradio as gr
5
+ import spaces
6
+ from PIL import Image
7
+ from transformers import pipeline
8
+
9
+ model = pipeline(
10
+ task="zero-shot-object-detection",
11
+ model="google/owlvit-large-patch14",
12
+ )
13
+
14
+
15
+ @spaces.GPU
16
+ def predict(base64: str, texts: str):
17
+ decoded_img = b64decode(base64)
18
+ image_stream = BytesIO(decoded_img)
19
+ img = Image.open(image_stream)
20
+ predictions = model(img, text_queries=["".join(list(term)).strip() for term in texts.split(",")])
21
+ return predictions
22
+
23
+
24
+ demo = gr.Interface(
25
+ fn=predict,
26
+ inputs=[
27
+ gr.Text(label="Image (B64)"),
28
+ gr.Text(label="Queries", placeholder="A photo of a dog,A photo of a cat")
29
+ ],
30
+ outputs=gr.JSON(label="Predictions"),
31
+ )
32
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ loguru
2
+ torch==2.2.0
3
+ transformers==4.40.1
4
+ pillow==10.3.0