-
Notifications
You must be signed in to change notification settings - Fork 15
Sourcery Starbot ⭐ refactored ItsCEED/Imaginepy #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(" "): | ||
| for i, word in enumerate(prompt): | ||
| word = re.sub(r'[^a-zA-Z]', "", word) | ||
| if word in BANNED_WORDS: | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| async with httpx.AsyncClient() as client: | ||
| response = await client.get(f"{self.cdn}/{href}") | ||
| response.raise_for_status() | ||
|
|
@@ -113,7 +111,7 @@ async def variate( | |
| "image": ("image.jpeg", content, "image/jpg") | ||
| } | ||
| ) | ||
| if asbase64 == True: | ||
| if asbase64: | ||
|
Comment on lines
-116
to
+114
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return pybase64.b64encode(response.content).decode('utf-8') | ||
| else: | ||
| return bytes2png(response.content) | ||
|
|
@@ -152,7 +150,7 @@ async def sdprem( | |
| "steps": get_steps(steps) | ||
| } | ||
| ) | ||
| if asbase64 == True: | ||
| if asbase64: | ||
|
Comment on lines
-155
to
+153
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return pybase64.b64encode(response.content).decode('utf-8') | ||
| else: | ||
| return bytes2png(response.content) | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return pybase64.b64encode(response.content).decode('utf-8') | ||
| else: | ||
| return bytes2png(response.content) | ||
|
|
@@ -239,7 +237,7 @@ async def sdimg( | |
| "priority": int(priority) | ||
| } | ||
| ) | ||
| if asbase64 == True: | ||
| if asbase64: | ||
|
Comment on lines
-242
to
+240
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return pybase64.b64encode(response.content).decode('utf-8') | ||
| else: | ||
| return bytes2png(response.content) | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return pybase64.b64encode(response.content).decode('utf-8') | ||
| else: | ||
| return bytes2png(response.content) | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return pybase64.b64encode(response.content).decode('utf-8') | ||
| else: | ||
| return bytes2png(response.content) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| for i, word in enumerate(prompt): | ||
| word = re.sub(r'[^a-zA-Z]', "", word) | ||
| if word in BANNED_WORDS: | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| with httpx.Client() as client: | ||
| response = client.get(f"{self.cdn}/{href}") | ||
| response.raise_for_status() | ||
|
|
@@ -109,7 +107,7 @@ def variate( | |
| "image": ("image.jpeg", content, "image/jpg") | ||
| } | ||
| ) | ||
| if asbase64 == True: | ||
| if asbase64: | ||
|
Comment on lines
-112
to
+110
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return pybase64.b64encode(response.content).decode('utf-8') | ||
| else: | ||
| return bytes2png(response.content) | ||
|
|
@@ -148,7 +146,7 @@ def sdprem( | |
| "steps": get_steps(steps) | ||
| } | ||
| ) | ||
| if asbase64 == True: | ||
| if asbase64: | ||
|
Comment on lines
-151
to
+149
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return pybase64.b64encode(response.content).decode('utf-8') | ||
| else: | ||
| return bytes2png(response.content) | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return pybase64.b64encode(response.content).decode('utf-8') | ||
| else: | ||
| return bytes2png(response.content) | ||
|
|
@@ -235,7 +233,7 @@ def sdimg( | |
| "priority": int(priority) | ||
| } | ||
| ) | ||
| if asbase64 == True: | ||
| if asbase64: | ||
|
Comment on lines
-238
to
+236
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return pybase64.b64encode(response.content).decode('utf-8') | ||
| else: | ||
| return bytes2png(response.content) | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return pybase64.b64encode(response.content).decode('utf-8') | ||
| else: | ||
| return bytes2png(response.content) | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return pybase64.b64encode(response.content).decode('utf-8') | ||
| else: | ||
| return bytes2png(response.content) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
AsyncImagine._requestrefactored with the following changes:dict-assign-update-to-union)use-named-expression)