File size: 2,082 Bytes
3f8e838
 
 
 
 
242ebc0
 
 
 
 
 
 
 
 
 
3f8e838
 
 
 
242ebc0
 
 
 
3f8e838
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242ebc0
 
 
 
3f8e838
 
 
 
 
 
 
242ebc0
 
 
 
 
 
 
 
 
 
3f8e838
 
 
 
 
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
58
59
60
61
62
63
64
65
66
67
68
import gradio as gr

from changechip import *


def process(
    input_image,
    reference_image,
    resize_factor,
    output_alpha,
    window_size,
    clusters,
    pca_dim_gray,
    pca_dim_rgb,
):
    return pipeline(
        (input_image, reference_image),
        resize_factor=resize_factor,
        output_alpha=output_alpha,
        window_size=window_size,
        clusters=clusters,
        pca_dim_gray=pca_dim_gray,
        pca_dim_rgb=pca_dim_rgb,
    )


with gr.Blocks() as demo:
    gr.Markdown("# ChangeChip")
    gr.Markdown(
        """
        Welcome to ChangeChip! This tool allows you to detect defects on printed circuit boards (PCBs) by comparing an input image with a reference "golden sample" image. 
        Simply upload your images, adjust the settings if needed, and click "Run" to highlight any discrepancies.
        """
    )
    with gr.Row():
        with gr.Column(scale=1):
            input_image = gr.Image(label="Input Image")
            reference_image = gr.Image(label="Reference Image")
            with gr.Accordion(label="Other Options", open=False):
                resize_factor = gr.Slider(0.1, 1, 0.5, step=0.1, label="Resize Factor")
                output_alpha = gr.Slider(0, 255, 50, step=1, label="Output Alpha")
                window_size = gr.Slider(0, 10, 5, step=1, label="Window Size")
                clusters = gr.Slider(0, 32, 16, step=1, label="Clusters")
                pca_dim_gray = gr.Slider(0, 9, 3, step=1, label="PCA Dim Gray")
                pca_dim_rgb = gr.Slider(0, 27, 9, step=1, label="PCA Dim RGB")

        with gr.Column(scale=2):
            output_image = gr.Image(label="Output Image", scale=9)
            btn = gr.Button("Run", scale=1)

    btn.click(
        fn=process,
        inputs=[
            input_image,
            reference_image,
            resize_factor,
            output_alpha,
            window_size,
            clusters,
            pca_dim_gray,
            pca_dim_rgb,
        ],
        outputs=output_image,
    )

if __name__ == "__main__":
    demo.launch()