Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import spaces
|
| 3 |
from dataclasses import dataclass
|
| 4 |
|
| 5 |
import gradio as gr
|
|
@@ -730,7 +730,7 @@ print(result)
|
|
| 730 |
# model = Flux().to(dtype=torch.bfloat16, device="cuda")
|
| 731 |
# result = model.load_state_dict(load_file("/storage/dev/nyanko/flux-dev/flux1-dev.sft"))
|
| 732 |
|
| 733 |
-
@spaces.GPU
|
| 734 |
@torch.inference_mode()
|
| 735 |
def generate_image(
|
| 736 |
prompt, width, height, guidance, seed,
|
|
@@ -767,12 +767,13 @@ def generate_image(
|
|
| 767 |
timesteps = timesteps[t_idx:]
|
| 768 |
x = t * x + (1.0 - t) * init_image.to(x.dtype)
|
| 769 |
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
|
|
|
| 776 |
|
| 777 |
x = x.clamp(-1, 1)
|
| 778 |
x = rearrange(x[0], "c h w -> h w c")
|
|
|
|
| 1 |
+
# import os
|
| 2 |
+
# import spaces
|
| 3 |
from dataclasses import dataclass
|
| 4 |
|
| 5 |
import gradio as gr
|
|
|
|
| 730 |
# model = Flux().to(dtype=torch.bfloat16, device="cuda")
|
| 731 |
# result = model.load_state_dict(load_file("/storage/dev/nyanko/flux-dev/flux1-dev.sft"))
|
| 732 |
|
| 733 |
+
# @spaces.GPU
|
| 734 |
@torch.inference_mode()
|
| 735 |
def generate_image(
|
| 736 |
prompt, width, height, guidance, seed,
|
|
|
|
| 767 |
timesteps = timesteps[t_idx:]
|
| 768 |
x = t * x + (1.0 - t) * init_image.to(x.dtype)
|
| 769 |
|
| 770 |
+
with torch_device:
|
| 771 |
+
inp = prepare(t5=t5, clip=clip, img=x, prompt=prompt)
|
| 772 |
+
x = denoise(model, **inp, timesteps=timesteps, guidance=guidance)
|
| 773 |
+
x = unpack(x.float(), height, width)
|
| 774 |
+
with torch.autocast(device_type=torch_device.type, dtype=torch.bfloat16):
|
| 775 |
+
x = x = (x / ae.config.scaling_factor) + ae.config.shift_factor
|
| 776 |
+
x = ae.decode(x).sample
|
| 777 |
|
| 778 |
x = x.clamp(-1, 1)
|
| 779 |
x = rearrange(x[0], "c h w -> h w c")
|