atef91 commited on
Commit
2ca668e
·
verified ·
1 Parent(s): c6009f2

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +24 -21
  2. requirements.txt +8 -8
app.py CHANGED
@@ -6,7 +6,7 @@ import warnings
6
  warnings.filterwarnings('ignore')
7
 
8
  # Constants
9
- MODEL_ID = "CompVis/stable-diffusion-v1-4" # Using SD 1.4 for better compatibility
10
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
11
  DTYPE = torch.float32
12
 
@@ -16,17 +16,19 @@ class FooocusGenerator:
16
  self.load_models()
17
 
18
  def load_models(self):
19
- self.pipe = StableDiffusionPipeline.from_pretrained(
20
- MODEL_ID,
21
- torch_dtype=DTYPE,
22
- safety_checker=None,
23
- requires_safety_checker=False
24
- )
25
-
26
- if DEVICE == "cuda":
27
- self.pipe.enable_attention_slicing()
28
- self.pipe.enable_vae_slicing()
29
- self.pipe = self.pipe.to(DEVICE)
 
 
30
 
31
  def generate_image(
32
  self,
@@ -65,15 +67,16 @@ class FooocusGenerator:
65
  "Landscape": (768, 512)
66
  }.get(aspect_ratios_selection, (512, 512))
67
 
68
- image = self.pipe(
69
- prompt=processed_prompt,
70
- negative_prompt=negative_prompt,
71
- num_inference_steps=steps,
72
- guidance_scale=guidance_scale,
73
- generator=generator,
74
- width=dimensions[0],
75
- height=dimensions[1]
76
- ).images[0]
 
77
 
78
  return image
79
 
 
6
  warnings.filterwarnings('ignore')
7
 
8
  # Constants
9
+ MODEL_ID = "runwayml/stable-diffusion-v1-5"
10
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
11
  DTYPE = torch.float32
12
 
 
16
  self.load_models()
17
 
18
  def load_models(self):
19
+ try:
20
+ self.pipe = StableDiffusionPipeline.from_pretrained(
21
+ MODEL_ID,
22
+ torch_dtype=DTYPE,
23
+ safety_checker=None
24
+ )
25
+
26
+ if DEVICE == "cuda":
27
+ self.pipe.enable_attention_slicing()
28
+ self.pipe = self.pipe.to(DEVICE)
29
+ except Exception as e:
30
+ print(f"Error loading model: {str(e)}")
31
+ raise e
32
 
33
  def generate_image(
34
  self,
 
67
  "Landscape": (768, 512)
68
  }.get(aspect_ratios_selection, (512, 512))
69
 
70
+ with torch.inference_mode():
71
+ image = self.pipe(
72
+ prompt=processed_prompt,
73
+ negative_prompt=negative_prompt,
74
+ num_inference_steps=steps,
75
+ guidance_scale=guidance_scale,
76
+ generator=generator,
77
+ width=dimensions[0],
78
+ height=dimensions[1]
79
+ ).images[0]
80
 
81
  return image
82
 
requirements.txt CHANGED
@@ -1,14 +1,14 @@
1
- torch==2.0.1
2
- torchvision==0.15.2
3
- diffusers==0.11.1
4
- transformers==4.26.1
5
- accelerate==0.17.1
6
  safetensors==0.3.1
7
- gradio==3.23.0
8
  opencv-python==4.8.0.74
9
  einops==0.6.1
10
- pytorch-lightning==2.0.2
11
  omegaconf==2.3.0
12
- huggingface-hub==0.13.4
13
  xformers==0.0.20
14
  triton==2.0.0
 
1
+ torch==1.13.1
2
+ torchvision==0.14.1
3
+ diffusers==0.7.2
4
+ transformers==4.25.1
5
+ accelerate==0.15.0
6
  safetensors==0.3.1
7
+ gradio==3.16.2
8
  opencv-python==4.8.0.74
9
  einops==0.6.1
10
+ pytorch-lightning==1.9.0
11
  omegaconf==2.3.0
12
+ huggingface-hub==0.11.1
13
  xformers==0.0.20
14
  triton==2.0.0