-
Notifications
You must be signed in to change notification settings - Fork 14
/
app_async.py
38 lines (29 loc) · 1020 Bytes
/
app_async.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import asyncio
from imaginepy import AsyncImagine, Style, Ratio, Model, constants
async def main():
imagine = AsyncImagine()
img_data = imagine.sdprem(
prompt="Woman sitting on a table, looking at the sky, seen from behind",
style=Style.NO_STYLE,
ratio=Ratio.RATIO_16X9,
negative="",
seed=1000,
cfg=16,
model=Model.REALISTIC,
asbase64=False # default is false, putting it here as presentation.
)
if img_data is None:
print("An error occurred while generating the image.")
return
img_data = await imagine.upscale(image=img_data)
if img_data is None:
print("An error occurred while upscaling the image.")
return
try:
with open("example.png", mode="wb") as img_file:
img_file.write(img_data)
except Exception as e:
print(f"An error occurred while writing the image to file: {e}")
await imagine.close()
if __name__ == "__main__":
asyncio.run(main())