iamsuman commited on
Commit
c05d727
·
1 Parent(s): 81cd359

add application file

Browse files
.gitignore ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ flagged/
2
+ *.pt
3
+ *.png
4
+ *.jpg
5
+ *.mp4
6
+ *.mkv
7
+ gradio_cached_examples/
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: Ripe And Unripe Tomatoes Detection
3
- emoji:
4
  colorFrom: green
5
  colorTo: yellow
6
  sdk: gradio
 
1
  ---
2
  title: Ripe And Unripe Tomatoes Detection
3
+ emoji: 🍅
4
  colorFrom: green
5
  colorTo: yellow
6
  sdk: gradio
app.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import requests
4
+ import os
5
+
6
+ from ultralytics import YOLO
7
+
8
+ file_urls = [
9
+ 'https://www.dropbox.com/scl/fi/appak1aswfncu155kn45p/unriped_tomato_1.jpeg?rlkey=qe9wedic2dz70t5625z9bf2uf&st=vqk413d0&raw=1',
10
+ 'https://www.dropbox.com/scl/fi/t3uctkym9g16kyre7xhkt/riped_tomato_94.jpeg?rlkey=fwrqlbugeozz74wlzwfu0p4al&st=en5b340w&raw=1',
11
+ ]
12
+
13
+ def download_file(url, save_name):
14
+ url = url
15
+ if not os.path.exists(save_name):
16
+ file = requests.get(url)
17
+ open(save_name, 'wb').write(file.content)
18
+
19
+ for i, url in enumerate(file_urls):
20
+ if 'mp4' in file_urls[i]:
21
+ download_file(
22
+ file_urls[i],
23
+ f"video.mp4"
24
+ )
25
+ else:
26
+ download_file(
27
+ file_urls[i],
28
+ f"image_{i}.jpg"
29
+ )
30
+
31
+ model = YOLO('best.pt')
32
+ path = [['image_0.jpg'], ['image_1.jpg']]
33
+ video_path = [['video.mp4']]
34
+
35
+ def show_preds_image(image_path):
36
+ image = cv2.imread(image_path)
37
+ outputs = model.predict(source=image_path)
38
+ results = outputs[0].cpu().numpy()
39
+ for i, det in enumerate(results.boxes.xyxy):
40
+ cv2.rectangle(
41
+ image,
42
+ (int(det[0]), int(det[1])),
43
+ (int(det[2]), int(det[3])),
44
+ color=(0, 0, 255),
45
+ thickness=2,
46
+ lineType=cv2.LINE_AA
47
+ )
48
+ return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
49
+
50
+ inputs_image = [
51
+ gr.components.Image(type="filepath", label="Input Image"),
52
+ ]
53
+ outputs_image = [
54
+ gr.components.Image(type="numpy", label="Output Image"),
55
+ ]
56
+ interface_image = gr.Interface(
57
+ fn=show_preds_image,
58
+ inputs=inputs_image,
59
+ outputs=outputs_image,
60
+ title="Ripe And Unripe Tomatoes Detection",
61
+ examples=path,
62
+ cache_examples=False,
63
+ )
64
+
65
+ def show_preds_video(video_path):
66
+ cap = cv2.VideoCapture(video_path)
67
+ while(cap.isOpened()):
68
+ ret, frame = cap.read()
69
+ if ret:
70
+ frame_copy = frame.copy()
71
+ outputs = model.predict(source=frame)
72
+ results = outputs[0].cpu().numpy()
73
+ for i, det in enumerate(results.boxes.xyxy):
74
+ cv2.rectangle(
75
+ frame_copy,
76
+ (int(det[0]), int(det[1])),
77
+ (int(det[2]), int(det[3])),
78
+ color=(0, 0, 255),
79
+ thickness=2,
80
+ lineType=cv2.LINE_AA
81
+ )
82
+ yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
83
+
84
+ inputs_video = [
85
+ gr.components.Video(type="filepath", label="Input Video"),
86
+
87
+ ]
88
+ outputs_video = [
89
+ gr.components.Image(type="numpy", label="Output Image"),
90
+ ]
91
+ interface_video = gr.Interface(
92
+ fn=show_preds_video,
93
+ inputs=inputs_video,
94
+ outputs=outputs_video,
95
+ title="Ripe And Unripe Tomatoes Detection",
96
+ examples=video_path,
97
+ cache_examples=False,
98
+ )
99
+
100
+ gr.TabbedInterface(
101
+ [interface_image, interface_video],
102
+ tab_names=['Image inference', 'Video inference']
103
+ ).queue().launch()
requirements.txt ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Ultralytics requirements
2
+ # Usage: pip install -r requirements.txt
3
+
4
+ # Base ----------------------------------------
5
+ hydra-core>=1.2.0
6
+ matplotlib>=3.2.2
7
+ numpy>=1.18.5
8
+ opencv-python>=4.1.1
9
+ Pillow>=7.1.2
10
+ PyYAML>=5.3.1
11
+ requests>=2.23.0
12
+ scipy>=1.4.1
13
+ torch>=1.7.0
14
+ torchvision>=0.8.1
15
+ tqdm>=4.64.0
16
+ ultralytics
17
+
18
+ # Logging -------------------------------------
19
+ tensorboard>=2.4.1
20
+ # clearml
21
+ # comet
22
+
23
+ # Plotting ------------------------------------
24
+ pandas>=1.1.4
25
+ seaborn>=0.11.0
26
+
27
+ # Export --------------------------------------
28
+ # coremltools>=6.0 # CoreML export
29
+ # onnx>=1.12.0 # ONNX export
30
+ # onnx-simplifier>=0.4.1 # ONNX simplifier
31
+ # nvidia-pyindex # TensorRT export
32
+ # nvidia-tensorrt # TensorRT export
33
+ # scikit-learn==0.19.2 # CoreML quantization
34
+ # tensorflow>=2.4.1 # TF exports (-cpu, -aarch64, -macos)
35
+ # tensorflowjs>=3.9.0 # TF.js export
36
+ # openvino-dev # OpenVINO export
37
+
38
+ # Extras --------------------------------------
39
+ ipython # interactive notebook
40
+ psutil # system utilization
41
+ thop>=0.1.1 # FLOPs computation
42
+ # albumentations>=1.0.3
43
+ # pycocotools>=2.0.6 # COCO mAP
44
+ # roboflow
45
+
46
+ # HUB -----------------------------------------
47
+ GitPython>=3.1.24
sample_images/riped_tomato_93.jpeg ADDED
sample_images/riped_tomato_94.jpeg ADDED
sample_images/unriped_tomato_1.jpeg ADDED
sample_images/unriped_tomato_18.jpeg ADDED
sample_images/unriped_tomato_7.jpeg ADDED