File size: 1,579 Bytes
9d4d5a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cbbe67a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import gradio as gr
import os
from pathlib import Path
from ultralytics import YOLO
import cv2
import logging
import numpy as np


def setup_logging():
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s - %(levelname)s - %(message)s')


def process_image(model_path, image):
    try:
        # Wczytanie modelu
        model = YOLO(model_path)
        logging.info(f'Loaded model from: {model_path}')

        # Przetwarzanie obrazu
        logging.info(f'Processing file')
        # Wykrywanie obiektów na obrazie
        results = model(image)

        for result in results:
            # Pobierz obraz wynikowy z zaznaczonymi wykryciami
            result_img = result.plot()

        logging.info("Image processing completed.")
        return result_img
    except Exception as e:
        logging.error(f'Error occurred: {e}')
        return None


def yolo_detection(image):
    model_path = 'model.pt'  # Podaj tutaj ścieżkę do swojego modelu YOLO
    result_image = process_image(model_path, image)
    if result_image is not None:
        return cv2.cvtColor(result_image, cv2.COLOR_BGR2RGB)
    else:
        return None


with gr.Blocks() as demo:
    gr.Markdown("# 👁️ tiny YOLOv8 Open/closed eye detection\nUpload an image and see the detection results.")

    image_input = gr.Image(label="Input Image")
    image_output = gr.Image(label="Detected Objects")

    detect_button = gr.Button("Detect Objects")

    detect_button.click(fn=yolo_detection, inputs=image_input, outputs=image_output)

demo.launch(share=False)