Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,10 @@ License: MIT
|
|
| 5 |
|
| 6 |
SD1.5 and SDXL-based flow matching with geometric crystalline architectures.
|
| 7 |
Supports Illustrious XL, standard SDXL, and SD1.5 variants.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
"""
|
| 9 |
|
| 10 |
import os
|
|
@@ -32,9 +36,21 @@ from transformers import (
|
|
| 32 |
)
|
| 33 |
from huggingface_hub import hf_hub_download
|
| 34 |
|
| 35 |
-
# Import Lyra VAE from geofractal
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
# ============================================================================
|
|
@@ -877,12 +893,12 @@ def load_sdxl_base(device: str = "cuda"):
|
|
| 877 |
|
| 878 |
|
| 879 |
def load_lyra_vae(repo_id: str = "AbstractPhil/vae-lyra", device: str = "cuda"):
|
| 880 |
-
"""Load Lyra VAE (SD1.5 version) from HuggingFace."""
|
| 881 |
-
if not
|
| 882 |
-
print("⚠️ Lyra VAE not available")
|
| 883 |
return None
|
| 884 |
|
| 885 |
-
print(f"🎵 Loading Lyra VAE from {repo_id}...")
|
| 886 |
|
| 887 |
try:
|
| 888 |
checkpoint_path = hf_hub_download(
|
|
@@ -909,7 +925,7 @@ def load_lyra_vae(repo_id: str = "AbstractPhil/vae-lyra", device: str = "cuda"):
|
|
| 909 |
'fusion_dropout': 0.1
|
| 910 |
}
|
| 911 |
|
| 912 |
-
vae_config =
|
| 913 |
modality_dims=config_dict.get('modality_dims', {"clip": 768, "t5": 768}),
|
| 914 |
latent_dim=config_dict.get('latent_dim', 768),
|
| 915 |
seq_len=config_dict.get('seq_len', 77),
|
|
@@ -922,7 +938,7 @@ def load_lyra_vae(repo_id: str = "AbstractPhil/vae-lyra", device: str = "cuda"):
|
|
| 922 |
fusion_dropout=config_dict.get('fusion_dropout', 0.1)
|
| 923 |
)
|
| 924 |
|
| 925 |
-
lyra_model =
|
| 926 |
|
| 927 |
if 'model_state_dict' in checkpoint:
|
| 928 |
lyra_model.load_state_dict(checkpoint['model_state_dict'])
|
|
@@ -932,11 +948,11 @@ def load_lyra_vae(repo_id: str = "AbstractPhil/vae-lyra", device: str = "cuda"):
|
|
| 932 |
lyra_model.to(device)
|
| 933 |
lyra_model.eval()
|
| 934 |
|
| 935 |
-
print(f"✅ Lyra VAE (SD1.5) loaded")
|
| 936 |
return lyra_model
|
| 937 |
|
| 938 |
except Exception as e:
|
| 939 |
-
print(f"❌ Failed to load Lyra VAE: {e}")
|
| 940 |
return None
|
| 941 |
|
| 942 |
|
|
@@ -944,12 +960,12 @@ def load_lyra_vae_xl(
|
|
| 944 |
repo_id: str = "AbstractPhil/vae-lyra-xl-adaptive-cantor-illustrious",
|
| 945 |
device: str = "cuda"
|
| 946 |
):
|
| 947 |
-
"""Load Lyra VAE
|
| 948 |
-
if not
|
| 949 |
-
print("⚠️ Lyra VAE not available")
|
| 950 |
return None
|
| 951 |
|
| 952 |
-
print(f"🎵 Loading Lyra VAE
|
| 953 |
|
| 954 |
try:
|
| 955 |
checkpoint_path = hf_hub_download(
|
|
@@ -963,7 +979,7 @@ def load_lyra_vae_xl(
|
|
| 963 |
if 'config' in checkpoint:
|
| 964 |
config_dict = checkpoint['config']
|
| 965 |
else:
|
| 966 |
-
# XL defaults -
|
| 967 |
config_dict = {
|
| 968 |
'modality_dims': {"clip": 768, "t5": 2048}, # T5-XL
|
| 969 |
'latent_dim': 2048,
|
|
@@ -977,7 +993,7 @@ def load_lyra_vae_xl(
|
|
| 977 |
'fusion_dropout': 0.1
|
| 978 |
}
|
| 979 |
|
| 980 |
-
vae_config =
|
| 981 |
modality_dims=config_dict.get('modality_dims', {"clip": 768, "t5": 2048}),
|
| 982 |
latent_dim=config_dict.get('latent_dim', 2048),
|
| 983 |
seq_len=config_dict.get('seq_len', 77),
|
|
@@ -990,7 +1006,7 @@ def load_lyra_vae_xl(
|
|
| 990 |
fusion_dropout=config_dict.get('fusion_dropout', 0.1)
|
| 991 |
)
|
| 992 |
|
| 993 |
-
lyra_model =
|
| 994 |
|
| 995 |
if 'model_state_dict' in checkpoint:
|
| 996 |
lyra_model.load_state_dict(checkpoint['model_state_dict'])
|
|
@@ -1000,14 +1016,14 @@ def load_lyra_vae_xl(
|
|
| 1000 |
lyra_model.to(device)
|
| 1001 |
lyra_model.eval()
|
| 1002 |
|
| 1003 |
-
print(f"✅ Lyra VAE
|
| 1004 |
if 'global_step' in checkpoint:
|
| 1005 |
print(f" Step: {checkpoint['global_step']:,}")
|
| 1006 |
|
| 1007 |
return lyra_model
|
| 1008 |
|
| 1009 |
except Exception as e:
|
| 1010 |
-
print(f"❌ Failed to load Lyra VAE
|
| 1011 |
return None
|
| 1012 |
|
| 1013 |
|
|
@@ -1284,12 +1300,12 @@ def create_demo():
|
|
| 1284 |
|
| 1285 |
Generate images using SD1.5 and SDXL-based models with geometric deep learning:
|
| 1286 |
|
| 1287 |
-
| Model | Architecture | Best For |
|
| 1288 |
-
|
| 1289 |
-
| **Illustrious XL** | SDXL | Anime/illustration, high detail |
|
| 1290 |
-
| **SDXL Base** | SDXL | Photorealistic, general purpose |
|
| 1291 |
-
| **Flow-Lune** | SD1.5 | Fast flow matching (15-25 steps) |
|
| 1292 |
-
| **SD1.5 Base** | SD1.5 | Baseline comparison |
|
| 1293 |
|
| 1294 |
Enable **Lyra VAE** for CLIP+T5 fusion comparison!
|
| 1295 |
""")
|
|
@@ -1417,12 +1433,13 @@ def create_demo():
|
|
| 1417 |
- **Illustrious XL**: Use CLIP skip 2, booru-style tags
|
| 1418 |
- **SDXL Base**: Natural language prompts work well
|
| 1419 |
- **Flow-Lune**: Enable flow matching, shift ~2.5, fewer steps
|
| 1420 |
-
- **Lyra**:
|
|
|
|
| 1421 |
|
| 1422 |
### Model Info
|
| 1423 |
- SDXL models use **epsilon** prediction
|
| 1424 |
- Lune uses **v_prediction** with flow matching
|
| 1425 |
-
- Lyra fuses CLIP + T5
|
| 1426 |
""")
|
| 1427 |
|
| 1428 |
# Examples
|
|
|
|
| 5 |
|
| 6 |
SD1.5 and SDXL-based flow matching with geometric crystalline architectures.
|
| 7 |
Supports Illustrious XL, standard SDXL, and SD1.5 variants.
|
| 8 |
+
|
| 9 |
+
Lyra VAE Versions:
|
| 10 |
+
- v1: SD1.5 (768 dim CLIP + T5-base) - geofractal.model.vae.vae_lyra
|
| 11 |
+
- v2: SDXL/Illustrious (768 CLIP-L + 2048 T5-XL) - geofractal.model.vae.vae_lyra_v2
|
| 12 |
"""
|
| 13 |
|
| 14 |
import os
|
|
|
|
| 36 |
)
|
| 37 |
from huggingface_hub import hf_hub_download
|
| 38 |
|
| 39 |
+
# Import Lyra VAE v1 (SD1.5) from geofractal
|
| 40 |
+
try:
|
| 41 |
+
from geofractal.model.vae.vae_lyra import MultiModalVAE as LyraV1, MultiModalVAEConfig as LyraV1Config
|
| 42 |
+
LYRA_V1_AVAILABLE = True
|
| 43 |
+
except ImportError:
|
| 44 |
+
print("⚠️ Lyra VAE v1 not available")
|
| 45 |
+
LYRA_V1_AVAILABLE = False
|
| 46 |
|
| 47 |
+
# Import Lyra VAE v2 (SDXL/Illustrious) from geofractal
|
| 48 |
+
try:
|
| 49 |
+
from geofractal.model.vae.vae_lyra_v2 import MultiModalVAE as LyraV2, MultiModalVAEConfig as LyraV2Config
|
| 50 |
+
LYRA_V2_AVAILABLE = True
|
| 51 |
+
except ImportError:
|
| 52 |
+
print("⚠️ Lyra VAE v2 not available")
|
| 53 |
+
LYRA_V2_AVAILABLE = False
|
| 54 |
|
| 55 |
|
| 56 |
# ============================================================================
|
|
|
|
| 893 |
|
| 894 |
|
| 895 |
def load_lyra_vae(repo_id: str = "AbstractPhil/vae-lyra", device: str = "cuda"):
|
| 896 |
+
"""Load Lyra VAE v1 (SD1.5 version) from HuggingFace."""
|
| 897 |
+
if not LYRA_V1_AVAILABLE:
|
| 898 |
+
print("⚠️ Lyra VAE v1 not available")
|
| 899 |
return None
|
| 900 |
|
| 901 |
+
print(f"🎵 Loading Lyra VAE v1 from {repo_id}...")
|
| 902 |
|
| 903 |
try:
|
| 904 |
checkpoint_path = hf_hub_download(
|
|
|
|
| 925 |
'fusion_dropout': 0.1
|
| 926 |
}
|
| 927 |
|
| 928 |
+
vae_config = LyraV1Config(
|
| 929 |
modality_dims=config_dict.get('modality_dims', {"clip": 768, "t5": 768}),
|
| 930 |
latent_dim=config_dict.get('latent_dim', 768),
|
| 931 |
seq_len=config_dict.get('seq_len', 77),
|
|
|
|
| 938 |
fusion_dropout=config_dict.get('fusion_dropout', 0.1)
|
| 939 |
)
|
| 940 |
|
| 941 |
+
lyra_model = LyraV1(vae_config)
|
| 942 |
|
| 943 |
if 'model_state_dict' in checkpoint:
|
| 944 |
lyra_model.load_state_dict(checkpoint['model_state_dict'])
|
|
|
|
| 948 |
lyra_model.to(device)
|
| 949 |
lyra_model.eval()
|
| 950 |
|
| 951 |
+
print(f"✅ Lyra VAE v1 (SD1.5) loaded")
|
| 952 |
return lyra_model
|
| 953 |
|
| 954 |
except Exception as e:
|
| 955 |
+
print(f"❌ Failed to load Lyra VAE v1: {e}")
|
| 956 |
return None
|
| 957 |
|
| 958 |
|
|
|
|
| 960 |
repo_id: str = "AbstractPhil/vae-lyra-xl-adaptive-cantor-illustrious",
|
| 961 |
device: str = "cuda"
|
| 962 |
):
|
| 963 |
+
"""Load Lyra VAE v2 (SDXL/Illustrious version) from HuggingFace."""
|
| 964 |
+
if not LYRA_V2_AVAILABLE:
|
| 965 |
+
print("⚠️ Lyra VAE v2 not available")
|
| 966 |
return None
|
| 967 |
|
| 968 |
+
print(f"🎵 Loading Lyra VAE v2 from {repo_id}...")
|
| 969 |
|
| 970 |
try:
|
| 971 |
checkpoint_path = hf_hub_download(
|
|
|
|
| 979 |
if 'config' in checkpoint:
|
| 980 |
config_dict = checkpoint['config']
|
| 981 |
else:
|
| 982 |
+
# XL v2 defaults - larger dimensions for SDXL
|
| 983 |
config_dict = {
|
| 984 |
'modality_dims': {"clip": 768, "t5": 2048}, # T5-XL
|
| 985 |
'latent_dim': 2048,
|
|
|
|
| 993 |
'fusion_dropout': 0.1
|
| 994 |
}
|
| 995 |
|
| 996 |
+
vae_config = LyraV2Config(
|
| 997 |
modality_dims=config_dict.get('modality_dims', {"clip": 768, "t5": 2048}),
|
| 998 |
latent_dim=config_dict.get('latent_dim', 2048),
|
| 999 |
seq_len=config_dict.get('seq_len', 77),
|
|
|
|
| 1006 |
fusion_dropout=config_dict.get('fusion_dropout', 0.1)
|
| 1007 |
)
|
| 1008 |
|
| 1009 |
+
lyra_model = LyraV2(vae_config)
|
| 1010 |
|
| 1011 |
if 'model_state_dict' in checkpoint:
|
| 1012 |
lyra_model.load_state_dict(checkpoint['model_state_dict'])
|
|
|
|
| 1016 |
lyra_model.to(device)
|
| 1017 |
lyra_model.eval()
|
| 1018 |
|
| 1019 |
+
print(f"✅ Lyra VAE v2 (SDXL) loaded")
|
| 1020 |
if 'global_step' in checkpoint:
|
| 1021 |
print(f" Step: {checkpoint['global_step']:,}")
|
| 1022 |
|
| 1023 |
return lyra_model
|
| 1024 |
|
| 1025 |
except Exception as e:
|
| 1026 |
+
print(f"❌ Failed to load Lyra VAE v2: {e}")
|
| 1027 |
return None
|
| 1028 |
|
| 1029 |
|
|
|
|
| 1300 |
|
| 1301 |
Generate images using SD1.5 and SDXL-based models with geometric deep learning:
|
| 1302 |
|
| 1303 |
+
| Model | Architecture | Lyra Version | Best For |
|
| 1304 |
+
|-------|-------------|--------------|----------|
|
| 1305 |
+
| **Illustrious XL** | SDXL | v2 (T5-XL) | Anime/illustration, high detail |
|
| 1306 |
+
| **SDXL Base** | SDXL | v2 (T5-XL) | Photorealistic, general purpose |
|
| 1307 |
+
| **Flow-Lune** | SD1.5 | v1 (T5-base) | Fast flow matching (15-25 steps) |
|
| 1308 |
+
| **SD1.5 Base** | SD1.5 | v1 (T5-base) | Baseline comparison |
|
| 1309 |
|
| 1310 |
Enable **Lyra VAE** for CLIP+T5 fusion comparison!
|
| 1311 |
""")
|
|
|
|
| 1433 |
- **Illustrious XL**: Use CLIP skip 2, booru-style tags
|
| 1434 |
- **SDXL Base**: Natural language prompts work well
|
| 1435 |
- **Flow-Lune**: Enable flow matching, shift ~2.5, fewer steps
|
| 1436 |
+
- **Lyra v2**: SDXL models use T5-XL for richer semantics
|
| 1437 |
+
- **Lyra v1**: SD1.5 models use T5-base
|
| 1438 |
|
| 1439 |
### Model Info
|
| 1440 |
- SDXL models use **epsilon** prediction
|
| 1441 |
- Lune uses **v_prediction** with flow matching
|
| 1442 |
+
- Lyra fuses CLIP + T5 via geometric Cantor attention
|
| 1443 |
""")
|
| 1444 |
|
| 1445 |
# Examples
|