Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,24 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
4 |
from ultralytics import YOLO
|
5 |
|
|
|
6 |
model = YOLO('best.pt')
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def predict(image):
|
9 |
try:
|
10 |
image = np.array(image)
|
@@ -31,6 +45,9 @@ def gallery_click_event(images, evt: gr.SelectData):
|
|
31 |
def clear_image():
|
32 |
return None
|
33 |
|
|
|
|
|
|
|
34 |
with gr.Blocks(css=".container { background-color: white; }") as demo:
|
35 |
with gr.Row():
|
36 |
with gr.Column():
|
@@ -38,7 +55,7 @@ with gr.Blocks(css=".container { background-color: white; }") as demo:
|
|
38 |
clear_button = gr.Button("Clear")
|
39 |
|
40 |
with gr.Column():
|
41 |
-
image_gallery = gr.Gallery(label="Image Gallery", elem_id="gallery", type="pil")
|
42 |
|
43 |
with gr.Column():
|
44 |
result_image = gr.Image(label="Result Image", type="pil")
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
from PIL import Image
|
5 |
from ultralytics import YOLO
|
6 |
|
7 |
+
# Load the model
|
8 |
model = YOLO('best.pt')
|
9 |
|
10 |
+
# Path to the photos folder
|
11 |
+
photos_folder = "Photos"
|
12 |
+
|
13 |
+
def load_images_from_folder(folder):
|
14 |
+
images = []
|
15 |
+
for filename in os.listdir(folder):
|
16 |
+
if filename.lower().endswith(('.png', '.jpg', '.jpeg')):
|
17 |
+
img_path = os.path.join(folder, filename)
|
18 |
+
img = Image.open(img_path)
|
19 |
+
images.append((img, filename))
|
20 |
+
return images
|
21 |
+
|
22 |
def predict(image):
|
23 |
try:
|
24 |
image = np.array(image)
|
|
|
45 |
def clear_image():
|
46 |
return None
|
47 |
|
48 |
+
# Load images at the start
|
49 |
+
images = load_images_from_folder(photos_folder)
|
50 |
+
|
51 |
with gr.Blocks(css=".container { background-color: white; }") as demo:
|
52 |
with gr.Row():
|
53 |
with gr.Column():
|
|
|
55 |
clear_button = gr.Button("Clear")
|
56 |
|
57 |
with gr.Column():
|
58 |
+
image_gallery = gr.Gallery(label="Image Gallery", elem_id="gallery", type="pil", value=[img for img, _ in images])
|
59 |
|
60 |
with gr.Column():
|
61 |
result_image = gr.Image(label="Result Image", type="pil")
|