alvdansen commited on
Commit
eaaefc2
β€’
1 Parent(s): f1ed22c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -1
app.py CHANGED
@@ -18,7 +18,40 @@ class CustomLCMScheduler(LCMScheduler):
18
  return {k: v for k, v in super().config.items() if k != "skip_prk_steps"}
19
 
20
  def get_image(image_data):
21
- # ... (keep the get_image function as is)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  with open("sdxl_lora.json", "r") as file:
24
  data = json.load(file)
 
18
  return {k: v for k, v in super().config.items() if k != "skip_prk_steps"}
19
 
20
  def get_image(image_data):
21
+ if isinstance(image_data, str):
22
+ return image_data
23
+
24
+ if isinstance(image_data, dict):
25
+ local_path = image_data.get('local_path')
26
+ hf_url = image_data.get('hf_url')
27
+ else:
28
+ print(f"Unexpected image_data format: {type(image_data)}")
29
+ return None
30
+
31
+ # Try loading from local path first
32
+ if local_path and os.path.exists(local_path):
33
+ try:
34
+ Image.open(local_path).verify() # Verify that it's a valid image
35
+ return local_path
36
+ except Exception as e:
37
+ print(f"Error loading local image {local_path}: {e}")
38
+
39
+ # If local path fails or doesn't exist, try URL
40
+ if hf_url:
41
+ try:
42
+ response = requests.get(hf_url)
43
+ if response.status_code == 200:
44
+ img = Image.open(requests.get(hf_url, stream=True).raw)
45
+ img.verify() # Verify that it's a valid image
46
+ img.save(local_path) # Save for future use
47
+ return local_path
48
+ else:
49
+ print(f"Failed to fetch image from URL {hf_url}. Status code: {response.status_code}")
50
+ except Exception as e:
51
+ print(f"Error loading image from URL {hf_url}: {e}")
52
+
53
+ print(f"Failed to load image for {image_data}")
54
+ return None
55
 
56
  with open("sdxl_lora.json", "r") as file:
57
  data = json.load(file)