Hug0endob commited on
Commit
e7c4cd5
·
verified ·
1 Parent(s): 5d2b527

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -21
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
- 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
 
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