Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +24 -21
- requirements.txt +8 -8
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import warnings
|
|
| 6 |
warnings.filterwarnings('ignore')
|
| 7 |
|
| 8 |
# Constants
|
| 9 |
-
MODEL_ID = "
|
| 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 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
self.pipe.
|
| 29 |
-
|
|
|
|
|
|
|
| 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 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
| 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 |
-
torchvision==0.
|
| 3 |
-
diffusers==0.
|
| 4 |
-
transformers==4.
|
| 5 |
-
accelerate==0.
|
| 6 |
safetensors==0.3.1
|
| 7 |
-
gradio==3.
|
| 8 |
opencv-python==4.8.0.74
|
| 9 |
einops==0.6.1
|
| 10 |
-
pytorch-lightning==
|
| 11 |
omegaconf==2.3.0
|
| 12 |
-
huggingface-hub==0.
|
| 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
|