Spaces:
Running on Zero
Running on Zero
Reset to recommended settings button
Browse files
app.py
CHANGED
|
@@ -180,6 +180,22 @@ def on_clear(state, gamma):
|
|
| 180 |
"Focal points cleared. Click the restored image or the depth map to focus.")
|
| 181 |
|
| 182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
HEADER = """
|
| 184 |
<div style="text-align:center">
|
| 185 |
<h1 style="margin-bottom:0.2em">FlashReFocus: Interactive Image Refocusing in Seconds</h1>
|
|
@@ -226,6 +242,7 @@ with gr.Blocks(title="FlashReFocus", theme=gr.themes.Soft()) as demo:
|
|
| 226 |
with gr.Row():
|
| 227 |
show_marker = gr.Checkbox(value=False, label="Show focal markers on the result")
|
| 228 |
clear = gr.Button("Clear focal points")
|
|
|
|
| 229 |
out = gr.Image(label="3. Refocused", type="pil", interactive=False, height=420, format="png")
|
| 230 |
status = gr.Markdown("")
|
| 231 |
controls = [state, strength, mode, gamma, band, show_marker]
|
|
@@ -239,6 +256,7 @@ with gr.Blocks(title="FlashReFocus", theme=gr.themes.Soft()) as demo:
|
|
| 239 |
show_marker.change(on_change, controls, outputs)
|
| 240 |
user_depth.change(on_user_depth, [state, user_depth, strength, mode, gamma, band, show_marker], outputs)
|
| 241 |
clear.click(on_clear, [state, gamma], outputs)
|
|
|
|
| 242 |
|
| 243 |
if __name__ == "__main__":
|
| 244 |
demo.queue(max_size=20).launch(show_api=False)
|
|
|
|
| 180 |
"Focal points cleared. Click the restored image or the depth map to focus.")
|
| 181 |
|
| 182 |
|
| 183 |
+
RECOMMENDED = {"long_side": 1024, "omega": 1.25, "gamma": 1.0, "band": 0.06, "strength": 0.5, "mode": SINGLE,
|
| 184 |
+
"show_marker": False}
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def on_reset(state):
|
| 188 |
+
"""Recommended settings (the paper's defaults), the estimated depth again; focal points are kept."""
|
| 189 |
+
r = RECOMMENDED
|
| 190 |
+
controls = [r["long_side"], r["omega"], r["gamma"], r["band"], r["strength"], r["mode"], r["show_marker"], None]
|
| 191 |
+
if not state:
|
| 192 |
+
return controls + [gr.update(), None, gr.update(), state, "Settings reset to the recommended values."]
|
| 193 |
+
state = dict(state, user_depth=None, pts=state["pts"][:1])
|
| 194 |
+
out, depth_view, msg = render(state, r["strength"], r["mode"], r["gamma"], r["band"], r["show_marker"])
|
| 195 |
+
note = "Settings reset to the recommended values (ω applies on the next Restore). "
|
| 196 |
+
return controls + [aif_view(state, r["mode"]), out, depth_view, state, note + msg]
|
| 197 |
+
|
| 198 |
+
|
| 199 |
HEADER = """
|
| 200 |
<div style="text-align:center">
|
| 201 |
<h1 style="margin-bottom:0.2em">FlashReFocus: Interactive Image Refocusing in Seconds</h1>
|
|
|
|
| 242 |
with gr.Row():
|
| 243 |
show_marker = gr.Checkbox(value=False, label="Show focal markers on the result")
|
| 244 |
clear = gr.Button("Clear focal points")
|
| 245 |
+
reset = gr.Button("Reset to recommended settings")
|
| 246 |
out = gr.Image(label="3. Refocused", type="pil", interactive=False, height=420, format="png")
|
| 247 |
status = gr.Markdown("")
|
| 248 |
controls = [state, strength, mode, gamma, band, show_marker]
|
|
|
|
| 256 |
show_marker.change(on_change, controls, outputs)
|
| 257 |
user_depth.change(on_user_depth, [state, user_depth, strength, mode, gamma, band, show_marker], outputs)
|
| 258 |
clear.click(on_clear, [state, gamma], outputs)
|
| 259 |
+
reset.click(on_reset, [state], [long_side, omega, gamma, band, strength, mode, show_marker, user_depth] + outputs)
|
| 260 |
|
| 261 |
if __name__ == "__main__":
|
| 262 |
demo.queue(max_size=20).launch(show_api=False)
|