chore: fix dtype, etc
Browse files- .gitignore +3 -0
- app.py +16 -7
- requirements.txt +1 -1
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
__pycache__
|
| 3 |
+
.DS_Store
|
app.py
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
|
|
|
|
|
| 1 |
import random
|
| 2 |
|
| 3 |
import numpy as np
|
| 4 |
import torch
|
| 5 |
|
| 6 |
from diffusers import StableDiffusionXLPipeline
|
| 7 |
-
import spaces
|
| 8 |
|
| 9 |
import gradio as gr
|
| 10 |
|
| 11 |
-
from
|
| 12 |
|
| 13 |
torch.backends.cuda.matmul.allow_tf32 = True
|
| 14 |
torch.backends.cudnn.allow_tf32 = True
|
| 15 |
|
| 16 |
-
device = "cuda"
|
| 17 |
model_repo_id = "cagliostrolab/animagine-xl-4.0" # Replace to the model you would like to use
|
| 18 |
|
| 19 |
|
|
@@ -44,7 +45,7 @@ def infer(
|
|
| 44 |
if randomize_seed:
|
| 45 |
seed = random.randint(0, MAX_SEED)
|
| 46 |
|
| 47 |
-
generator = torch.Generator().manual_seed(seed)
|
| 48 |
|
| 49 |
latents = torch.randn(
|
| 50 |
(
|
|
@@ -82,7 +83,7 @@ def infer(
|
|
| 82 |
|
| 83 |
def color_name_to_channels(color_name: str) -> list[int]:
|
| 84 |
if color_name in COLOR_SET_MAP:
|
| 85 |
-
return COLOR_SET_MAP[color_name]
|
| 86 |
else:
|
| 87 |
raise ValueError(f"Unknown color name: {color_name}")
|
| 88 |
|
|
@@ -122,7 +123,15 @@ examples = [
|
|
| 122 |
|
| 123 |
with gr.Blocks() as demo:
|
| 124 |
with gr.Column():
|
| 125 |
-
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
with gr.Row():
|
| 128 |
prompt = gr.Text(
|
|
@@ -144,7 +153,7 @@ with gr.Blocks() as demo:
|
|
| 144 |
label="Negative prompt",
|
| 145 |
max_lines=1,
|
| 146 |
placeholder="Enter a negative prompt",
|
| 147 |
-
|
| 148 |
)
|
| 149 |
|
| 150 |
seed = gr.Slider(
|
|
|
|
| 1 |
+
import spaces # import first
|
| 2 |
+
|
| 3 |
import random
|
| 4 |
|
| 5 |
import numpy as np
|
| 6 |
import torch
|
| 7 |
|
| 8 |
from diffusers import StableDiffusionXLPipeline
|
|
|
|
| 9 |
|
| 10 |
import gradio as gr
|
| 11 |
|
| 12 |
+
from tkg import apply_tkg_noise, ColorSet, COLOR_SET_MAP
|
| 13 |
|
| 14 |
torch.backends.cuda.matmul.allow_tf32 = True
|
| 15 |
torch.backends.cudnn.allow_tf32 = True
|
| 16 |
|
| 17 |
+
device = "cuda"
|
| 18 |
model_repo_id = "cagliostrolab/animagine-xl-4.0" # Replace to the model you would like to use
|
| 19 |
|
| 20 |
|
|
|
|
| 45 |
if randomize_seed:
|
| 46 |
seed = random.randint(0, MAX_SEED)
|
| 47 |
|
| 48 |
+
generator = torch.Generator(device=device).manual_seed(seed)
|
| 49 |
|
| 50 |
latents = torch.randn(
|
| 51 |
(
|
|
|
|
| 83 |
|
| 84 |
def color_name_to_channels(color_name: str) -> list[int]:
|
| 85 |
if color_name in COLOR_SET_MAP:
|
| 86 |
+
return COLOR_SET_MAP[color_name].channels
|
| 87 |
else:
|
| 88 |
raise ValueError(f"Unknown color name: {color_name}")
|
| 89 |
|
|
|
|
| 123 |
|
| 124 |
with gr.Blocks() as demo:
|
| 125 |
with gr.Column():
|
| 126 |
+
gr.Markdown(
|
| 127 |
+
"""
|
| 128 |
+
# TKG Chroma-Key with AnimagineXL 4.0
|
| 129 |
+
|
| 130 |
+
TKG-DMπ₯π: Training-free Chroma Key Content Generation Diffusion Model
|
| 131 |
+
- arXiv: https://arxiv.org/abs/2411.15580
|
| 132 |
+
- GitHub: https://github.com/ryugo417/TKG-DM
|
| 133 |
+
|
| 134 |
+
""")
|
| 135 |
|
| 136 |
with gr.Row():
|
| 137 |
prompt = gr.Text(
|
|
|
|
| 153 |
label="Negative prompt",
|
| 154 |
max_lines=1,
|
| 155 |
placeholder="Enter a negative prompt",
|
| 156 |
+
value="lowres, bad anatomy, bad hands, text, error, missing finger, extra digits, fewer digits, cropped, worst quality, low quality, low score, bad score, average score, signature, watermark, username, blurry",
|
| 157 |
)
|
| 158 |
|
| 159 |
seed = gr.Slider(
|
requirements.txt
CHANGED
|
@@ -3,4 +3,4 @@ diffusers
|
|
| 3 |
torch
|
| 4 |
transformers
|
| 5 |
xformers
|
| 6 |
-
spaces
|
|
|
|
| 3 |
torch
|
| 4 |
transformers
|
| 5 |
xformers
|
| 6 |
+
spaces>=0.40.1
|