mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-06-30 06:21:16 -03:00
Compare commits
2 Commits
451f74b874
...
7cbddd9cf7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7cbddd9cf7 | ||
|
|
cb8c699224 |
File diff suppressed because one or more lines are too long
@@ -907,6 +907,7 @@ class RecipeManagementHandler:
|
|||||||
extension,
|
extension,
|
||||||
civitai_meta_raw,
|
civitai_meta_raw,
|
||||||
model_version_id,
|
model_version_id,
|
||||||
|
_original_image_url,
|
||||||
) = await self._download_remote_media(image_url)
|
) = await self._download_remote_media(image_url)
|
||||||
|
|
||||||
# Extract embedded EXIF metadata (offloaded to thread pool in this call)
|
# Extract embedded EXIF metadata (offloaded to thread pool in this call)
|
||||||
@@ -1319,7 +1320,9 @@ class RecipeManagementHandler:
|
|||||||
"exclude": False,
|
"exclude": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
async def _download_remote_media(self, image_url: str) -> tuple[bytes, str, Any, Any]:
|
async def _download_remote_media(
|
||||||
|
self, image_url: str
|
||||||
|
) -> tuple[bytes, str, Any, Any, Optional[str]]:
|
||||||
civitai_client = self._civitai_client_getter()
|
civitai_client = self._civitai_client_getter()
|
||||||
downloader = await self._downloader_factory()
|
downloader = await self._downloader_factory()
|
||||||
temp_path = None
|
temp_path = None
|
||||||
@@ -1394,11 +1397,16 @@ class RecipeManagementHandler:
|
|||||||
if mvids and isinstance(civitai_meta_raw, dict):
|
if mvids and isinstance(civitai_meta_raw, dict):
|
||||||
civitai_meta_raw["modelVersionIds"] = mvids
|
civitai_meta_raw["modelVersionIds"] = mvids
|
||||||
|
|
||||||
|
original_url = (
|
||||||
|
image_info.get("url") if civitai_image_id and image_info else None
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
file_obj.read(),
|
file_obj.read(),
|
||||||
extension,
|
extension,
|
||||||
civitai_meta_raw,
|
civitai_meta_raw,
|
||||||
model_ver_id,
|
model_ver_id,
|
||||||
|
original_url,
|
||||||
)
|
)
|
||||||
except RecipeDownloadError:
|
except RecipeDownloadError:
|
||||||
raise
|
raise
|
||||||
@@ -1550,7 +1558,7 @@ class RecipeManagementHandler:
|
|||||||
"Could not extract Civitai image ID from URL"
|
"Could not extract Civitai image ID from URL"
|
||||||
)
|
)
|
||||||
|
|
||||||
image_bytes, extension, civitai_meta_raw, model_version_id = (
|
image_bytes, extension, civitai_meta_raw, model_version_id, original_image_url = (
|
||||||
await self._download_remote_media(image_url)
|
await self._download_remote_media(image_url)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1588,6 +1596,51 @@ class RecipeManagementHandler:
|
|||||||
"Failed to extract embedded metadata: %s", exc
|
"Failed to extract embedded metadata: %s", exc
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not parsed_embedded and original_image_url:
|
||||||
|
self._logger.debug(
|
||||||
|
"Optimized image has no embedded metadata, "
|
||||||
|
"falling back to original: %s",
|
||||||
|
original_image_url,
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
downloader = await self._downloader_factory()
|
||||||
|
with tempfile.NamedTemporaryFile(
|
||||||
|
suffix=".png", delete=False
|
||||||
|
) as tmp:
|
||||||
|
orig_tmp_path = tmp.name
|
||||||
|
try:
|
||||||
|
success, _ = await downloader.download_file(
|
||||||
|
original_image_url, orig_tmp_path, use_auth=False
|
||||||
|
)
|
||||||
|
if success:
|
||||||
|
raw_orig = await asyncio.to_thread(
|
||||||
|
ExifUtils.extract_image_metadata, orig_tmp_path
|
||||||
|
)
|
||||||
|
if raw_orig:
|
||||||
|
parser = (
|
||||||
|
self._analysis_service._recipe_parser_factory.create_parser(
|
||||||
|
raw_orig
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if parser:
|
||||||
|
parsed_embedded = await parser.parse_metadata(
|
||||||
|
raw_orig, recipe_scanner=recipe_scanner
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
parsed_embedded
|
||||||
|
and "gen_params" in parsed_embedded
|
||||||
|
):
|
||||||
|
embedded_gen_params = parsed_embedded[
|
||||||
|
"gen_params"
|
||||||
|
]
|
||||||
|
finally:
|
||||||
|
if os.path.exists(orig_tmp_path):
|
||||||
|
os.unlink(orig_tmp_path)
|
||||||
|
except Exception as exc:
|
||||||
|
self._logger.warning(
|
||||||
|
"Failed to extract metadata from original image: %s", exc
|
||||||
|
)
|
||||||
|
|
||||||
# Parse CivitAI API meta to discover all resources from modelVersionIds.
|
# Parse CivitAI API meta to discover all resources from modelVersionIds.
|
||||||
# Run unconditionally — EXIF parsing succeeds for gen_params but misses
|
# Run unconditionally — EXIF parsing succeeds for gen_params but misses
|
||||||
# LoRAs (modelVersionIds is NOT in the image EXIF).
|
# LoRAs (modelVersionIds is NOT in the image EXIF).
|
||||||
|
|||||||
@@ -176,6 +176,24 @@ class RecipeAnalysisService:
|
|||||||
self._exif_utils.extract_image_metadata, temp_path
|
self._exif_utils.extract_image_metadata, temp_path
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not metadata and civitai_image_id and image_info:
|
||||||
|
original_url = image_info.get("url")
|
||||||
|
if original_url:
|
||||||
|
self._logger.debug(
|
||||||
|
"Optimized image lacks embedded metadata, "
|
||||||
|
"falling back to original image: %s",
|
||||||
|
original_url,
|
||||||
|
)
|
||||||
|
orig_temp_path = self._create_temp_path(suffix=".png")
|
||||||
|
try:
|
||||||
|
await self._download_image(original_url, orig_temp_path)
|
||||||
|
metadata = await asyncio.to_thread(
|
||||||
|
self._exif_utils.extract_image_metadata,
|
||||||
|
orig_temp_path,
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
self._safe_cleanup(orig_temp_path)
|
||||||
|
|
||||||
result = await self._parse_metadata(
|
result = await self._parse_metadata(
|
||||||
metadata or {},
|
metadata or {},
|
||||||
recipe_scanner=recipe_scanner,
|
recipe_scanner=recipe_scanner,
|
||||||
|
|||||||
@@ -104,6 +104,7 @@
|
|||||||
id="civitaiApiKey"
|
id="civitaiApiKey"
|
||||||
placeholder="{{ t('settings.civitaiApiKeyPlaceholder') }}"
|
placeholder="{{ t('settings.civitaiApiKeyPlaceholder') }}"
|
||||||
value="{{ settings.get('civitai_api_key', '') }}"
|
value="{{ settings.get('civitai_api_key', '') }}"
|
||||||
|
autocomplete="new-password"
|
||||||
onblur="settingsManager.saveInputSetting('civitaiApiKey', 'civitai_api_key')"
|
onblur="settingsManager.saveInputSetting('civitaiApiKey', 'civitai_api_key')"
|
||||||
onkeydown="if(event.key === 'Enter') { this.blur(); }" />
|
onkeydown="if(event.key === 'Enter') { this.blur(); }" />
|
||||||
<button class="toggle-visibility">
|
<button class="toggle-visibility">
|
||||||
@@ -371,6 +372,7 @@
|
|||||||
<div class="api-key-input">
|
<div class="api-key-input">
|
||||||
<input type="password" id="proxyPassword"
|
<input type="password" id="proxyPassword"
|
||||||
placeholder="{{ t('settings.proxySettings.proxyPasswordPlaceholder') }}"
|
placeholder="{{ t('settings.proxySettings.proxyPasswordPlaceholder') }}"
|
||||||
|
autocomplete="new-password"
|
||||||
onblur="settingsManager.saveInputSetting('proxyPassword', 'proxy_password')"
|
onblur="settingsManager.saveInputSetting('proxyPassword', 'proxy_password')"
|
||||||
onkeydown="if(event.key === 'Enter') { this.blur(); }" />
|
onkeydown="if(event.key === 'Enter') { this.blur(); }" />
|
||||||
<button class="toggle-visibility">
|
<button class="toggle-visibility">
|
||||||
|
|||||||
Reference in New Issue
Block a user