Spaces:
Running on Zero
Running on Zero
[Admin maintenance] Support new ZeroGPU hardware
#7
by multimodalart HF Staff - opened
- README.md +1 -1
- app.py +17 -4
- requirements.txt +1 -1
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 😻
|
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
|
|
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.50.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
app.py
CHANGED
|
@@ -1,10 +1,23 @@
|
|
| 1 |
-
import torch
|
| 2 |
import spaces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL
|
| 4 |
-
from transformers import
|
| 5 |
from ip_adapter.pipeline_stable_diffusion_extra_cfg import StableDiffusionPipelineCFG
|
| 6 |
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
from ip_adapter.ip_adapter_instruct import IPAdapterInstruct
|
| 9 |
from huggingface_hub import hf_hub_download
|
| 10 |
import gradio as gr
|
|
@@ -16,7 +29,7 @@ image_encoder_path = "laion/CLIP-ViT-H-14-laion2B-s32B-b79K"
|
|
| 16 |
ip_ckpt = hf_hub_download(repo_id="CiaraRowles/IP-Adapter-Instruct", filename="ip-adapter-instruct-sd15.bin", repo_type="model")
|
| 17 |
|
| 18 |
safety_model_id = "CompVis/stable-diffusion-safety-checker"
|
| 19 |
-
safety_feature_extractor =
|
| 20 |
safety_checker = StableDiffusionSafetyChecker.from_pretrained(safety_model_id)
|
| 21 |
|
| 22 |
device = "cuda"
|
|
@@ -47,7 +60,7 @@ ip_model = IPAdapterInstruct(pipe, image_encoder_path, ip_ckpt, device,dtypein=t
|
|
| 47 |
|
| 48 |
cv2.setNumThreads(1)
|
| 49 |
|
| 50 |
-
@spaces.GPU
|
| 51 |
def generate_image(images, prompt, negative_prompt,instruct_query, scale, nfaa_negative_prompt, progress=gr.Progress(track_tqdm=True)):
|
| 52 |
faceid_all_embeds = []
|
| 53 |
first_iteration = True
|
|
|
|
|
|
|
| 1 |
import spaces
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
# diffusers 0.29.2 imports FLAX_WEIGHTS_NAME from transformers.utils, removed in
|
| 5 |
+
# transformers 5.x. Shim it back before importing diffusers.
|
| 6 |
+
import transformers.utils as _tu
|
| 7 |
+
if not hasattr(_tu, "FLAX_WEIGHTS_NAME"):
|
| 8 |
+
_tu.FLAX_WEIGHTS_NAME = "flax_model.msgpack"
|
| 9 |
+
|
| 10 |
from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL
|
| 11 |
+
from transformers import CLIPImageProcessor
|
| 12 |
from ip_adapter.pipeline_stable_diffusion_extra_cfg import StableDiffusionPipelineCFG
|
| 13 |
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
|
| 14 |
|
| 15 |
+
# transformers 5.x's _finalize_model_loading reads self.all_tied_weights_keys,
|
| 16 |
+
# which diffusers 0.29.2's StableDiffusionSafetyChecker (older PreTrainedModel)
|
| 17 |
+
# does not define. Provide an empty default so loading succeeds.
|
| 18 |
+
if not hasattr(StableDiffusionSafetyChecker, "all_tied_weights_keys"):
|
| 19 |
+
StableDiffusionSafetyChecker.all_tied_weights_keys = {}
|
| 20 |
+
|
| 21 |
from ip_adapter.ip_adapter_instruct import IPAdapterInstruct
|
| 22 |
from huggingface_hub import hf_hub_download
|
| 23 |
import gradio as gr
|
|
|
|
| 29 |
ip_ckpt = hf_hub_download(repo_id="CiaraRowles/IP-Adapter-Instruct", filename="ip-adapter-instruct-sd15.bin", repo_type="model")
|
| 30 |
|
| 31 |
safety_model_id = "CompVis/stable-diffusion-safety-checker"
|
| 32 |
+
safety_feature_extractor = CLIPImageProcessor.from_pretrained(safety_model_id)
|
| 33 |
safety_checker = StableDiffusionSafetyChecker.from_pretrained(safety_model_id)
|
| 34 |
|
| 35 |
device = "cuda"
|
|
|
|
| 60 |
|
| 61 |
cv2.setNumThreads(1)
|
| 62 |
|
| 63 |
+
@spaces.GPU
|
| 64 |
def generate_image(images, prompt, negative_prompt,instruct_query, scale, nfaa_negative_prompt, progress=gr.Progress(track_tqdm=True)):
|
| 65 |
faceid_all_embeds = []
|
| 66 |
first_iteration = True
|
requirements.txt
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
diffusers==0.29.2
|
| 2 |
transformers
|
|
|
|
| 3 |
accelerate
|
| 4 |
safetensors
|
| 5 |
einops
|
| 6 |
onnxruntime-gpu
|
| 7 |
-
spaces==0.19.4
|
| 8 |
opencv-python
|
| 9 |
git+https://github.com/unity-research/IP-Adapter-Instruct.git
|
|
|
|
| 1 |
diffusers==0.29.2
|
| 2 |
transformers
|
| 3 |
+
torchvision
|
| 4 |
accelerate
|
| 5 |
safetensors
|
| 6 |
einops
|
| 7 |
onnxruntime-gpu
|
|
|
|
| 8 |
opencv-python
|
| 9 |
git+https://github.com/unity-research/IP-Adapter-Instruct.git
|