Ali Mohsin commited on
Commit
dbb02ac
Β·
1 Parent(s): d9371aa
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  import base64
3
  import io
 
4
  from typing import List, Optional, Any, Dict
5
 
6
  import gradio as gr
@@ -952,8 +953,8 @@ def gradio_recommend(
952
  print(f"πŸ” DEBUG: Error in compose_outfits result: {res[0]}")
953
  return [], res[0]
954
 
955
- # Prepare stitched previews
956
- strips: List[Image.Image] = []
957
  print(f"πŸ” DEBUG: Preparing stitched previews for {len(res)} outfits...")
958
  for i, r in enumerate(res):
959
  idxs = []
@@ -971,12 +972,19 @@ def gradio_recommend(
971
  print(f"πŸ” DEBUG: Extracted {len(imgs)} images from indices {idxs}")
972
  if imgs:
973
  strip = _stitch_strip(imgs)
974
- strips.append(strip)
975
  print(f"πŸ” DEBUG: Created stitched image: {strip.size}")
 
 
 
 
 
 
 
 
976
  else:
977
  print(f"⚠️ DEBUG: No images extracted for outfit {i+1}")
978
 
979
- print(f"πŸ” DEBUG: Returning {len(strips)} stitched images and {len(res)} outfit results")
980
  return strips, {"outfits": res}
981
 
982
 
 
1
  import os
2
  import base64
3
  import io
4
+ import tempfile
5
  from typing import List, Optional, Any, Dict
6
 
7
  import gradio as gr
 
953
  print(f"πŸ” DEBUG: Error in compose_outfits result: {res[0]}")
954
  return [], res[0]
955
 
956
+ # Prepare stitched previews - save to temp files for Gradio API compatibility
957
+ strips: List[str] = [] # Changed to List[str] for file paths
958
  print(f"πŸ” DEBUG: Preparing stitched previews for {len(res)} outfits...")
959
  for i, r in enumerate(res):
960
  idxs = []
 
972
  print(f"πŸ” DEBUG: Extracted {len(imgs)} images from indices {idxs}")
973
  if imgs:
974
  strip = _stitch_strip(imgs)
 
975
  print(f"πŸ” DEBUG: Created stitched image: {strip.size}")
976
+
977
+ # Save to temporary file (Gradio will convert to URL)
978
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.png', dir='/tmp')
979
+ strip.save(temp_file.name, 'PNG')
980
+ temp_file.close()
981
+
982
+ strips.append(temp_file.name) # Return file path instead of PIL Image
983
+ print(f"πŸ” DEBUG: Saved to temp file: {temp_file.name}")
984
  else:
985
  print(f"⚠️ DEBUG: No images extracted for outfit {i+1}")
986
 
987
+ print(f"πŸ” DEBUG: Returning {len(strips)} stitched image file paths and {len(res)} outfit results")
988
  return strips, {"outfits": res}
989
 
990