Spaces:
Sleeping
Sleeping
Initial image load bug fix
Browse files
app.py
CHANGED
|
@@ -11,7 +11,8 @@ weights = torch.load('trained_model', map_location=torch.device('cpu'))
|
|
| 11 |
model.load_state_dict(weights)
|
| 12 |
model.eval()
|
| 13 |
|
| 14 |
-
file_list = os.listdir(
|
|
|
|
| 15 |
examples = []
|
| 16 |
usersIndexes = []
|
| 17 |
for x in file_list:
|
|
@@ -77,47 +78,46 @@ js = """
|
|
| 77 |
}
|
| 78 |
}
|
| 79 |
"""
|
| 80 |
-
|
| 81 |
-
|
|
|
|
| 82 |
|
| 83 |
with gr.Blocks(css=css, elem_classes=['container']) as demo:
|
| 84 |
with gr.Row():
|
| 85 |
|
| 86 |
with gr.Row():
|
| 87 |
-
drop1 = gr.Dropdown(value=
|
| 88 |
choices=file_list,
|
| 89 |
label='Select first image',
|
| 90 |
scale=1,
|
| 91 |
|
| 92 |
)
|
| 93 |
|
| 94 |
-
drop2 = gr.Dropdown(value=
|
| 95 |
choices=file_list,
|
| 96 |
label='Select second image',
|
| 97 |
scale=1,
|
| 98 |
|
| 99 |
)
|
| 100 |
label = gr.Label(value='Scans of the same finger', show_label=False)
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
with gr.Row():
|
| 105 |
-
img1 = gr.Image(
|
| 106 |
-
height=288,
|
| 107 |
width=256,
|
| 108 |
interactive=False,
|
| 109 |
scale=1,
|
| 110 |
label='first image',
|
| 111 |
show_download_button=False,
|
|
|
|
| 112 |
elem_classes=['my-img'])
|
| 113 |
|
| 114 |
-
img2 = gr.Image(
|
| 115 |
-
height=288,
|
| 116 |
width=256,
|
| 117 |
interactive=False,
|
| 118 |
scale=1,
|
| 119 |
label='second image',
|
| 120 |
show_download_button=False,
|
|
|
|
| 121 |
elem_classes=['my-img'])
|
| 122 |
|
| 123 |
output = gr.Label(value=predict(*examples[0])[2], elem_id='res', show_label=False)
|
|
@@ -125,6 +125,8 @@ with gr.Blocks(css=css, elem_classes=['container']) as demo:
|
|
| 125 |
drop1.change(fn=predict, inputs=[drop1, drop2], outputs=[img1, img2, output, label])
|
| 126 |
drop2.change(fn=predict, inputs=[drop1, drop2], outputs=[img1, img2, output, label])
|
| 127 |
output.change(fn=None, inputs=None, js=js)
|
|
|
|
|
|
|
| 128 |
demo.launch()
|
| 129 |
|
| 130 |
# %%
|
|
|
|
| 11 |
model.load_state_dict(weights)
|
| 12 |
model.eval()
|
| 13 |
|
| 14 |
+
file_list = os.listdir("data")
|
| 15 |
+
|
| 16 |
examples = []
|
| 17 |
usersIndexes = []
|
| 18 |
for x in file_list:
|
|
|
|
| 78 |
}
|
| 79 |
}
|
| 80 |
"""
|
| 81 |
+
def refresh():
|
| 82 |
+
image = Image.open(f'data/{file_list[0]}')
|
| 83 |
+
return image, image
|
| 84 |
|
| 85 |
with gr.Blocks(css=css, elem_classes=['container']) as demo:
|
| 86 |
with gr.Row():
|
| 87 |
|
| 88 |
with gr.Row():
|
| 89 |
+
drop1 = gr.Dropdown(value=file_list[0],
|
| 90 |
choices=file_list,
|
| 91 |
label='Select first image',
|
| 92 |
scale=1,
|
| 93 |
|
| 94 |
)
|
| 95 |
|
| 96 |
+
drop2 = gr.Dropdown(value=file_list[0],
|
| 97 |
choices=file_list,
|
| 98 |
label='Select second image',
|
| 99 |
scale=1,
|
| 100 |
|
| 101 |
)
|
| 102 |
label = gr.Label(value='Scans of the same finger', show_label=False)
|
| 103 |
+
|
|
|
|
|
|
|
| 104 |
with gr.Row():
|
| 105 |
+
img1 = gr.Image(height=288, # unfortunately value doesn't work properly
|
|
|
|
| 106 |
width=256,
|
| 107 |
interactive=False,
|
| 108 |
scale=1,
|
| 109 |
label='first image',
|
| 110 |
show_download_button=False,
|
| 111 |
+
show_share_button=False,
|
| 112 |
elem_classes=['my-img'])
|
| 113 |
|
| 114 |
+
img2 = gr.Image(height=288,
|
|
|
|
| 115 |
width=256,
|
| 116 |
interactive=False,
|
| 117 |
scale=1,
|
| 118 |
label='second image',
|
| 119 |
show_download_button=False,
|
| 120 |
+
show_share_button=False,
|
| 121 |
elem_classes=['my-img'])
|
| 122 |
|
| 123 |
output = gr.Label(value=predict(*examples[0])[2], elem_id='res', show_label=False)
|
|
|
|
| 125 |
drop1.change(fn=predict, inputs=[drop1, drop2], outputs=[img1, img2, output, label])
|
| 126 |
drop2.change(fn=predict, inputs=[drop1, drop2], outputs=[img1, img2, output, label])
|
| 127 |
output.change(fn=None, inputs=None, js=js)
|
| 128 |
+
# initial img load workaround
|
| 129 |
+
demo.load(fn=refresh, inputs=None, outputs=[img1, img2])
|
| 130 |
demo.launch()
|
| 131 |
|
| 132 |
# %%
|