Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -66,16 +66,19 @@ async def infer(model_str, prompt, nprompt="", height=0, width=0, steps=0, cfg=0
|
|
66 |
if steps > 0: kwargs["num_inference_steps"] = steps
|
67 |
if cfg > 0: cfg = kwargs["guidance_scale"] = cfg
|
68 |
|
|
|
69 |
if seed == -1:
|
70 |
theSeed = randomize_seed()
|
71 |
else:
|
72 |
theSeed = seed
|
73 |
kwargs["seed"] = theSeed
|
74 |
|
|
|
75 |
task = asyncio.create_task(asyncio.to_thread(models_load[model_str].fn, prompt=prompt, negative_prompt=nprompt, **kwargs, token=HF_TOKEN))
|
76 |
await asyncio.sleep(0)
|
77 |
try:
|
78 |
result = await asyncio.wait_for(task, timeout=timeout)
|
|
|
79 |
except asyncio.TimeoutError as e:
|
80 |
print(e)
|
81 |
print(f"infer: Task timed out: {model_str}")
|
@@ -93,6 +96,8 @@ async def infer(model_str, prompt, nprompt="", height=0, width=0, steps=0, cfg=0
|
|
93 |
png_path = model_str.replace("/", "_") + " - " + get_current_time() + "_" + str(theSeed) + ".png"
|
94 |
image = save_image(result, png_path, model_str, prompt, nprompt, height, width, steps, cfg, theSeed)
|
95 |
return image
|
|
|
|
|
96 |
return None
|
97 |
|
98 |
def gen_fn(model_str, prompt, nprompt="", height=0, width=0, steps=0, cfg=0, seed=-1):
|
|
|
66 |
if steps > 0: kwargs["num_inference_steps"] = steps
|
67 |
if cfg > 0: cfg = kwargs["guidance_scale"] = cfg
|
68 |
|
69 |
+
print(f"infer: model '{model_str}', prompt: '{prompt}'...")
|
70 |
if seed == -1:
|
71 |
theSeed = randomize_seed()
|
72 |
else:
|
73 |
theSeed = seed
|
74 |
kwargs["seed"] = theSeed
|
75 |
|
76 |
+
print("Create task...")
|
77 |
task = asyncio.create_task(asyncio.to_thread(models_load[model_str].fn, prompt=prompt, negative_prompt=nprompt, **kwargs, token=HF_TOKEN))
|
78 |
await asyncio.sleep(0)
|
79 |
try:
|
80 |
result = await asyncio.wait_for(task, timeout=timeout)
|
81 |
+
print(f"Task ended, result: {result}")
|
82 |
except asyncio.TimeoutError as e:
|
83 |
print(e)
|
84 |
print(f"infer: Task timed out: {model_str}")
|
|
|
96 |
png_path = model_str.replace("/", "_") + " - " + get_current_time() + "_" + str(theSeed) + ".png"
|
97 |
image = save_image(result, png_path, model_str, prompt, nprompt, height, width, steps, cfg, theSeed)
|
98 |
return image
|
99 |
+
else:
|
100 |
+
print(f"Else, no valid result...: result '{result}'")
|
101 |
return None
|
102 |
|
103 |
def gen_fn(model_str, prompt, nprompt="", height=0, width=0, steps=0, cfg=0, seed=-1):
|