Darius Morawiec
commited on
Commit
·
b196700
1
Parent(s):
0708417
chore: Update UI
Browse files
app.py
CHANGED
|
@@ -13,8 +13,12 @@ from diffusers import (
|
|
| 13 |
from nunchaku import NunchakuQwenImageTransformer2DModel
|
| 14 |
from nunchaku.utils import get_gpu_memory, get_precision
|
| 15 |
|
|
|
|
|
|
|
| 16 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 17 |
|
|
|
|
|
|
|
| 18 |
RANK = 128
|
| 19 |
PRECISION = get_precision() if DEVICE == "cuda" else "fp4"
|
| 20 |
TRANSFORMER_ID = f"nunchaku-tech/nunchaku-qwen-image-edit-2509/svdq-{PRECISION}_r{RANK}-qwen-image-edit-2509.safetensors"
|
|
@@ -139,7 +143,7 @@ class Model:
|
|
| 139 |
latents = callback_kwargs.get("latents", None)
|
| 140 |
|
| 141 |
if latents is not None:
|
| 142 |
-
print(f"Latents shape: {latents.shape}, dtype: {latents.dtype}")
|
| 143 |
|
| 144 |
latents = pipeline._unpack_latents(
|
| 145 |
latents, self.image_height, self.image_width, pipeline.vae_scale_factor
|
|
@@ -166,15 +170,8 @@ class Model:
|
|
| 166 |
return {}
|
| 167 |
|
| 168 |
|
| 169 |
-
with gr.Blocks() as demo:
|
| 170 |
-
title = gr.Markdown(
|
| 171 |
-
"# [Nunchaku Qwen-Image-Edit-2509](https://huggingface.co/nunchaku-tech/nunchaku-qwen-image-edit-2509)"
|
| 172 |
-
)
|
| 173 |
-
|
| 174 |
-
if DEVICE != "cuda":
|
| 175 |
-
gr.Markdown(
|
| 176 |
-
"⚠️ **CUDA not available.** This application requires a CUDA-compatible GPU to function properly. You can duplicate this space with a CUDA-enabled runtime."
|
| 177 |
-
)
|
| 178 |
|
| 179 |
with gr.Row():
|
| 180 |
with gr.Column():
|
|
@@ -254,6 +251,15 @@ with gr.Blocks() as demo:
|
|
| 254 |
with gr.Row():
|
| 255 |
run_button = gr.Button("Run")
|
| 256 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
def preprocess_image(
|
| 258 |
image: PIL.Image.Image,
|
| 259 |
image_size: int = IMAGE_SIZE,
|
|
@@ -353,5 +359,5 @@ with gr.Blocks() as demo:
|
|
| 353 |
if __name__ == "__main__":
|
| 354 |
demo.launch(
|
| 355 |
allowed_paths=["output/video.mp4"],
|
| 356 |
-
|
| 357 |
)
|
|
|
|
| 13 |
from nunchaku import NunchakuQwenImageTransformer2DModel
|
| 14 |
from nunchaku.utils import get_gpu_memory, get_precision
|
| 15 |
|
| 16 |
+
from kofi import SCRIPT
|
| 17 |
+
|
| 18 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 19 |
|
| 20 |
+
HEADER = "# [Nunchaku Qwen-Image-Edit-2509](https://huggingface.co/nunchaku-tech/nunchaku-qwen-image-edit-2509)"
|
| 21 |
+
|
| 22 |
RANK = 128
|
| 23 |
PRECISION = get_precision() if DEVICE == "cuda" else "fp4"
|
| 24 |
TRANSFORMER_ID = f"nunchaku-tech/nunchaku-qwen-image-edit-2509/svdq-{PRECISION}_r{RANK}-qwen-image-edit-2509.safetensors"
|
|
|
|
| 143 |
latents = callback_kwargs.get("latents", None)
|
| 144 |
|
| 145 |
if latents is not None:
|
| 146 |
+
# print(f"Latents shape: {latents.shape}, dtype: {latents.dtype}")
|
| 147 |
|
| 148 |
latents = pipeline._unpack_latents(
|
| 149 |
latents, self.image_height, self.image_width, pipeline.vae_scale_factor
|
|
|
|
| 170 |
return {}
|
| 171 |
|
| 172 |
|
| 173 |
+
with gr.Blocks(js=SCRIPT) as demo:
|
| 174 |
+
title = gr.Markdown(HEADER)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
with gr.Row():
|
| 177 |
with gr.Column():
|
|
|
|
| 251 |
with gr.Row():
|
| 252 |
run_button = gr.Button("Run")
|
| 253 |
|
| 254 |
+
with gr.Row():
|
| 255 |
+
if DEVICE != "cuda":
|
| 256 |
+
gr.Markdown(
|
| 257 |
+
"⚠️ **CUDA not available.** This application requires a CUDA-compatible GPU to function properly. You can duplicate this space with a CUDA-enabled runtime."
|
| 258 |
+
)
|
| 259 |
+
|
| 260 |
+
with gr.Row():
|
| 261 |
+
gr.HTML('<div id="kofi" style="text-align: center;"></div>')
|
| 262 |
+
|
| 263 |
def preprocess_image(
|
| 264 |
image: PIL.Image.Image,
|
| 265 |
image_size: int = IMAGE_SIZE,
|
|
|
|
| 359 |
if __name__ == "__main__":
|
| 360 |
demo.launch(
|
| 361 |
allowed_paths=["output/video.mp4"],
|
| 362 |
+
share=False,
|
| 363 |
)
|
kofi.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
SCRIPT = """
|
| 2 |
+
async function loadKofi() {
|
| 3 |
+
var kofiwidget2 = kofiwidget2 ||
|
| 4 |
+
(function () {
|
| 5 |
+
var style = "";
|
| 6 |
+
var html = "";
|
| 7 |
+
var color = "";
|
| 8 |
+
var text = "";
|
| 9 |
+
var id = "";
|
| 10 |
+
return {
|
| 11 |
+
init: function (pText, pColor, pId) {
|
| 12 |
+
color = pColor;
|
| 13 |
+
text = pText;
|
| 14 |
+
id = pId;
|
| 15 |
+
style =
|
| 16 |
+
"img.kofiimg{display: initial!important;vertical-align:middle;height:13px!important;width:20px!important;padding-top:0!important;padding-bottom:0!important;border:none;margin-top:0;margin-right:7px!important;margin-left:0!important;margin-bottom:3px!important;content:url('https://storage.ko-fi.com/cdn/cup-border.png')}.kofiimg:after{vertical-align:middle;height:25px;padding-top:0;padding-bottom:0;border:none;margin-top:0;margin-right:6px;margin-left:0;margin-bottom:4px!important;content:url('https://storage.ko-fi.com/cdn/whitelogo.svg')}.btn-container{display:inline-block!important;white-space:nowrap;min-width:160px}span.kofitext{color:#fff !important;letter-spacing: -0.15px!important;text-wrap:none;vertical-align:middle;line-height:30px !important;padding:0;text-align:center;text-decoration:none!important; text-shadow: 0 1px 1px rgba(34, 34, 34, 0.05);}.kofitext a{color:#fff !important;text-decoration:none:important;}.kofitext a:hover{color:#fff !important;text-decoration:none}a.kofi-button{box-shadow: 1px 1px 0px rgba(0, 0, 0, 0.2);line-height:27px!important;min-width:150px;display:inline-block!important;background-color:#29abe0;padding:2px 12px !important;text-align:center !important;border-radius:7px;color:#fff;cursor:pointer;overflow-wrap:break-word;vertical-align:middle;border:0 none #fff !important;font-family:'Quicksand',Helvetica,Century Gothic,sans-serif !important;text-decoration:none;text-shadow:none;font-weight:700!important;font-size:14px !important}a.kofi-button:visited{color:#fff !important;text-decoration:none !important}a.kofi-button:hover{opacity:.85;color:#f5f5f5 !important;text-decoration:none !important}a.kofi-button:active{color:#f5f5f5 !important;text-decoration:none !important}.kofitext img.kofiimg {height:15px!important;width:22px!important;display: initial;animation: kofi-wiggle 3s infinite;}";
|
| 17 |
+
style = style + "@keyframes kofi-wiggle{0%{transform:rotate(0) scale(1)}60%{transform:rotate(0) scale(1)}75%{transform:rotate(0) scale(1.12)}80%{transform:rotate(0) scale(1.1)}84%{transform:rotate(-10deg) scale(1.1)}88%{transform:rotate(10deg) scale(1.1)}92%{transform:rotate(-10deg) scale(1.1)}96%{transform:rotate(10deg) scale(1.1)}100%{transform:rotate(0) scale(1)}}";
|
| 18 |
+
style = "<style>" + style + "</style>";
|
| 19 |
+
html =
|
| 20 |
+
"<link href='https://fonts.googleapis.com/css?family=Quicksand:400,700' rel='stylesheet' type='text/css'>";
|
| 21 |
+
html +=
|
| 22 |
+
'<div class=btn-container><a title="Support me on ko-fi.com" class="kofi-button" style="background-color:[color]; text-decoration: none;" href="https://ko-fi.com/[id]" target="_blank"> <span class="kofitext"><img src="https://storage.ko-fi.com/cdn/cup-border.png" alt="Ko-fi donations" class="kofiimg"/>[text]</span></a></div>';
|
| 23 |
+
},
|
| 24 |
+
getHTML: function () {
|
| 25 |
+
var rtn = style + html.replace("[color]", color).replace("[text]", text).replace("[id]", id);
|
| 26 |
+
return rtn;
|
| 27 |
+
},
|
| 28 |
+
draw: function () {
|
| 29 |
+
document.writeln(style + html.replace("[color]", color).replace("[text]", text).replace("[id]", id));
|
| 30 |
+
}
|
| 31 |
+
};
|
| 32 |
+
}());
|
| 33 |
+
const checkElement = setInterval(() => {
|
| 34 |
+
const kofiDiv = document.getElementById('kofi');
|
| 35 |
+
if (kofiDiv) {
|
| 36 |
+
clearInterval(checkElement);
|
| 37 |
+
kofiwidget2.init('Buy me a coffee', '#f87316', 'Y8Y0STZND');
|
| 38 |
+
kofiDiv.innerHTML = kofiwidget2.getHTML();
|
| 39 |
+
}
|
| 40 |
+
}, 100);
|
| 41 |
+
}
|
| 42 |
+
"""
|