Spaces:
Running
on
Zero
Running
on
Zero
Update app.py (#3)
Browse files- Update app.py (aaf793d29adebed6d08998e3e918227a76a31c44)
Co-authored-by: Kun Yan <[email protected]>
app.py
CHANGED
@@ -4,6 +4,7 @@ import random
|
|
4 |
|
5 |
from PIL import Image
|
6 |
|
|
|
7 |
from http import HTTPStatus
|
8 |
from urllib.parse import urlparse, unquote
|
9 |
from pathlib import PurePosixPath
|
@@ -30,7 +31,7 @@ def get_image_size(aspect_ratio):
|
|
30 |
else:
|
31 |
return 1328, 1328
|
32 |
|
33 |
-
|
34 |
def infer(
|
35 |
prompt,
|
36 |
negative_prompt=" ",
|
@@ -44,7 +45,7 @@ def infer(
|
|
44 |
if randomize_seed:
|
45 |
seed = random.randint(0, MAX_SEED)
|
46 |
width, height = get_image_size(aspect_ratio)
|
47 |
-
|
48 |
rsp = ImageSynthesis.call(api_key=os.environ.get("DASH_API_KEY"),
|
49 |
model="qwen-image",
|
50 |
prompt=prompt,
|
@@ -155,7 +156,7 @@ with gr.Blocks(css=css) as demo:
|
|
155 |
value=50,
|
156 |
)
|
157 |
|
158 |
-
gr.Examples(examples=examples, inputs=[prompt], outputs=[result, seed], fn=infer, cache_examples=
|
159 |
gr.on(
|
160 |
triggers=[run_button.click, prompt.submit],
|
161 |
fn=infer,
|
|
|
4 |
|
5 |
from PIL import Image
|
6 |
|
7 |
+
import spaces
|
8 |
from http import HTTPStatus
|
9 |
from urllib.parse import urlparse, unquote
|
10 |
from pathlib import PurePosixPath
|
|
|
31 |
else:
|
32 |
return 1328, 1328
|
33 |
|
34 |
+
@spaces.GPU(duration=65)
|
35 |
def infer(
|
36 |
prompt,
|
37 |
negative_prompt=" ",
|
|
|
45 |
if randomize_seed:
|
46 |
seed = random.randint(0, MAX_SEED)
|
47 |
width, height = get_image_size(aspect_ratio)
|
48 |
+
print("calling with prompt: %s" % prompt)
|
49 |
rsp = ImageSynthesis.call(api_key=os.environ.get("DASH_API_KEY"),
|
50 |
model="qwen-image",
|
51 |
prompt=prompt,
|
|
|
156 |
value=50,
|
157 |
)
|
158 |
|
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=infer,
|