File size: 1,452 Bytes
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
import os
import gradio as gr

from changechip import *

app_port = os.getenv("APP_PORT", "7860")


def process(input_image, reference_image, resize_factor, output_alpha):
    return pipeline(
        (input_image, reference_image),
        resize_factor=resize_factor,
        output_alpha=output_alpha,
    )


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")

        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],
        outputs=output_image,
    )

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