SkalskiP commited on
Commit
f590b07
1 Parent(s): 67f0f0b

test of the first version of the code - zero-shot detection only

Browse files
Files changed (4) hide show
  1. .gitignore +2 -0
  2. README.md +3 -3
  3. app.py +59 -0
  4. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ venv/
2
+ .idea/
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: YOLO World
3
- emoji: 📚
4
- colorFrom: yellow
5
- colorTo: purple
6
  sdk: gradio
7
  sdk_version: 4.19.0
8
  app_file: app.py
 
1
  ---
2
  title: YOLO World
3
+ emoji: 🔥
4
+ colorFrom: purple
5
+ colorTo: green
6
  sdk: gradio
7
  sdk_version: 4.19.0
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List
2
+
3
+ import gradio as gr
4
+ import numpy as np
5
+ import supervision as sv
6
+ from inference.models import YOLOWorld
7
+
8
+ MARKDOWN = """
9
+ # YOLO-World 🌎
10
+
11
+ Powered by Roboflow [Inference](https://github.com/roboflow/inference) and [Supervision](https://github.com/roboflow/supervision).
12
+ """
13
+
14
+ MODEL = YOLOWorld(model_id="yolo_world/l")
15
+ BOUNDING_BOX_ANNOTATOR = sv.BoundingBoxAnnotator()
16
+ LABEL_ANNOTATOR = sv.LabelAnnotator(text_color=sv.Color.BLACK)
17
+
18
+
19
+ def process_categories(categories: str) -> List[str]:
20
+ return [category.strip() for category in categories.split(',')]
21
+
22
+
23
+ def process_image(input_image: np.ndarray, categories: str) -> np.ndarray:
24
+ categories = process_categories(categories)
25
+ MODEL.set_classes(categories)
26
+ results = MODEL.infer(input_image, confidence=0.003)
27
+ detections = sv.Detections.from_inference(results).with_nms(0.1)
28
+ output_image = input_image.copy()
29
+ output_image = BOUNDING_BOX_ANNOTATOR.annotate(output_image, detections)
30
+ output_image = LABEL_ANNOTATOR.annotate(output_image, detections)
31
+ return output_image
32
+
33
+
34
+ with gr.Blocks() as demo:
35
+ gr.Markdown(MARKDOWN)
36
+ with gr.Row():
37
+ input_image_component = gr.Image(
38
+ type='numpy',
39
+ label='Input Image'
40
+ )
41
+ output_image_component = gr.Image(
42
+ type='numpy',
43
+ label='Output Image'
44
+ )
45
+ with gr.Row():
46
+ categories_text_component = gr.Textbox(
47
+ label='Categories',
48
+ placeholder='comma separated list of categories',
49
+ scale=5
50
+ )
51
+ submit_button_component = gr.Button('Submit', scale=1)
52
+
53
+ submit_button_component.click(
54
+ fn=process_image,
55
+ inputs=[input_image_component, categories_text_component],
56
+ outputs=output_image_component
57
+ )
58
+
59
+ demo.launch(debug=False, show_error=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ inference-gpu[yolo-world]==0.9.12
2
+ supervision==0.19.0rc3
3
+ gradio==4.19.0