|
|
@ -19,6 +19,7 @@ async def generate_sync( |
|
|
|
prompt: str, |
|
|
|
api_key: str, |
|
|
|
bot, |
|
|
|
typing_fn |
|
|
|
): |
|
|
|
# Set the API endpoint URL |
|
|
|
endpoint = "https://api.runpod.ai/v2/pygmalion-6b/run" |
|
|
@ -61,6 +62,7 @@ async def generate_sync( |
|
|
|
logger.info(r_json) |
|
|
|
status = r_json["status"] |
|
|
|
if status == 'IN_PROGRESS': |
|
|
|
await typing_fn() |
|
|
|
await asyncio.sleep(DELAY) |
|
|
|
elif status == 'IN_QUEUE': |
|
|
|
await asyncio.sleep(DELAY) |
|
|
@ -157,7 +159,7 @@ async def download_image(url, path): |
|
|
|
for chunk in r: |
|
|
|
f.write(chunk) |
|
|
|
|
|
|
|
async def generate_image(input_prompt: str, negative_prompt: str, api_url: str, api_key: str): |
|
|
|
async def generate_image(input_prompt: str, negative_prompt: str, api_url: str, api_key: str, typing_fn): |
|
|
|
|
|
|
|
# Set the API endpoint URL |
|
|
|
endpoint = api_url + "run" |
|
|
@ -203,6 +205,7 @@ async def generate_image(input_prompt: str, negative_prompt: str, api_url: str, |
|
|
|
logger.debug(r_json) |
|
|
|
status = r_json["status"] |
|
|
|
if status == 'IN_PROGRESS': |
|
|
|
await typing_fn() |
|
|
|
await asyncio.sleep(DELAY) |
|
|
|
elif status == 'IN_QUEUE': |
|
|
|
await asyncio.sleep(DELAY) |
|
|
@ -226,25 +229,25 @@ async def generate_image(input_prompt: str, negative_prompt: str, api_url: str, |
|
|
|
|
|
|
|
return files |
|
|
|
|
|
|
|
async def generate_image1(input_prompt: str, negative_prompt: str, api_key: str): |
|
|
|
return await generate_image(input_prompt, negative_prompt, "https://api.runpod.ai/v1/sd-anything-v4/", api_key) |
|
|
|
async def generate_image1(input_prompt: str, negative_prompt: str, api_key: str, typing_fn): |
|
|
|
return await generate_image(input_prompt, negative_prompt, "https://api.runpod.ai/v1/sd-anything-v4/", api_key, typing_fn) |
|
|
|
|
|
|
|
async def generate_image2(input_prompt: str, negative_prompt: str, api_key: str): |
|
|
|
return await generate_image(input_prompt, negative_prompt, "https://api.runpod.ai/v1/sd-openjourney/", api_key) |
|
|
|
async def generate_image2(input_prompt: str, negative_prompt: str, api_key: str, typing_fn): |
|
|
|
return await generate_image(input_prompt, negative_prompt, "https://api.runpod.ai/v1/sd-openjourney/", api_key, typing_fn) |
|
|
|
|
|
|
|
async def generate_image3(input_prompt: str, negative_prompt: str, api_key: str): |
|
|
|
return await generate_image(input_prompt, negative_prompt, "https://api.runpod.ai/v1/mf5f6mocy8bsvx/", api_key) |
|
|
|
async def generate_image3(input_prompt: str, negative_prompt: str, api_key: str, typing_fn): |
|
|
|
return await generate_image(input_prompt, negative_prompt, "https://api.runpod.ai/v1/mf5f6mocy8bsvx/", api_key, typing_fn) |
|
|
|
|
|
|
|
async def generate_image4(input_prompt: str, negative_prompt: str, api_key: str): |
|
|
|
return await generate_image_automatic(input_prompt, negative_prompt, "https://api.runpod.ai/v1/lxdhmiccp3vdsf/", api_key) |
|
|
|
async def generate_image4(input_prompt: str, negative_prompt: str, api_key: str, typing_fn): |
|
|
|
return await generate_image_automatic(input_prompt, negative_prompt, "https://api.runpod.ai/v1/lxdhmiccp3vdsf/", api_key, typing_fn) |
|
|
|
|
|
|
|
async def generate_image5(input_prompt: str, negative_prompt: str, api_key: str): |
|
|
|
return await generate_image_automatic(input_prompt, negative_prompt, "https://api.runpod.ai/v1/13rrs00l7yxikf/", api_key) |
|
|
|
async def generate_image5(input_prompt: str, negative_prompt: str, api_key: str, typing_fn): |
|
|
|
return await generate_image_automatic(input_prompt, negative_prompt, "https://api.runpod.ai/v1/13rrs00l7yxikf/", api_key, typing_fn) |
|
|
|
|
|
|
|
async def generate_image6(input_prompt: str, negative_prompt: str, api_key: str): |
|
|
|
return await generate_image_automatic(input_prompt, negative_prompt, "https://api.runpod.ai/v1/5j1xzlsyw84vk5/", api_key) |
|
|
|
async def generate_image6(input_prompt: str, negative_prompt: str, api_key: str, typing_fn): |
|
|
|
return await generate_image_automatic(input_prompt, negative_prompt, "https://api.runpod.ai/v1/5j1xzlsyw84vk5/", api_key, typing_fn) |
|
|
|
|
|
|
|
async def serverless_automatic_request(payload, cmd, api_url: str, api_key: str): |
|
|
|
async def serverless_automatic_request(payload, cmd, api_url: str, api_key: str, typing_fn): |
|
|
|
# Set the API endpoint URL |
|
|
|
endpoint = api_url + "run" |
|
|
|
|
|
|
@ -284,6 +287,7 @@ async def serverless_automatic_request(payload, cmd, api_url: str, api_key: str) |
|
|
|
logger.debug(r_json) |
|
|
|
status = r_json["status"] |
|
|
|
if status == 'IN_PROGRESS': |
|
|
|
await typing_fn() |
|
|
|
await asyncio.sleep(DELAY) |
|
|
|
elif status == 'IN_QUEUE': |
|
|
|
await asyncio.sleep(DELAY) |
|
|
@ -300,7 +304,7 @@ async def serverless_automatic_request(payload, cmd, api_url: str, api_key: str) |
|
|
|
return output |
|
|
|
|
|
|
|
|
|
|
|
async def generate_image_automatic(input_prompt: str, negative_prompt: str, api_url: str, api_key: str): |
|
|
|
async def generate_image_automatic(input_prompt: str, negative_prompt: str, api_url: str, api_key: str, typing_fn): |
|
|
|
payload = { |
|
|
|
"prompt": input_prompt, |
|
|
|
"nagative_prompt": negative_prompt, |
|
|
@ -321,7 +325,7 @@ async def generate_image_automatic(input_prompt: str, negative_prompt: str, api_ |
|
|
|
## }, |
|
|
|
} |
|
|
|
|
|
|
|
output = await serverless_automatic_request(payload, "txt2img", api_url, api_key) |
|
|
|
output = await serverless_automatic_request(payload, "txt2img", api_url, api_key, typing_fn) |
|
|
|
|
|
|
|
upscale = False |
|
|
|
if upscale: |
|
|
@ -337,7 +341,7 @@ async def generate_image_automatic(input_prompt: str, negative_prompt: str, api_ |
|
|
|
# "script_args": ["",512,0,8,32,64,0.275,32,3,False,0,True,8,3,2,1080,1440,1.875], |
|
|
|
# "script_name": "Ultimate SD upscale", |
|
|
|
} |
|
|
|
upscaled_output = await serverless_automatic_request(payload, "img2img", api_url, api_key) |
|
|
|
upscaled_output = await serverless_automatic_request(payload, "img2img", api_url, api_key, typing_fn) |
|
|
|
output['images'][count] = upscaled_output['images'][count] |
|
|
|
|
|
|
|
os.makedirs("./images", exist_ok=True) |
|
|
|