Upload lpips/app.py with huggingface_hub
Browse files- lpips/app.py +33 -0
lpips/app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from PIL import Image
|
| 5 |
+
from imgutils.metrics import lpips_difference
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _fn_diff(imagex: Image.Image, imagey: Image.Image):
|
| 9 |
+
diff = lpips_difference(imagex, imagey)
|
| 10 |
+
return diff
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
if __name__ == '__main__':
|
| 14 |
+
with gr.Blocks() as demo:
|
| 15 |
+
with gr.Row():
|
| 16 |
+
with gr.Column():
|
| 17 |
+
with gr.Row():
|
| 18 |
+
gr_input_x = gr.Image(label='Image X', image_mode='RGB', type='pil')
|
| 19 |
+
gr_input_y = gr.Image(label='Image Y', image_mode='RGB', type='pil')
|
| 20 |
+
with gr.Row():
|
| 21 |
+
gr_submit = gr.Button(value='Get Diff', variant='primary')
|
| 22 |
+
|
| 23 |
+
with gr.Column():
|
| 24 |
+
with gr.Row():
|
| 25 |
+
gr_diff = gr.Textbox(label='Difference')
|
| 26 |
+
|
| 27 |
+
gr_submit.click(
|
| 28 |
+
_fn_diff,
|
| 29 |
+
inputs=[gr_input_x, gr_input_y],
|
| 30 |
+
outputs=[gr_diff],
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
demo.queue(os.cpu_count()).launch()
|