-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from mrhan1993/support_imagemeta
Support image meta
- Loading branch information
Showing
13 changed files
with
4,222 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version = '0.4.0.3' | ||
version = '0.4.0.4' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
""" | ||
Image meta schema | ||
""" | ||
from typing import List | ||
|
||
from fooocus_version import version | ||
from pydantic import BaseModel | ||
|
||
|
||
class ImageMeta(BaseModel): | ||
""" | ||
Image meta data model | ||
""" | ||
|
||
metadata_scheme: str = "fooocus" | ||
|
||
base_model: str | ||
base_model_hash: str | ||
|
||
prompt: str | ||
full_prompt: List[str] | ||
prompt_expansion: str | ||
|
||
negative_prompt: str | ||
full_negative_prompt: List[str] | ||
|
||
performance: str | ||
|
||
style: str | ||
|
||
refiner_model: str = "None" | ||
refiner_switch: float = 0.5 | ||
|
||
loras: List[list] | ||
|
||
resolution: str | ||
|
||
sampler: str = "dpmpp_2m_sde_gpu" | ||
scheduler: str = "karras" | ||
seed: str | ||
adm_guidance: str | ||
guidance_scale: int | ||
sharpness: int | ||
steps: int | ||
|
||
version: str = version | ||
|
||
def __repr__(self): | ||
return "" | ||
|
||
|
||
def loras_parser(loras: list) -> list: | ||
""" | ||
Parse lora list | ||
""" | ||
return [ | ||
[ | ||
lora[0].rsplit('.', maxsplit=1)[:1][0], | ||
lora[1], | ||
"hash_not_calculated", | ||
] for lora in loras if lora[0] != 'None' and lora[0] is not None] | ||
|
||
|
||
def image_parse( | ||
async_tak: object, | ||
task: dict | ||
) -> dict | str: | ||
""" | ||
Parse image meta data | ||
Generate meta data for image from task and async task object | ||
Args: | ||
async_tak: async task obj | ||
task: task obj | ||
Returns: | ||
dict: image meta data | ||
""" | ||
req_param = async_tak.req_param | ||
meta = ImageMeta( | ||
metadata_scheme=req_param.meta_scheme, | ||
base_model=req_param.base_model_name.rsplit('.', maxsplit=1)[:1][0], | ||
base_model_hash='', | ||
prompt=req_param.prompt, | ||
full_prompt=task['positive'], | ||
prompt_expansion=task['expansion'], | ||
negative_prompt=req_param.negative_prompt, | ||
full_negative_prompt=task['negative'], | ||
performance=req_param.performance_selection, | ||
style=str(req_param.style_selections), | ||
refiner_model=req_param.refiner_model_name, | ||
refiner_switch=req_param.refiner_switch, | ||
loras=loras_parser(req_param.loras), | ||
resolution=str(tuple([int(n) for n in req_param.aspect_ratios_selection.split('*')])), | ||
sampler=req_param.advanced_params.sampler_name, | ||
scheduler=req_param.advanced_params.scheduler_name, | ||
seed=str(task['task_seed']), | ||
adm_guidance=str(( | ||
req_param.advanced_params.adm_scaler_positive, | ||
req_param.advanced_params.adm_scaler_negative, | ||
req_param.advanced_params.adm_scaler_end)), | ||
guidance_scale=req_param.guidance_scale, | ||
sharpness=req_param.sharpness, | ||
steps=-1, | ||
version=version | ||
) | ||
if meta.metadata_scheme not in ["fooocus", "a111"]: | ||
meta.metadata_scheme = "fooocus" | ||
if meta.metadata_scheme == "fooocus": | ||
meta_dict = meta.model_dump() | ||
for i, lora in enumerate(meta.loras): | ||
attr_name = f"lora_combined_{i+1}" | ||
lr = [str(x) for x in lora] | ||
meta_dict[attr_name] = f"{lr[0]} : {lr[1]}" | ||
else: | ||
meta_dict = meta.model_dump() | ||
return meta_dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.