mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Improves metadata handling, fixes #1450
- Removes model list from metadata - Adds generation's specific model to metadata - Displays full metadata in JSON viewer
This commit is contained in:
parent
9418324030
commit
b908f2b4bc
@ -282,6 +282,7 @@ class InvokeAIWebServer:
|
|||||||
def handle_request_capabilities():
|
def handle_request_capabilities():
|
||||||
print(f">> System config requested")
|
print(f">> System config requested")
|
||||||
config = self.get_system_config()
|
config = self.get_system_config()
|
||||||
|
config["model_list"] = self.generate.model_cache.list_models()
|
||||||
socketio.emit("systemConfig", config)
|
socketio.emit("systemConfig", config)
|
||||||
|
|
||||||
@socketio.on("requestModelChange")
|
@socketio.on("requestModelChange")
|
||||||
@ -335,9 +336,10 @@ class InvokeAIWebServer:
|
|||||||
for path in image_paths:
|
for path in image_paths:
|
||||||
if os.path.splitext(path)[1] == ".png":
|
if os.path.splitext(path)[1] == ".png":
|
||||||
metadata = retrieve_metadata(path)
|
metadata = retrieve_metadata(path)
|
||||||
sd_metadata = metadata["sd-metadata"]
|
# sd_metadata = metadata["sd-metadata"]
|
||||||
else:
|
else:
|
||||||
sd_metadata = {}
|
# sd_metadata = {}
|
||||||
|
metadata = {}
|
||||||
|
|
||||||
pil_image = Image.open(path)
|
pil_image = Image.open(path)
|
||||||
(width, height) = pil_image.size
|
(width, height) = pil_image.size
|
||||||
@ -351,7 +353,8 @@ class InvokeAIWebServer:
|
|||||||
"url": self.get_url_from_image_path(path),
|
"url": self.get_url_from_image_path(path),
|
||||||
"thumbnail": self.get_url_from_image_path(thumbnail_path),
|
"thumbnail": self.get_url_from_image_path(thumbnail_path),
|
||||||
"mtime": os.path.getmtime(path),
|
"mtime": os.path.getmtime(path),
|
||||||
"metadata": sd_metadata,
|
"metadata": metadata,
|
||||||
|
# "metadata": sd_metadata,
|
||||||
"width": width,
|
"width": width,
|
||||||
"height": height,
|
"height": height,
|
||||||
"category": category,
|
"category": category,
|
||||||
@ -401,9 +404,10 @@ class InvokeAIWebServer:
|
|||||||
for path in image_paths:
|
for path in image_paths:
|
||||||
if os.path.splitext(path)[1] == ".png":
|
if os.path.splitext(path)[1] == ".png":
|
||||||
metadata = retrieve_metadata(path)
|
metadata = retrieve_metadata(path)
|
||||||
sd_metadata = metadata["sd-metadata"]
|
# sd_metadata = metadata["sd-metadata"]
|
||||||
else:
|
else:
|
||||||
sd_metadata = {}
|
# sd_metadata = {}
|
||||||
|
metadata = {}
|
||||||
|
|
||||||
pil_image = Image.open(path)
|
pil_image = Image.open(path)
|
||||||
(width, height) = pil_image.size
|
(width, height) = pil_image.size
|
||||||
@ -417,7 +421,8 @@ class InvokeAIWebServer:
|
|||||||
"url": self.get_url_from_image_path(path),
|
"url": self.get_url_from_image_path(path),
|
||||||
"thumbnail": self.get_url_from_image_path(thumbnail_path),
|
"thumbnail": self.get_url_from_image_path(thumbnail_path),
|
||||||
"mtime": os.path.getmtime(path),
|
"mtime": os.path.getmtime(path),
|
||||||
"metadata": sd_metadata,
|
# "metadata": sd_metadata,
|
||||||
|
"metadata": metadata,
|
||||||
"width": width,
|
"width": width,
|
||||||
"height": height,
|
"height": height,
|
||||||
"category": category,
|
"category": category,
|
||||||
@ -492,12 +497,10 @@ class InvokeAIWebServer:
|
|||||||
|
|
||||||
image = Image.open(original_image_path)
|
image = Image.open(original_image_path)
|
||||||
|
|
||||||
seed = (
|
try:
|
||||||
original_image["metadata"]["seed"]
|
seed = original_image["metadata"]["image"]["seed"]
|
||||||
if "metadata" in original_image
|
except (NameError, AttributeError) as e:
|
||||||
and "seed" in original_image["metadata"]
|
seed = "unknown_seed"
|
||||||
else "unknown_seed"
|
|
||||||
)
|
|
||||||
|
|
||||||
if postprocessing_parameters["type"] == "esrgan":
|
if postprocessing_parameters["type"] == "esrgan":
|
||||||
progress.set_current_status("Upscaling (ESRGAN)")
|
progress.set_current_status("Upscaling (ESRGAN)")
|
||||||
@ -620,14 +623,19 @@ class InvokeAIWebServer:
|
|||||||
|
|
||||||
# App Functions
|
# App Functions
|
||||||
def get_system_config(self):
|
def get_system_config(self):
|
||||||
model_list = self.generate.model_cache.list_models()
|
model_list: dict = self.generate.model_cache.list_models()
|
||||||
|
active_model_name = None
|
||||||
|
|
||||||
|
for model_name, model_dict in model_list.items():
|
||||||
|
if model_dict["status"] == "active":
|
||||||
|
active_model_name = model_name
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"model": "stable diffusion",
|
"model": "stable diffusion",
|
||||||
"model_id": args.model,
|
"model_weights": active_model_name,
|
||||||
"model_hash": self.generate.model_hash,
|
"model_hash": self.generate.model_hash,
|
||||||
"app_id": APP_ID,
|
"app_id": APP_ID,
|
||||||
"app_version": APP_VERSION,
|
"app_version": APP_VERSION,
|
||||||
"model_list": model_list,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def generate_images(
|
def generate_images(
|
||||||
|
10
frontend/src/app/invokeai.d.ts
vendored
10
frontend/src/app/invokeai.d.ts
vendored
@ -105,7 +105,7 @@ export declare type PostProcessedImageMetadata =
|
|||||||
| FacetoolMetadata;
|
| FacetoolMetadata;
|
||||||
|
|
||||||
// Metadata includes the system config and image metadata.
|
// Metadata includes the system config and image metadata.
|
||||||
export declare type Metadata = SystemConfig & {
|
export declare type Metadata = SystemGenerationMetadata & {
|
||||||
image: GeneratedImageMetadata | PostProcessedImageMetadata;
|
image: GeneratedImageMetadata | PostProcessedImageMetadata;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -143,12 +143,16 @@ export declare type SystemStatus = {
|
|||||||
hasError: boolean;
|
hasError: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export declare type SystemConfig = {
|
export declare type SystemGenerationMetadata = {
|
||||||
model: string;
|
model: string;
|
||||||
model_id: string;
|
model_weights?: string;
|
||||||
|
model_id?: string;
|
||||||
model_hash: string;
|
model_hash: string;
|
||||||
app_id: string;
|
app_id: string;
|
||||||
app_version: string;
|
app_version: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export declare type SystemConfig = SystemGenerationMetadata & {
|
||||||
model_list: ModelList;
|
model_list: ModelList;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ const ImageMetadataViewer = memo(
|
|||||||
scale,
|
scale,
|
||||||
} = metadata;
|
} = metadata;
|
||||||
|
|
||||||
const metadataJSON = JSON.stringify(metadata, null, 2);
|
const metadataJSON = JSON.stringify(image.metadata, null, 2);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`image-metadata-viewer ${styleClass}`}>
|
<div className={`image-metadata-viewer ${styleClass}`}>
|
||||||
@ -153,6 +153,12 @@ const ImageMetadataViewer = memo(
|
|||||||
{Object.keys(metadata).length > 0 ? (
|
{Object.keys(metadata).length > 0 ? (
|
||||||
<>
|
<>
|
||||||
{type && <MetadataItem label="Generation type" value={type} />}
|
{type && <MetadataItem label="Generation type" value={type} />}
|
||||||
|
{image.metadata?.model_weights && (
|
||||||
|
<MetadataItem
|
||||||
|
label="Model"
|
||||||
|
value={image.metadata.model_weights}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{['esrgan', 'gfpgan'].includes(type) && (
|
{['esrgan', 'gfpgan'].includes(type) && (
|
||||||
<MetadataItem label="Original image" value={orig_path} />
|
<MetadataItem label="Original image" value={orig_path} />
|
||||||
)}
|
)}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user