Mairaaa commited on
Commit
d3837fc
·
verified ·
1 Parent(s): c5a0203

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -3,7 +3,7 @@ import torch
3
  from PIL import Image
4
  from transformers import CLIPTextModel, CLIPTokenizer
5
  from diffusers import AutoencoderKL, DDIMScheduler
6
- from src.mgd_pipelines.mgd_pipe import MGDPipe # Use your implementation of MGDPipe
7
 
8
 
9
  # Load models and pipeline
@@ -24,6 +24,9 @@ def load_models(pretrained_model_path, device):
24
  scheduler = DDIMScheduler.from_pretrained(pretrained_model_path, subfolder="scheduler")
25
  scheduler.set_timesteps(50)
26
 
 
 
 
27
  # Load the UNet model
28
  unet = torch.hub.load(
29
  repo_or_dir="aimagelab/multimodal-garment-designer",
@@ -31,7 +34,11 @@ def load_models(pretrained_model_path, device):
31
  model="mgd",
32
  pretrained=True,
33
  dataset="dresscode", # Change to "vitonhd" if needed
34
- ).to(device)
 
 
 
 
35
 
36
  # Initialize the pipeline
37
  pipeline = MGDPipe(
@@ -88,9 +95,11 @@ if st.button("Generate"):
88
  if uploaded_file and text_prompt:
89
  st.write("Loading models...")
90
 
91
- # Load the pipeline
92
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
93
  pretrained_model_path = "runwayml/stable-diffusion-inpainting" # Change as required
 
 
94
  pipeline = load_models(pretrained_model_path, device)
95
 
96
  # Load sketch
 
3
  from PIL import Image
4
  from transformers import CLIPTextModel, CLIPTokenizer
5
  from diffusers import AutoencoderKL, DDIMScheduler
6
+ from src.mgd_pipelines.mgd_pipe import MGDPipe # Your MGDPipe implementation
7
 
8
 
9
  # Load models and pipeline
 
24
  scheduler = DDIMScheduler.from_pretrained(pretrained_model_path, subfolder="scheduler")
25
  scheduler.set_timesteps(50)
26
 
27
+ # Handle torch.hub checkpoint loading for CPU-only environments
28
+ map_location = "cpu" if device.type == "cpu" else None
29
+
30
  # Load the UNet model
31
  unet = torch.hub.load(
32
  repo_or_dir="aimagelab/multimodal-garment-designer",
 
34
  model="mgd",
35
  pretrained=True,
36
  dataset="dresscode", # Change to "vitonhd" if needed
37
+ map_location=map_location,
38
+ )
39
+
40
+ # Move UNet to the appropriate device
41
+ unet = unet.to(device)
42
 
43
  # Initialize the pipeline
44
  pipeline = MGDPipe(
 
95
  if uploaded_file and text_prompt:
96
  st.write("Loading models...")
97
 
98
+ # Detect device (CPU or GPU)
99
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
100
  pretrained_model_path = "runwayml/stable-diffusion-inpainting" # Change as required
101
+
102
+ # Load the pipeline
103
  pipeline = load_models(pretrained_model_path, device)
104
 
105
  # Load sketch