File size: 1,392 Bytes
58c4939
 
 
f7d50a4
 
58c4939
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65961e1
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
import os

import gradio as gr

from ccip import _VALID_MODEL_NAMES, _DEFAULT_MODEL_NAMES, ccip_difference, ccip_default_threshold


def _compare(imagex, imagey, model_name):
    threshold = ccip_default_threshold(model_name)
    diff = ccip_difference(imagex, imagey)

    return diff, 'Same' if diff <= threshold else 'Not Same'


if __name__ == '__main__':
    with gr.Blocks() as demo:
        with gr.Row():
            with gr.Column():
                with gr.Row():
                    with gr.Column():
                        gr_input_x = gr.Image(type='pil', label='Image X')
                    with gr.Column():
                        gr_input_y = gr.Image(type='pil', label='Image Y')
                with gr.Row():
                    gr_model_name = gr.Dropdown(_VALID_MODEL_NAMES, value=_DEFAULT_MODEL_NAMES, label='Model')

                gr_button = gr.Button(value='Compare', variant='primary')

            with gr.Column():
                with gr.Row():
                    gr_diff = gr.Number(value=0.0, label='Difference')
                with gr.Row():
                    gr_prediction = gr.Text(value='', label='Prediction')

            gr_button.click(
                _compare,
                inputs=[gr_input_x, gr_input_y, gr_model_name],
                outputs=[gr_diff, gr_prediction],
            )

    demo.queue(os.cpu_count()).launch(share = True)