Spaces:
Runtime error
Runtime error
Test diffusers
Browse files
app.py
CHANGED
@@ -9,9 +9,23 @@ from http import HTTPStatus
|
|
9 |
from urllib.parse import urlparse, unquote
|
10 |
from pathlib import PurePosixPath
|
11 |
import requests
|
12 |
-
from dashscope import ImageSynthesis
|
13 |
import os
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
MAX_SEED = np.iinfo(np.int32).max
|
16 |
MAX_IMAGE_SIZE = 1440
|
17 |
|
@@ -31,6 +45,37 @@ def get_image_size(aspect_ratio):
|
|
31 |
else:
|
32 |
return 1328, 1328
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
@spaces.GPU(duration=65)
|
35 |
def infer(
|
36 |
prompt,
|
@@ -159,7 +204,7 @@ with gr.Blocks(css=css) as demo:
|
|
159 |
gr.Examples(examples=examples, inputs=[prompt], outputs=[result, seed], fn=infer, cache_examples=False, cache_mode="lazy")
|
160 |
gr.on(
|
161 |
triggers=[run_button.click, prompt.submit],
|
162 |
-
fn=
|
163 |
inputs=[
|
164 |
prompt,
|
165 |
negative_prompt,
|
|
|
9 |
from urllib.parse import urlparse, unquote
|
10 |
from pathlib import PurePosixPath
|
11 |
import requests
|
|
|
12 |
import os
|
13 |
|
14 |
+
from diffusers import DiffusionPipeline
|
15 |
+
import torch
|
16 |
+
|
17 |
+
model_name = "Qwen/Qwen-Image"
|
18 |
+
|
19 |
+
# Load the pipeline
|
20 |
+
if torch.cuda.is_available():
|
21 |
+
torch_dtype = torch.bfloat16
|
22 |
+
device = "cuda"
|
23 |
+
else:
|
24 |
+
torch_dtype = torch.float32
|
25 |
+
device = "cpu"
|
26 |
+
|
27 |
+
pipe = DiffusionPipeline.from_pretrained(model_name, torch_dtype=torch_dtype)
|
28 |
+
|
29 |
MAX_SEED = np.iinfo(np.int32).max
|
30 |
MAX_IMAGE_SIZE = 1440
|
31 |
|
|
|
45 |
else:
|
46 |
return 1328, 1328
|
47 |
|
48 |
+
@spaces.GPU(duration=60)
|
49 |
+
def infer_diffusers(
|
50 |
+
prompt,
|
51 |
+
negative_prompt=" ",
|
52 |
+
seed=42,
|
53 |
+
randomize_seed=False,
|
54 |
+
aspect_ratio="16:9",
|
55 |
+
guidance_scale=4,
|
56 |
+
num_inference_steps=50,
|
57 |
+
progress=gr.Progress(track_tqdm=True),
|
58 |
+
):
|
59 |
+
if randomize_seed:
|
60 |
+
seed = random.randint(0, MAX_SEED)
|
61 |
+
width, height = get_image_size(aspect_ratio)
|
62 |
+
|
63 |
+
print("Generating for prompt:", prompt)
|
64 |
+
pipe(
|
65 |
+
prompt=prompt,
|
66 |
+
negative_prompt=negative_prompt,
|
67 |
+
width=width,
|
68 |
+
height=height,
|
69 |
+
num_inference_steps=50,
|
70 |
+
true_cfg_scale=4.0,
|
71 |
+
generator=torch.Generator(device="cuda").manual_seed(42)
|
72 |
+
).images[0]
|
73 |
+
|
74 |
+
#image.save("example.png")
|
75 |
+
|
76 |
+
return image, seed
|
77 |
+
|
78 |
+
|
79 |
@spaces.GPU(duration=65)
|
80 |
def infer(
|
81 |
prompt,
|
|
|
204 |
gr.Examples(examples=examples, inputs=[prompt], outputs=[result, seed], fn=infer, cache_examples=False, cache_mode="lazy")
|
205 |
gr.on(
|
206 |
triggers=[run_button.click, prompt.submit],
|
207 |
+
fn=infer_diffusers,
|
208 |
inputs=[
|
209 |
prompt,
|
210 |
negative_prompt,
|