File size: 1,182 Bytes
230fbb8
78117b4
 
230fbb8
78117b4
230fbb8
10183ac
230fbb8
 
 
 
 
 
087eb84
230fbb8
 
 
 
 
 
b489f83
230fbb8
 
 
 
3c41e97
230fbb8
 
 
27cf630
230fbb8
 
 
10183ac
230fbb8
f1c5a5b
230fbb8
78117b4
35e349f
230fbb8
 
 
 
 
 
 
 
 
 
 
acb5516
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
import gradio as gr
from PIL import Image
import numpy as np
from ultralytics import YOLO
import os

def handle_classify(image=None):
    """This function performs YOLOv8 object detection on the given image.

    Args:
        image (gr.inputs.Image, optional): Input image to detect objects on. Defaults to None.
    """

    model_path = "racistv4.pt"
    model = YOLO(model_path)

    results = model(image)
    
    result = results[0]
    
    top5 = [[result.names[class_index], str(round(result.probs.top5conf.tolist()[rank], 4)*100)+'%']
                    for class_index, rank in zip(result.probs.top5, range(5))]
    
    print(top5)
    
    return "\n".join(['{:<16}:{:>8}'.format(row[0], row[1]) for row in top5])


inputs = [
    gr.Image(label="Input Image"),
]


outputs = gr.Textbox()

title = "Racist model v4"

SAMPLE_DIR = 'samples'
examples = [os.path.join(SAMPLE_DIR, path) for path in os.listdir(SAMPLE_DIR)]

yolo_app = gr.Interface(
    fn=handle_classify,
    inputs=inputs,
    outputs=outputs,
    title=title,
    examples=examples,
    cache_examples=True,
)

# Launch the Gradio interface in debug mode with queue enabled
yolo_app.launch(debug=True)