multimodalart HF Staff commited on
Commit
c355351
·
verified ·
1 Parent(s): 9a27802

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py CHANGED
@@ -14,6 +14,7 @@ import random
14
  import time
15
  import requests
16
  import pandas as pd
 
17
 
18
  #Load prompts for randomization
19
  df = pd.read_csv('prompts.csv', header=None)
@@ -23,6 +24,31 @@ prompt_values = df.values.flatten()
23
  with open('loras.json', 'r') as f:
24
  loras = json.load(f)
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  # Initialize the base model
27
  dtype = torch.bfloat16
28
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
14
  import time
15
  import requests
16
  import pandas as pd
17
+ import tempfile
18
 
19
  #Load prompts for randomization
20
  df = pd.read_csv('prompts.csv', header=None)
 
24
  with open('loras.json', 'r') as f:
25
  loras = json.load(f)
26
 
27
+ def download_and_cache_lora_images(loras):
28
+ """Download all lora images and replace URLs with local paths"""
29
+ for lora in loras:
30
+ if lora.get('image') and lora['image'].startswith('http'):
31
+ try:
32
+ response = requests.get(lora['image'], timeout=10)
33
+ response.raise_for_status()
34
+
35
+ # Create temp file
36
+ temp_dir = tempfile.gettempdir()
37
+ filename = f"lora_{hash(lora['image'])}.png"
38
+ local_path = os.path.join(temp_dir, filename)
39
+
40
+ with open(local_path, 'wb') as f:
41
+ f.write(response.content)
42
+
43
+ lora['image'] = local_path
44
+ print(f"Downloaded image for {lora['title']}")
45
+ except Exception as e:
46
+ print(f"Failed to download image for {lora['title']}: {e}")
47
+ lora['image'] = None
48
+ return loras
49
+
50
+ loras = download_and_cache_lora_images(loras)
51
+
52
  # Initialize the base model
53
  dtype = torch.bfloat16
54
  device = "cuda" if torch.cuda.is_available() else "cpu"