MichalMlodawski commited on
Commit
9d4d5a3
·
verified ·
1 Parent(s): 9e2e723

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from pathlib import Path
4
+ from ultralytics import YOLO
5
+ import cv2
6
+ import logging
7
+ import numpy as np
8
+
9
+
10
+ def setup_logging():
11
+ logging.basicConfig(level=logging.INFO,
12
+ format='%(asctime)s - %(levelname)s - %(message)s')
13
+
14
+
15
+ def process_image(model_path, image):
16
+ try:
17
+ # Wczytanie modelu
18
+ model = YOLO(model_path)
19
+ logging.info(f'Loaded model from: {model_path}')
20
+
21
+ # Przetwarzanie obrazu
22
+ logging.info(f'Processing file')
23
+ # Wykrywanie obiektów na obrazie
24
+ results = model(image)
25
+
26
+ for result in results:
27
+ # Pobierz obraz wynikowy z zaznaczonymi wykryciami
28
+ result_img = result.plot()
29
+
30
+ logging.info("Image processing completed.")
31
+ return result_img
32
+ except Exception as e:
33
+ logging.error(f'Error occurred: {e}')
34
+ return None
35
+
36
+
37
+ def yolo_detection(image):
38
+ model_path = 'model.pt' # Podaj tutaj ścieżkę do swojego modelu YOLO
39
+ result_image = process_image(model_path, image)
40
+ if result_image is not None:
41
+ return cv2.cvtColor(result_image, cv2.COLOR_BGR2RGB)
42
+ else:
43
+ return None
44
+
45
+
46
+ with gr.Blocks() as demo:
47
+ gr.Markdown("# 👁️ tiny YOLOv8 Open/closed eye detection\nUpload an image and see the detection results.")
48
+
49
+ image_input = gr.Image(label="Input Image")
50
+ image_output = gr.Image(label="Detected Objects")
51
+
52
+ detect_button = gr.Button("Detect Objects")
53
+
54
+ detect_button.click(fn=yolo_detection, inputs=image_input, outputs=image_output)
55
+
56
+ demo.launch(share=True)