File size: 1,432 Bytes
da0bb8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from ultralytics import RTDETR
from huggingface_hub import hf_hub_download, snapshot_download

model_path = hf_hub_download(
    repo_id="itsyoboieltr/pcb",
    repo_type="model",
    filename="model.pt",
)

examples_path = snapshot_download(
    repo_id="itsyoboieltr/pcb",
    repo_type="dataset",
    allow_patterns=["examples/*"],
    local_dir="./pcb_dataset",
)

model = RTDETR(model=model_path)


def predict_image(src):
    predictions = model.predict(src)
    return predictions[0].plot()


with gr.Blocks() as demo:
    gr.Markdown(
        '### <h3 align="center">Defect detection for Printed Circuit Boards</h3>'
    )
    gr.Markdown(
        "This AI was trained to detect and recognize six types of defects on printed circuit boards: missing hole, mouse bite, open circuit, short, spur, and spurious copper."
    )
    with gr.Row():
        image_input = gr.Image(width=486, height=238)
        image_output = gr.Image(width=486, height=238)
        image_input.upload(
            predict_image,
            inputs=[image_input],
            outputs=[image_output],
        )
        image_input.clear(lambda: None, outputs=[image_output], api_name=False)
    gr.Examples(
        "./pcb_dataset/examples",
        [image_input],
        [image_output],
        predict_image,
        cache_examples=True,
    )
    gr.Markdown("[@itsyoboieltr](https://github.com/itsyoboieltr)")

demo.launch()