Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions imaginepy/async_imagine.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ async def close(self):

async def _request(self, **kwargs) -> Response:
headers = {"accept": "*/*", "user-agent": "okhttp/4.10.0"}
headers.update(kwargs.get("headers") or {})
headers |= (kwargs.get("headers") or {})

data = clear_dict(kwargs.get("data"))
if data:
prompt = data.get("prompt", "").lower().split(" ")
if prompt:
if prompt := data.get("prompt", "").lower().split(" "):
Comment on lines -36 to +40
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AsyncImagine._request refactored with the following changes:

for i, word in enumerate(prompt):
word = re.sub(r'[^a-zA-Z]', "", word)
if word in BANNED_WORDS:
Expand Down Expand Up @@ -76,8 +75,7 @@ async def _request(self, **kwargs) -> Response:
return r

async def thumb(self, item: Union[Model, Style, Inspiration, Mode]) -> bytes:
href = item.value[2 if isinstance(
item, Model) or isinstance(item, Style) else 1]
href = item.value[2 if isinstance(item, (Model, Style)) else 1]
Comment on lines -79 to +78
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AsyncImagine.thumb refactored with the following changes:

async with httpx.AsyncClient() as client:
response = await client.get(f"{self.cdn}/{href}")
response.raise_for_status()
Expand Down Expand Up @@ -113,7 +111,7 @@ async def variate(
"image": ("image.jpeg", content, "image/jpg")
}
)
if asbase64 == True:
if asbase64:
Comment on lines -116 to +114
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AsyncImagine.variate refactored with the following changes:

return pybase64.b64encode(response.content).decode('utf-8')
else:
return bytes2png(response.content)
Expand Down Expand Up @@ -152,7 +150,7 @@ async def sdprem(
"steps": get_steps(steps)
}
)
if asbase64 == True:
if asbase64:
Comment on lines -155 to +153
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AsyncImagine.sdprem refactored with the following changes:

return pybase64.b64encode(response.content).decode('utf-8')
else:
return bytes2png(response.content)
Expand All @@ -170,7 +168,7 @@ async def upscale(self, content: bytes, asbase64: bool = False) -> bytes:
"image": ("_", content, "image/jpg")
}
)
if asbase64 == True:
if asbase64:
Comment on lines -173 to +171
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AsyncImagine.upscale refactored with the following changes:

return pybase64.b64encode(response.content).decode('utf-8')
else:
return bytes2png(response.content)
Expand Down Expand Up @@ -239,7 +237,7 @@ async def sdimg(
"priority": int(priority)
}
)
if asbase64 == True:
if asbase64:
Comment on lines -242 to +240
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AsyncImagine.sdimg refactored with the following changes:

return pybase64.b64encode(response.content).decode('utf-8')
else:
return bytes2png(response.content)
Expand Down Expand Up @@ -276,7 +274,7 @@ async def controlnet(
"image": ("temp_314.1353898439128.jpg", content, "image/jpg")
}
)
if asbase64 == True:
if asbase64:
Comment on lines -279 to +277
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AsyncImagine.controlnet refactored with the following changes:

return pybase64.b64encode(response.content).decode('utf-8')
else:
return bytes2png(response.content)
Expand All @@ -294,7 +292,7 @@ async def codeformer(self, content: bytes, asbase64: bool = False) -> bytes:
"image": ("tempImage.jpg", content, "image/jpg")
}
)
if asbase64 == True:
if asbase64:
Comment on lines -297 to +295
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AsyncImagine.codeformer refactored with the following changes:

return pybase64.b64encode(response.content).decode('utf-8')
else:
return bytes2png(response.content)
Expand Down
20 changes: 9 additions & 11 deletions imaginepy/sync_imagine.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ def __init__(self, restricted: bool = True):

def _request(self, **kwargs) -> Response:
headers = {"accept": "*/*", "user-agent": "okhttp/4.10.0"}
headers.update(kwargs.get("headers") or {})
headers |= (kwargs.get("headers") or {})

data = clear_dict(kwargs.get("data"))
if data:
prompt = data.get("prompt", "").lower().split(" ")
if prompt:
if prompt := data.get("prompt", "").lower().split(" "):
Comment on lines -32 to +36
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Imagine._request refactored with the following changes:

for i, word in enumerate(prompt):
word = re.sub(r'[^a-zA-Z]', "", word)
if word in BANNED_WORDS:
Expand Down Expand Up @@ -72,8 +71,7 @@ def _request(self, **kwargs) -> Response:
return r

def thumb(self, item: Union[Model, Style, Inspiration, Mode]) -> bytes:
href = item.value[2 if isinstance(
item, Model) or isinstance(item, Style) else 1]
href = item.value[2 if isinstance(item, (Model, Style)) else 1]
Comment on lines -75 to +74
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Imagine.thumb refactored with the following changes:

with httpx.Client() as client:
response = client.get(f"{self.cdn}/{href}")
response.raise_for_status()
Expand Down Expand Up @@ -109,7 +107,7 @@ def variate(
"image": ("image.jpeg", content, "image/jpg")
}
)
if asbase64 == True:
if asbase64:
Comment on lines -112 to +110
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Imagine.variate refactored with the following changes:

return pybase64.b64encode(response.content).decode('utf-8')
else:
return bytes2png(response.content)
Expand Down Expand Up @@ -148,7 +146,7 @@ def sdprem(
"steps": get_steps(steps)
}
)
if asbase64 == True:
if asbase64:
Comment on lines -151 to +149
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Imagine.sdprem refactored with the following changes:

return pybase64.b64encode(response.content).decode('utf-8')
else:
return bytes2png(response.content)
Expand All @@ -166,7 +164,7 @@ def upscale(self, content: bytes, asbase64: bool = False) -> bytes:
"image": ("_", content, "image/jpg")
}
)
if asbase64 == True:
if asbase64:
Comment on lines -169 to +167
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Imagine.upscale refactored with the following changes:

return pybase64.b64encode(response.content).decode('utf-8')
else:
return bytes2png(response.content)
Expand Down Expand Up @@ -235,7 +233,7 @@ def sdimg(
"priority": int(priority)
}
)
if asbase64 == True:
if asbase64:
Comment on lines -238 to +236
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Imagine.sdimg refactored with the following changes:

return pybase64.b64encode(response.content).decode('utf-8')
else:
return bytes2png(response.content)
Expand Down Expand Up @@ -272,7 +270,7 @@ def controlnet(
"image": ("temp_314.1353898439128.jpg", content, "image/jpg")
}
)
if asbase64 == True:
if asbase64:
Comment on lines -275 to +273
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Imagine.controlnet refactored with the following changes:

return pybase64.b64encode(response.content).decode('utf-8')
else:
return bytes2png(response.content)
Expand All @@ -290,7 +288,7 @@ def codeformer(self, content: bytes, asbase64: bool = False) -> bytes:
"image": ("tempImage.jpg", content, "image/jpg")
}
)
if asbase64 == True:
if asbase64:
Comment on lines -293 to +291
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Imagine.codeformer refactored with the following changes:

return pybase64.b64encode(response.content).decode('utf-8')
else:
return bytes2png(response.content)
Expand Down