DurgaDeepak commited on
Commit
e071be8
·
verified ·
1 Parent(s): b0ea65c

Update core/input_handler.py

Browse files
Files changed (1) hide show
  1. core/input_handler.py +11 -4
core/input_handler.py CHANGED
@@ -123,13 +123,20 @@ def validate_video(path):
123
  def show_preview_from_upload(files):
124
  if not files or len(files) == 0:
125
  return gr.update(visible=False), gr.update(visible=False)
126
- file_path = files[0].name # Use .name to get the temp file path
 
 
 
 
127
  if file_path.endswith((".png", ".jpg", ".jpeg", ".webp")):
128
- return gr.update(value=file_path, visible=True), gr.update(visible=False)
 
 
 
129
  elif file_path.endswith((".mp4", ".mov", ".avi")):
130
- return gr.update(visible=False), gr.update(value=file_path, visible=True)
131
- return gr.update(visible=False), gr.update(visible=False)
132
 
 
133
 
134
  def show_preview_from_url(url):
135
  if not url:
 
123
  def show_preview_from_upload(files):
124
  if not files or len(files) == 0:
125
  return gr.update(visible=False), gr.update(visible=False)
126
+
127
+ file = files[0]
128
+ file_path = file.name.lower()
129
+
130
+ # Handle Image Preview via PIL
131
  if file_path.endswith((".png", ".jpg", ".jpeg", ".webp")):
132
+ pil_image = Image.open(file).convert("RGB")
133
+ return gr.update(value=pil_image, visible=True), gr.update(visible=False)
134
+
135
+ # Handle Video Preview via .name
136
  elif file_path.endswith((".mp4", ".mov", ".avi")):
137
+ return gr.update(visible=False), gr.update(value=file.name, visible=True)
 
138
 
139
+ return gr.update(visible=False), gr.update(visible=False)
140
 
141
  def show_preview_from_url(url):
142
  if not url: