atef91 commited on
Commit
5efda0a
·
verified ·
1 Parent(s): ad059fb

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +9 -8
  2. requirements.txt +2 -2
app.py CHANGED
@@ -6,7 +6,7 @@ import warnings
6
  warnings.filterwarnings('ignore')
7
 
8
  # Constants
9
- MODEL_ID = "runwayml/stable-diffusion-v1-5" # Using SD 1.5 for better compatibility
10
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
11
  DTYPE = torch.float32 # Using float32 for better compatibility
12
 
@@ -16,18 +16,19 @@ class FooocusGenerator:
16
  self.load_models()
17
 
18
  def load_models(self):
19
- # Load base model
20
- scheduler = DDIMScheduler.from_pretrained(MODEL_ID, subfolder="scheduler")
21
  self.pipe = StableDiffusionPipeline.from_pretrained(
22
  MODEL_ID,
23
- scheduler=scheduler,
24
  torch_dtype=DTYPE,
25
- safety_checker=None
 
26
  )
27
 
28
  if DEVICE == "cuda":
29
  self.pipe.enable_attention_slicing()
30
- self.pipe = self.pipe.to(DEVICE)
 
 
31
 
32
  def generate_image(
33
  self,
@@ -100,7 +101,7 @@ class FooocusGenerator:
100
  generator = FooocusGenerator()
101
 
102
  # Create the Gradio interface
103
- with gr.Blocks(title="Fooocus Web", theme=gr.themes.Soft()) as demo:
104
  gr.Markdown("# 🎨 Fooocus Web")
105
  gr.Markdown("Generate high-quality images with advanced controls")
106
 
@@ -197,4 +198,4 @@ with gr.Blocks(title="Fooocus Web", theme=gr.themes.Soft()) as demo:
197
  )
198
 
199
  if __name__ == "__main__":
200
- demo.launch(share=True)
 
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 # Using float32 for better compatibility
12
 
 
16
  self.load_models()
17
 
18
  def load_models(self):
19
+ # Load base model with minimal memory usage
 
20
  self.pipe = StableDiffusionPipeline.from_pretrained(
21
  MODEL_ID,
 
22
  torch_dtype=DTYPE,
23
+ safety_checker=None,
24
+ requires_safety_checker=False
25
  )
26
 
27
  if DEVICE == "cuda":
28
  self.pipe.enable_attention_slicing()
29
+ self.pipe.enable_sequential_cpu_offload()
30
+ else:
31
+ self.pipe = self.pipe.to(DEVICE)
32
 
33
  def generate_image(
34
  self,
 
101
  generator = FooocusGenerator()
102
 
103
  # Create the Gradio interface
104
+ with gr.Blocks(title="Fooocus Web", theme=gr.themes.Default()) as demo:
105
  gr.Markdown("# 🎨 Fooocus Web")
106
  gr.Markdown("Generate high-quality images with advanced controls")
107
 
 
198
  )
199
 
200
  if __name__ == "__main__":
201
+ demo.launch()
requirements.txt CHANGED
@@ -3,13 +3,13 @@ torchvision==0.15.2
3
  transformers==4.30.2
4
  accelerate==0.21.0
5
  safetensors==0.3.1
6
- gradio==4.19.2
7
  diffusers==0.19.3
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.16.4
13
  xformers==0.0.20
14
  triton==2.0.0
15
  compel==2.0.1
 
3
  transformers==4.30.2
4
  accelerate==0.21.0
5
  safetensors==0.3.1
6
+ gradio==3.50.2
7
  diffusers==0.19.3
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.15.1
13
  xformers==0.0.20
14
  triton==2.0.0
15
  compel==2.0.1