moved back to models
Browse files- pipeline_loader.py +0 -42
pipeline_loader.py
DELETED
|
@@ -1,42 +0,0 @@
|
|
| 1 |
-
from text_diffusion_pipeline import TextConditionalDDPMPipeline
|
| 2 |
-
from latent_diffusion_pipeline import UnconditionalDDPMPipeline
|
| 3 |
-
import os
|
| 4 |
-
from diffusers.pipelines.pipeline_utils import DiffusionPipeline
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
def get_pipeline(model_path):
|
| 8 |
-
# If model_path is a local directory, use the original logic
|
| 9 |
-
if os.path.isdir(model_path):
|
| 10 |
-
#Diffusion models
|
| 11 |
-
if os.path.exists(os.path.join(model_path, "unet")):
|
| 12 |
-
if os.path.exists(os.path.join(model_path, "text_encoder")):
|
| 13 |
-
#If it has a text encoder and a unet, it's text conditional diffusion
|
| 14 |
-
pipe = TextConditionalDDPMPipeline.from_pretrained(model_path)
|
| 15 |
-
else:
|
| 16 |
-
#If it has no text encoder, use the unconditional diffusion model
|
| 17 |
-
pipe = UnconditionalDDPMPipeline.from_pretrained(model_path)
|
| 18 |
-
else:
|
| 19 |
-
# Assume it's a Hugging Face Hub model ID
|
| 20 |
-
# Try to load config to determine if it's text-conditional
|
| 21 |
-
try:
|
| 22 |
-
config, _ = DiffusionPipeline.load_config(model_path)
|
| 23 |
-
has_text_encoder = "text_encoder" in config
|
| 24 |
-
except Exception:
|
| 25 |
-
print(f"Warning: Could not load config: {e}")
|
| 26 |
-
has_text_encoder = False
|
| 27 |
-
if has_text_encoder:
|
| 28 |
-
# Use the local pipeline file for custom_pipeline
|
| 29 |
-
pipe = DiffusionPipeline.from_pretrained(
|
| 30 |
-
model_path,
|
| 31 |
-
custom_pipeline="models.text_diffusion_pipeline.TextConditionalDDPMPipeline",
|
| 32 |
-
trust_remote_code=True,
|
| 33 |
-
)
|
| 34 |
-
else:
|
| 35 |
-
# Fallback: try unconditional
|
| 36 |
-
pipe = DiffusionPipeline.from_pretrained(
|
| 37 |
-
model_path,
|
| 38 |
-
custom_pipeline="models.latent_diffusion_pipeline.UnconditionalDDPMPipeline",
|
| 39 |
-
trust_remote_code=True,
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
-
return pipe
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|