Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -790,29 +790,29 @@ def create_demo():
|
|
| 790 |
preview_path_state = gr.State("") # current preview file
|
| 791 |
prev_preview_state = gr.State("") # remembers the last file we showed
|
| 792 |
|
| 793 |
-
def apply_preview(path: str, last_path: str):
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
if not path:
|
| 798 |
-
return gr.update(), gr.update(), ""
|
| 799 |
-
|
| 800 |
-
try:
|
| 801 |
-
if any(path.lower().endswith(ext) for ext in IMAGE_EXTS):
|
| 802 |
-
return gr.update(value=path, visible=True), gr.update(value=None, visible=False), "Preview updated."
|
| 803 |
|
| 804 |
-
if
|
| 805 |
-
return gr.update(
|
| 806 |
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 816 |
|
| 817 |
demo.queue()
|
| 818 |
return demo
|
|
|
|
| 790 |
preview_path_state = gr.State("") # current preview file
|
| 791 |
prev_preview_state = gr.State("") # remembers the last file we showed
|
| 792 |
|
| 793 |
+
def apply_preview(path: str, last_path: str):
|
| 794 |
+
if path == last_path:
|
| 795 |
+
return gr.update(), gr.update(), ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 796 |
|
| 797 |
+
if not path:
|
| 798 |
+
return gr.update(), gr.update(), ""
|
| 799 |
|
| 800 |
+
try:
|
| 801 |
+
if any(path.lower().endswith(ext) for ext in IMAGE_EXTS):
|
| 802 |
+
return gr.update(value=path, visible=True), gr.update(value=None, visible=False), "Preview updated."
|
| 803 |
+
|
| 804 |
+
if any(path.lower().endswith(ext) for ext in VIDEO_EXTS):
|
| 805 |
+
return gr.update(value=None, visible=False), gr.update(value=path, visible=True), "Preview updated."
|
| 806 |
+
|
| 807 |
+
img = Image.open(path)
|
| 808 |
+
img.verify()
|
| 809 |
+
return gr.update(value=path, visible=True), gr.update(value=None, visible=False), "Preview updated."
|
| 810 |
+
|
| 811 |
+
except Exception as e:
|
| 812 |
+
print(f"Failed to update preview: {e}")
|
| 813 |
+
return gr.update(value=None, visible=False), gr.update(value=None, visible=False), ""
|
| 814 |
+
|
| 815 |
+
preview_path_state.change(fn=apply_preview, inputs=[preview_path_state], outputs=[preview_image, preview_video, preview_status])
|
| 816 |
|
| 817 |
demo.queue()
|
| 818 |
return demo
|