File size: 1,425 Bytes
0093fb3 3b4a7c0 a35e152 7efb1aa b06f7bd 7efb1aa 1204185 7efb1aa 1204185 62d8c85 7efb1aa 1204185 0093fb3 884c19e ad83853 33afddf 7efb1aa 05958ce 7efb1aa 33afddf 7efb1aa 0093fb3 25c8f14 | 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 | import gradio as gr
import numpy as np
import flip_evaluator as flip
def compute_simple_diff(a: np.array, b: np.array) -> (np.array, float):
'''compute difference of two arrays'''
return a - b, str(np.round(np.mean(a-b), 4))
def compute_flip_diff(a: np.array, b: np.array) -> (np.array, float):
'''
compute NVIDIA nvlab's FLIP difference between two image arrays
'''
error_map, mean_error, _ = flip.evaluate(a, b, "HDR")
return error_map, str(np.round(mean_error,4))
examples = [
["examples/Office_ShadowAcne/reference.png",
"examples/Office_ShadowAcne/test.png"]
]
with gr.Blocks() as demo:
gr.Markdown("Compute difference using NVIDIA's [FLIP](https://github.com/NVlabs/flip/)")
with gr.Row(equal_height=True):
# define inputs and outputs
before = gr.Image(label="Before")
after = gr.Image(label="After")
diff = gr.Image(label="Difference")
with gr.Row(equal_height=True):
with gr.Column(scale=2):
button = gr.Button("Compute difference")
with gr.Column(scale=1, min_width=200):
meanbox = gr.Textbox(label="Mean difference")
# interaction
button.click(fn=compute_flip_diff,
inputs=[before, after],
outputs=[diff, meanbox]
)
gr.Examples(examples, [before, after])
if __name__ == "__main__":
demo.launch()
|