cv-yolo commited on
Commit
77c9c0f
·
1 Parent(s): 67c8d26

initial commit

Browse files
Files changed (3) hide show
  1. .gitignore +7 -0
  2. app.py +58 -0
  3. requirements.txt +50 -0
.gitignore ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ flagged/
2
+ *.pt
3
+ *.png
4
+ *.jpg
5
+ *.mp4
6
+ *.mkv
7
+ gradio_cached_examples/
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from PIL import Image
4
+ from ultralytics import YOLO
5
+ import requests
6
+ import os
7
+
8
+ model = YOLO('best.pt')
9
+
10
+ def predict(image):
11
+ try:
12
+ image = np.array(image)
13
+ results = model(image)
14
+ result_image = results[0].plot()
15
+ return Image.fromarray(result_image)
16
+ except Exception as e:
17
+ print(f"Error during prediction: {e}")
18
+ return "Error"
19
+
20
+ def load_image_from_gallery(images, index):
21
+ if images and 0 <= index < len(images):
22
+ image = images[index]
23
+ if isinstance(image, tuple):
24
+ image = image[0]
25
+ return image
26
+ return None
27
+
28
+ def gallery_click_event(images, evt: gr.SelectData):
29
+ index = evt.index
30
+ selected_img = load_image_from_gallery(images, index)
31
+ return selected_img
32
+
33
+ with gr.Blocks() as demo:
34
+ with gr.Row():
35
+ with gr.Column():
36
+ selected_image = gr.Image(label="Selected Image from Gallery", type="pil")
37
+
38
+ with gr.Column():
39
+ image_gallery = gr.Gallery(label="Image Gallery", elem_id="gallery", type="pil")
40
+
41
+ with gr.Column():
42
+ result_image = gr.Image(label="Result Image", type="pil")
43
+
44
+ # Update selected image based on gallery click
45
+ image_gallery.select(
46
+ fn=gallery_click_event,
47
+ inputs=image_gallery,
48
+ outputs=selected_image
49
+ )
50
+
51
+ # Predict and display the result image when the selected image changes
52
+ selected_image.change(
53
+ fn=predict,
54
+ inputs=selected_image,
55
+ outputs=result_image
56
+ )
57
+
58
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # YOLOv5 requirements
2
+ # Usage: pip install -r requirements.txt
3
+
4
+ # Base ------------------------------------------------------------------------
5
+ gitpython>=3.1.30
6
+ matplotlib>=3.3
7
+ numpy>=1.23.5
8
+ opencv-python>=4.1.1
9
+ pillow>=10.3.0
10
+ psutil # system resources
11
+ PyYAML>=5.3.1
12
+ requests>=2.32.0
13
+ scipy>=1.4.1
14
+ thop>=0.1.1 # FLOPs computation
15
+ torch>=1.8.0 # see https://pytorch.org/get-started/locally (recommended)
16
+ torchvision>=0.9.0
17
+ tqdm>=4.64.0
18
+ ultralytics>=8.0.232
19
+ # protobuf<=3.20.1 # https://github.com/ultralytics/yolov5/issues/8012
20
+
21
+ # Logging ---------------------------------------------------------------------
22
+ # tensorboard>=2.4.1
23
+ # clearml>=1.2.0
24
+ # comet
25
+
26
+ # Plotting --------------------------------------------------------------------
27
+ pandas>=1.1.4
28
+ seaborn>=0.11.0
29
+
30
+ # Export ----------------------------------------------------------------------
31
+ # coremltools>=6.0 # CoreML export
32
+ # onnx>=1.10.0 # ONNX export
33
+ # onnx-simplifier>=0.4.1 # ONNX simplifier
34
+ # nvidia-pyindex # TensorRT export
35
+ # nvidia-tensorrt # TensorRT export
36
+ # scikit-learn<=1.1.2 # CoreML quantization
37
+ # tensorflow>=2.4.0,<=2.13.1 # TF exports (-cpu, -aarch64, -macos)
38
+ # tensorflowjs>=3.9.0 # TF.js export
39
+ # openvino-dev>=2023.0 # OpenVINO export
40
+
41
+ # Deploy ----------------------------------------------------------------------
42
+ setuptools>=65.5.1 # Snyk vulnerability fix
43
+ # tritonclient[all]~=2.24.0
44
+
45
+ # Extras ----------------------------------------------------------------------
46
+ # ipython # interactive notebook
47
+ # mss # screenshots
48
+ # albumentations>=1.0.3
49
+ # pycocotools>=2.0.6 # COCO mAP
50
+ wheel>=0.38.0 # not directly required, pinned by Snyk to avoid a vulnerability