Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bddcfb6dc7 | ||
|
|
8f9a91e2b1 | ||
|
|
10d853465c | ||
|
|
2874d7bc77 | ||
|
|
4e1d589b7d | ||
|
|
dff702527d | ||
|
|
7ffc3e9e2a | ||
|
|
6961609640 | ||
|
|
0791426027 | ||
|
|
c88ff4def9 | ||
|
|
b362bff243 | ||
|
|
5ada54681b | ||
|
|
3dcb2af2ef |
+12
-6
@@ -13,8 +13,9 @@ import asyncio
|
|||||||
import subprocess
|
import subprocess
|
||||||
import requests
|
import requests
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
import importlib.util
|
import importlib
|
||||||
import sys
|
import sys
|
||||||
|
import pkg_resources
|
||||||
from packaging import version
|
from packaging import version
|
||||||
|
|
||||||
def check_and_install(package, import_name="", desired_version=None,reboot=False):
|
def check_and_install(package, import_name="", desired_version=None,reboot=False):
|
||||||
@@ -23,9 +24,12 @@ def check_and_install(package, import_name="", desired_version=None,reboot=False
|
|||||||
try:
|
try:
|
||||||
library_module = importlib.import_module(import_name)
|
library_module = importlib.import_module(import_name)
|
||||||
current_version = getattr(library_module, '__version__', None)
|
current_version = getattr(library_module, '__version__', None)
|
||||||
if current_version :
|
if current_version is None:
|
||||||
if current_version:
|
current_version = pkg_resources.get_distribution(import_name).version
|
||||||
print(f"Current version of {import_name}: {current_version}")
|
|
||||||
|
|
||||||
|
if current_version:
|
||||||
|
print(f"Current version of {import_name}: {current_version}")
|
||||||
if desired_version:
|
if desired_version:
|
||||||
if version.parse(current_version) < version.parse(desired_version):
|
if version.parse(current_version) < version.parse(desired_version):
|
||||||
print(f"Updating {import_name} to version {desired_version}...")
|
print(f"Updating {import_name} to version {desired_version}...")
|
||||||
@@ -41,7 +45,9 @@ def check_and_install(package, import_name="", desired_version=None,reboot=False
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
print(f"Installing {import_name}...")
|
print(f"Installing {import_name}...")
|
||||||
install_package(package)
|
install_package(package)
|
||||||
|
except pkg_resources.DistributionNotFound:
|
||||||
|
print(f"{import_name} is not installed. Installing...")
|
||||||
|
install_package(package)
|
||||||
|
|
||||||
def install_package(package):
|
def install_package(package):
|
||||||
subprocess.check_call([sys.executable, "-m", "pip", "install", "--no-cache-dir", package])
|
subprocess.check_call([sys.executable, "-m", "pip", "install", "--no-cache-dir", package])
|
||||||
@@ -658,7 +664,7 @@ async def proxy_models(request):
|
|||||||
}
|
}
|
||||||
|
|
||||||
full_url = f"{api_url}?{urlencode(params)}"
|
full_url = f"{api_url}?{urlencode(params)}"
|
||||||
|
#print(full_url)
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.get(full_url, headers=headers) as response:
|
async with session.get(full_url, headers=headers) as response:
|
||||||
response_data = await response.json()
|
response_data = await response.json()
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ async function settingsSetup(app,$el) {
|
|||||||
addSBSetting( "g_section",{
|
addSBSetting( "g_section",{
|
||||||
id: "embed_osb",
|
id: "embed_osb",
|
||||||
name: "Embed Official Sidebar",
|
name: "Embed Official Sidebar",
|
||||||
defaultValue: "true",
|
defaultValue: "false",
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
local: true,
|
local: true,
|
||||||
info: "This will move the buttons of the official sidebar inside the N-Sidebar.",
|
info: "This will move the buttons of the official sidebar inside the N-Sidebar.",
|
||||||
@@ -278,7 +278,7 @@ async function settingsSetup(app,$el) {
|
|||||||
addSBSetting( "g_section", {
|
addSBSetting( "g_section", {
|
||||||
id: "bartop",
|
id: "bartop",
|
||||||
name: "Space Top",
|
name: "Space Top",
|
||||||
defaultValue: 0,
|
defaultValue: 6,
|
||||||
type: "slider",
|
type: "slider",
|
||||||
local: true,
|
local: true,
|
||||||
attrs: {
|
attrs: {
|
||||||
@@ -413,7 +413,7 @@ async function settingsSetup(app,$el) {
|
|||||||
addSBSetting( "g_section", {
|
addSBSetting( "g_section", {
|
||||||
id: "position",
|
id: "position",
|
||||||
name: "Position",
|
name: "Position",
|
||||||
defaultValue: "left",
|
defaultValue: "right",
|
||||||
type: "dropdown",
|
type: "dropdown",
|
||||||
options: [
|
options: [
|
||||||
{ value: "left", label: "LEFT" },
|
{ value: "left", label: "LEFT" },
|
||||||
@@ -513,7 +513,7 @@ async function settingsSetup(app,$el) {
|
|||||||
|
|
||||||
if (localStorage.getItem("Comfy.Settings.Comfy.Sidebar.Location") === null ) {
|
if (localStorage.getItem("Comfy.Settings.Comfy.Sidebar.Location") === null ) {
|
||||||
addDynamicCSSRule('.side-bar-panel', 'min-width', 'calc('+localStorage.getItem("sidebarWidth")+'px - 35px)');
|
addDynamicCSSRule('.side-bar-panel', 'min-width', 'calc('+localStorage.getItem("sidebarWidth")+'px - 35px)');
|
||||||
addDynamicCSSRule('.splitter-overlay', 'margin-left', '35px');
|
//addDynamicCSSRule('.splitter-overlay', 'margin-left', '35px');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,12 +39,15 @@ jsloader(cnPath + "js/functions/settings.js");
|
|||||||
|
|
||||||
|
|
||||||
let CUSTOM_COLORS;
|
let CUSTOM_COLORS;
|
||||||
|
const SETTING_THEME = 'jovi.color.theme';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var response = await api.fetchApi("/jovimetrix/config", { cache: "no-store" })
|
CUSTOM_COLORS = app.extensionManager.setting.get(SETTING_THEME) || {};
|
||||||
const CONFIG_CORE = await response.json()
|
Object.keys(DEFAULT_THEME).forEach(key => {
|
||||||
CUSTOM_COLORS = CONFIG_CORE?.user?.default?.color?.theme;
|
if (!(key in CONFIG_THEME)) {
|
||||||
|
CONFIG_THEME[key] = DEFAULT_THEME[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,332 @@
|
|||||||
|
import json
|
||||||
|
import requests # Assuming requests is used by CivitaiSearch
|
||||||
|
|
||||||
|
# This is the CivitaiSearch class provided by the user
|
||||||
|
# (Included for context, no changes made to this part)
|
||||||
|
class CivitaiSearch:
|
||||||
|
BASE_URL = "https://search.civitai.com/multi-search"
|
||||||
|
|
||||||
|
def __init__(self, token: str):
|
||||||
|
self.headers = {
|
||||||
|
"accept": "*/*",
|
||||||
|
"accept-encoding": "gzip, deflate, br, zstd",
|
||||||
|
"accept-language": "en-US,en;q=0.9,it;q=0.8",
|
||||||
|
"authorization": f"Bearer {token}",
|
||||||
|
"cache-control": "no-cache",
|
||||||
|
"content-type": "application/json",
|
||||||
|
"dnt": "1",
|
||||||
|
"origin": "https://civitai.com",
|
||||||
|
"pragma": "no-cache",
|
||||||
|
"referer": "https://civitai.com/",
|
||||||
|
"user-agent": "Mozilla/5.0", # Standard User-Agent
|
||||||
|
"x-meilisearch-client": "Meilisearch instant-meilisearch (v0.13.5) ; Meilisearch JavaScript (v0.34.0)"
|
||||||
|
}
|
||||||
|
|
||||||
|
def build_query(self, search_term="asd", limit=51, offset=0,
|
||||||
|
checkpoint_types=None,
|
||||||
|
file_formats=None,
|
||||||
|
model_types=None,
|
||||||
|
base_models=None,
|
||||||
|
nsfw_levels=None,
|
||||||
|
extra_filter=None):
|
||||||
|
filter_list = []
|
||||||
|
|
||||||
|
if checkpoint_types:
|
||||||
|
filter_list.append([f"\"checkpointType\"=\"{t}\"" for t in checkpoint_types])
|
||||||
|
if file_formats:
|
||||||
|
filter_list.append([f"\"fileFormats\"=\"{f}\"" for f in file_formats])
|
||||||
|
if model_types:
|
||||||
|
filter_list.append([f"\"type\"=\"{t}\"" for t in model_types])
|
||||||
|
if base_models:
|
||||||
|
filter_list.append([f"\"version.baseModel\"=\"{b}\"" for b in base_models])
|
||||||
|
|
||||||
|
nsfw_values = nsfw_levels if nsfw_levels else [1, 2, 4, 8, 16] # Default to all levels if None
|
||||||
|
nsfw_filter_parts = [f"nsfwLevel={level}" for level in nsfw_values]
|
||||||
|
|
||||||
|
# Ensure nsfw_filter_parts is not empty before joining
|
||||||
|
if nsfw_filter_parts:
|
||||||
|
nsfw_filter = " OR ".join(nsfw_filter_parts)
|
||||||
|
else: # Fallback if nsfw_levels was an empty list, though default above should prevent this
|
||||||
|
nsfw_filter = "nsfwLevel=1" # Or some other safe default
|
||||||
|
|
||||||
|
base_filter = "(poi != true OR user.id = 58660) AND (availability != Private OR user.id = 58660)"
|
||||||
|
full_extra_filter = f"{base_filter} AND ({nsfw_filter})"
|
||||||
|
|
||||||
|
if extra_filter:
|
||||||
|
full_extra_filter = f"{full_extra_filter} AND ({extra_filter})"
|
||||||
|
|
||||||
|
filter_list.append(full_extra_filter)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"queries": [
|
||||||
|
{
|
||||||
|
"q": search_term,
|
||||||
|
"indexUid": "models_v9",
|
||||||
|
"facets": [
|
||||||
|
"category.name", "checkpointType", "fileFormats",
|
||||||
|
"lastVersionAtUnix", "tags.name", "type", "user.username",
|
||||||
|
"version.baseModel"
|
||||||
|
],
|
||||||
|
"attributesToHighlight": [],
|
||||||
|
"highlightPreTag": "__ais-highlight__",
|
||||||
|
"highlightPostTag": "__/ais-highlight__",
|
||||||
|
"limit": limit,
|
||||||
|
"offset": offset,
|
||||||
|
"filter": filter_list
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
def search(self, **kwargs):
|
||||||
|
query = self.build_query(**kwargs)
|
||||||
|
# print(json.dumps(query, indent=2)) # For debugging the query
|
||||||
|
response = requests.post(self.BASE_URL, headers=self.headers, data=json.dumps(query))
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
return response.json()
|
||||||
|
else:
|
||||||
|
raise Exception(f"Errore {response.status_code}: {response.text}")
|
||||||
|
|
||||||
|
# --- Transformation Logic ---
|
||||||
|
BASE_CIVITAI_IMAGE_URL_PREFIX = "https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA"
|
||||||
|
|
||||||
|
def sanitize_filename_part(name_part):
|
||||||
|
if not name_part: return ""
|
||||||
|
# Basic sanitization for filenames
|
||||||
|
return str(name_part).replace(' ', '_').replace('/', '_').replace('\\', '_').replace(':', '_') \
|
||||||
|
.replace('*', '_').replace('?', '_').replace('"', '_').replace('<', '_') \
|
||||||
|
.replace('>', '_').replace('|', '_')
|
||||||
|
|
||||||
|
def get_file_extension_from_format(format_string):
|
||||||
|
if not format_string:
|
||||||
|
return "bin" # Default extension
|
||||||
|
f_lower = format_string.lower()
|
||||||
|
if "safetensor" in f_lower:
|
||||||
|
return "safetensors"
|
||||||
|
if "pickletensor" in f_lower:
|
||||||
|
return "ckpt"
|
||||||
|
# Add more mappings as needed
|
||||||
|
return f_lower # Fallback
|
||||||
|
|
||||||
|
def transform_search_hashdata_to_official_hashes(hash_data_list):
|
||||||
|
hashes_dict = {}
|
||||||
|
if isinstance(hash_data_list, list):
|
||||||
|
for hd_entry in hash_data_list:
|
||||||
|
if isinstance(hd_entry, dict) and "type" in hd_entry and "hash" in hd_entry:
|
||||||
|
hashes_dict[hd_entry["type"]] = hd_entry["hash"]
|
||||||
|
return hashes_dict
|
||||||
|
|
||||||
|
def adapt_search_response_to_official_api(search_response_json):
|
||||||
|
"""
|
||||||
|
Transforms the Civitai search API response to a structure similar to the official GET /models API.
|
||||||
|
"""
|
||||||
|
official_api_items = []
|
||||||
|
|
||||||
|
if not search_response_json or "results" not in search_response_json or \
|
||||||
|
not search_response_json["results"] or "hits" not in search_response_json["results"][0]:
|
||||||
|
return {"items": []}
|
||||||
|
|
||||||
|
search_hits = search_response_json["results"][0]["hits"]
|
||||||
|
|
||||||
|
for hit in search_hits:
|
||||||
|
# --- Model Level ---
|
||||||
|
model_metrics = hit.get("metrics", {})
|
||||||
|
model_permissions = hit.get("permissions", {})
|
||||||
|
|
||||||
|
# Calculate model nsfwLevel: sum of flags from search result
|
||||||
|
model_nsfw_level_flags = hit.get("nsfwLevel", [])
|
||||||
|
if isinstance(model_nsfw_level_flags, list):
|
||||||
|
calculated_model_nsfw_level = sum(model_nsfw_level_flags)
|
||||||
|
else: # Should be a list based on example, but handle if it's not
|
||||||
|
calculated_model_nsfw_level = 0
|
||||||
|
|
||||||
|
|
||||||
|
official_item = {
|
||||||
|
"id": hit.get("id"),
|
||||||
|
"name": hit.get("name"),
|
||||||
|
"description": "", # Official API often has this empty for the model itself
|
||||||
|
"allowNoCredit": model_permissions.get("allowNoCredit", False),
|
||||||
|
"allowCommercialUse": model_permissions.get("allowCommercialUse", []),
|
||||||
|
"allowDerivatives": model_permissions.get("allowDerivatives", True),
|
||||||
|
"allowDifferentLicense": model_permissions.get("allowDifferentLicense", False),
|
||||||
|
"type": hit.get("type"),
|
||||||
|
"minor": hit.get("minor", False),
|
||||||
|
"sfwOnly": hit.get("sfwOnly", False), # This key is present in the search example
|
||||||
|
"poi": hit.get("poi", False),
|
||||||
|
"nsfw": hit.get("nsfw", False),
|
||||||
|
"nsfwLevel": calculated_model_nsfw_level,
|
||||||
|
"availability": hit.get("availability", "Public"),
|
||||||
|
"cosmetic": hit.get("cosmetic"),
|
||||||
|
"supportsGeneration": hit.get("canGenerate", False), # Renamed from canGenerate
|
||||||
|
"stats": {
|
||||||
|
"downloadCount": model_metrics.get("downloadCount", 0),
|
||||||
|
"favoriteCount": model_metrics.get("favoriteCount", 0), # Official API might show 0 here
|
||||||
|
"thumbsUpCount": model_metrics.get("thumbsUpCount", 0),
|
||||||
|
"thumbsDownCount": 0, # Not in search model metrics; official example has it
|
||||||
|
"commentCount": model_metrics.get("commentCount", 0),
|
||||||
|
"ratingCount": model_metrics.get("ratingCount", 0), # Official API might show 0
|
||||||
|
"rating": model_metrics.get("rating", 0.0), # Official API might show 0
|
||||||
|
"tippedAmountCount": model_metrics.get("tippedAmountCount", 0)
|
||||||
|
},
|
||||||
|
"tags": [tag.get("name") for tag in hit.get("tags", []) if tag.get("name")]
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Model Versions Level ---
|
||||||
|
official_model_versions = []
|
||||||
|
|
||||||
|
# Pre-group images by modelVersionId for easier lookup
|
||||||
|
images_by_version_id = {}
|
||||||
|
for img in hit.get("images", []):
|
||||||
|
mv_id = img.get("modelVersionId")
|
||||||
|
if mv_id:
|
||||||
|
if mv_id not in images_by_version_id:
|
||||||
|
images_by_version_id[mv_id] = []
|
||||||
|
images_by_version_id[mv_id].append(img)
|
||||||
|
|
||||||
|
for index, search_version in enumerate(hit.get("versions", [])):
|
||||||
|
version_id = search_version.get("id")
|
||||||
|
version_metrics = search_version.get("metrics", {})
|
||||||
|
|
||||||
|
official_version_data = {
|
||||||
|
"id": version_id,
|
||||||
|
"index": index,
|
||||||
|
"name": search_version.get("name"),
|
||||||
|
"baseModel": search_version.get("baseModel"),
|
||||||
|
"baseModelType": search_version.get("baseModelType"),
|
||||||
|
"publishedAt": search_version.get("createdAt"), # Search uses createdAt for version
|
||||||
|
"availability": "Public", # Default, not in search version object
|
||||||
|
"nsfwLevel": search_version.get("nsfwLevel"), # This is per-version
|
||||||
|
"description": search_version.get("description"), # Usually null/missing in search version
|
||||||
|
"trainedWords": search_version.get("trainedWords", []),
|
||||||
|
"stats": {
|
||||||
|
"downloadCount": version_metrics.get("downloadCount", 0),
|
||||||
|
"ratingCount": version_metrics.get("ratingCount", 0),
|
||||||
|
"rating": version_metrics.get("rating", 0.0),
|
||||||
|
"thumbsUpCount": version_metrics.get("thumbsUpCount", 0),
|
||||||
|
"thumbsDownCount": version_metrics.get("thumbsDownCount", 0) # Present in version metrics
|
||||||
|
},
|
||||||
|
"supportsGeneration": False, # Official API example shows this as false for versions
|
||||||
|
"files": [],
|
||||||
|
"images": [],
|
||||||
|
"downloadUrl": f"https://civitai.com/api/download/models/{version_id}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Files for Version (Simplified) ---
|
||||||
|
# Search API doesn't provide detailed file info like official GET /model/:id
|
||||||
|
# We'll create one primary file entry based on available info.
|
||||||
|
model_file_formats = hit.get("fileFormats", [])
|
||||||
|
version_hash_data = search_version.get("hashData", [])
|
||||||
|
|
||||||
|
if model_file_formats and version_hash_data:
|
||||||
|
primary_file_format_str = model_file_formats[0] # Assume first is primary
|
||||||
|
file_extension = get_file_extension_from_format(primary_file_format_str)
|
||||||
|
|
||||||
|
# Construct a filename
|
||||||
|
sane_model_name = sanitize_filename_part(hit.get("name", "model"))
|
||||||
|
sane_version_name = sanitize_filename_part(search_version.get("name", f"v{index + 1}"))
|
||||||
|
# Example filename: modelname-versionname.ext
|
||||||
|
constructed_filename = f"{sane_model_name}-{sane_version_name}.{file_extension}"
|
||||||
|
|
||||||
|
file_entry = {
|
||||||
|
"id": version_id + 100000, # Placeholder file ID, not from search
|
||||||
|
"sizeKB": None, # Not available from search, official API has it
|
||||||
|
"name": constructed_filename,
|
||||||
|
"type": "Model", # Default type
|
||||||
|
"pickleScanResult": "Success", # Placeholder
|
||||||
|
"pickleScanMessage": "No Pickle imports", # Placeholder
|
||||||
|
"virusScanResult": "Success", # Placeholder
|
||||||
|
"virusScanMessage": None, # Placeholder
|
||||||
|
"scannedAt": search_version.get("createdAt"), # Placeholder
|
||||||
|
"metadata": {
|
||||||
|
"format": primary_file_format_str,
|
||||||
|
"size": "full", # Placeholder
|
||||||
|
"fp": "fp16" # Placeholder, common
|
||||||
|
},
|
||||||
|
"hashes": transform_search_hashdata_to_official_hashes(version_hash_data),
|
||||||
|
"downloadUrl": f"https://civitai.com/api/download/models/{version_id}", # Same as version for primary
|
||||||
|
"primary": True
|
||||||
|
}
|
||||||
|
official_version_data["files"].append(file_entry)
|
||||||
|
|
||||||
|
# --- Images for Version ---
|
||||||
|
version_images_list = images_by_version_id.get(version_id, [])
|
||||||
|
for search_img in version_images_list:
|
||||||
|
img_id = search_img.get("id")
|
||||||
|
img_url_segment = search_img.get("url")
|
||||||
|
img_width_for_url = search_img.get("width", 512) # Default if width missing
|
||||||
|
|
||||||
|
constructed_img_url = None
|
||||||
|
if img_id and img_url_segment:
|
||||||
|
# Official API image URLs use .jpeg, server handles format.
|
||||||
|
constructed_img_url = f"{BASE_CIVITAI_IMAGE_URL_PREFIX}/{img_url_segment}/width={img_width_for_url}/{img_id}.jpeg"
|
||||||
|
|
||||||
|
image_entry = {
|
||||||
|
"id": img_id,
|
||||||
|
"url": constructed_img_url,
|
||||||
|
"nsfwLevel": search_img.get("nsfwLevel", 0),
|
||||||
|
"width": search_img.get("width"),
|
||||||
|
"height": search_img.get("height"),
|
||||||
|
"hash": search_img.get("hash"),
|
||||||
|
"type": search_img.get("type", "image"),
|
||||||
|
"minor": search_img.get("minor", False),
|
||||||
|
"poi": search_img.get("poi", False),
|
||||||
|
"hasMeta": search_img.get("hasMeta", False),
|
||||||
|
"hasPositivePrompt": search_img.get("hasPositivePrompt", False),
|
||||||
|
"onSite": search_img.get("onSite", False),
|
||||||
|
"remixOfId": search_img.get("remixOfId")
|
||||||
|
}
|
||||||
|
official_version_data["images"].append(image_entry)
|
||||||
|
|
||||||
|
official_model_versions.append(official_version_data)
|
||||||
|
|
||||||
|
official_item["modelVersions"] = official_model_versions
|
||||||
|
official_api_items.append(official_item)
|
||||||
|
|
||||||
|
return {"items": official_api_items}
|
||||||
|
|
||||||
|
|
||||||
|
# Example of how to use the transformation (assuming you have `results_from_search`)
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# This is the example usage from your code
|
||||||
|
token = "4c7745e54e872213201291ba1cae1aaca702941f291432cf4fef22803333e487" # Example token
|
||||||
|
civitai_searcher = CivitaiSearch(token)
|
||||||
|
|
||||||
|
print("Performing search (this will make a live API call)...")
|
||||||
|
try:
|
||||||
|
search_api_response = civitai_searcher.search(
|
||||||
|
search_term="hentai",
|
||||||
|
model_types=["Checkpoint"],
|
||||||
|
base_models=["SDXL 1.0"],
|
||||||
|
nsfw_levels=[1, 2, 4, 8, 16] # Explicitly pass all desired NSFW levels
|
||||||
|
)
|
||||||
|
|
||||||
|
print("\nOriginal Search API Response (first hit preview):")
|
||||||
|
if search_api_response and search_api_response["results"] and search_api_response["results"][0]["hits"]:
|
||||||
|
print(json.dumps(search_api_response["results"][0]["hits"][0], indent=2, ensure_ascii=False))
|
||||||
|
else:
|
||||||
|
print("No hits found or unexpected response structure.")
|
||||||
|
|
||||||
|
print("\n--- Transforming to Official API Format ---")
|
||||||
|
adapted_response = adapt_search_response_to_official_api(search_api_response)
|
||||||
|
|
||||||
|
print("\nAdapted Response (first item preview):")
|
||||||
|
if adapted_response and adapted_response["items"]:
|
||||||
|
print(json.dumps(adapted_response["items"][0], indent=2, ensure_ascii=False))
|
||||||
|
else:
|
||||||
|
print("No items after transformation or empty result.")
|
||||||
|
|
||||||
|
# To see the full adapted response:
|
||||||
|
# print("\nFull Adapted Response:")
|
||||||
|
# print(json.dumps(adapted_response, indent=2, ensure_ascii=False))
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"An error occurred: {e}")
|
||||||
|
|
||||||
|
# You can also test with the provided sample JSON if you don't want to make a live call
|
||||||
|
# sample_search_response_text = """ PASTE YOUR FULL SEARCH RESPONSE JSON HERE """
|
||||||
|
# if sample_search_response_text:
|
||||||
|
# sample_search_response_json = json.loads(sample_search_response_text)
|
||||||
|
# adapted_from_sample = adapt_search_response_to_official_api(sample_search_response_json)
|
||||||
|
# print("\nAdapted Response from Sample JSON (first item):")
|
||||||
|
# if adapted_from_sample and adapted_from_sample["items"]:
|
||||||
|
# print(json.dumps(adapted_from_sample["items"][0], indent=2, ensure_ascii=False))
|
||||||
@@ -36,6 +36,59 @@
|
|||||||
<option value="Workflows">Workflows</option>
|
<option value="Workflows">Workflows</option>
|
||||||
<option value="Other">Other</option>
|
<option value="Other">Other</option>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="baseModelFilter" data-placeholder="Base Model(s)" multiple data-multi-select>
|
||||||
|
<option value="AuraFlow">AuraFlow</option>
|
||||||
|
<option value="CogVideoX">CogVideoX</option>
|
||||||
|
<option value="Flux.1 D">Flux.1 D</option>
|
||||||
|
<option value="Flux.1 S">Flux.1 S</option>
|
||||||
|
<option value="HiDream">HiDream</option>
|
||||||
|
<option value="Hunyuan 1">Hunyuan 1</option>
|
||||||
|
<option value="Hunyuan Video">Hunyuan Video</option>
|
||||||
|
<option value="Illustrious">Illustrious</option>
|
||||||
|
<option value="Kolors">Kolors</option>
|
||||||
|
<option value="LTXV">LTXV</option>
|
||||||
|
<option value="Lumina">Lumina</option>
|
||||||
|
<option value="Mochi">Mochi</option>
|
||||||
|
<option value="NoobAI">NoobAI</option>
|
||||||
|
<option value="ODOR">ODOR</option>
|
||||||
|
<option value="OpenAI">OpenAI</option>
|
||||||
|
<option value="Other">Other</option>
|
||||||
|
<option value="PixArt a">PixArt a</option>
|
||||||
|
<option value="PixArt E">PixArt E</option>
|
||||||
|
<option value="Playground v2">Playground v2</option>
|
||||||
|
<option value="Pony">Pony</option>
|
||||||
|
<option value="SD 1.4">SD 1.4</option>
|
||||||
|
<option value="SD 1.5">SD 1.5</option>
|
||||||
|
<option value="SD 1.5 Hyper">SD 1.5 Hyper</option>
|
||||||
|
<option value="SD 1.5 LCM">SD 1.5 LCM</option>
|
||||||
|
<option value="SD 2.0">SD 2.0</option>
|
||||||
|
<option value="SD 2.0 768">SD 2.0 768</option>
|
||||||
|
<option value="SD 2.1">SD 2.1</option>
|
||||||
|
<option value="SD 2.1 768">SD 2.1 768</option>
|
||||||
|
<option value="SD 2.1 Unclip">SD 2.1 Unclip</option>
|
||||||
|
<option value="SD 3">SD 3</option>
|
||||||
|
<option value="SD 3.5">SD 3.5</option>
|
||||||
|
<option value="SD 3.5 Large">SD 3.5 Large</option>
|
||||||
|
<option value="SD 3.5 Large Turbo">SD 3.5 Large Turbo</option>
|
||||||
|
<option value="SD 3.5 Medium">SD 3.5 Medium</option>
|
||||||
|
<option value="SDXL 0.9">SDXL 0.9</option>
|
||||||
|
<option value="SDXL 1.0">SDXL 1.0</option>
|
||||||
|
<option value="SDXL 1.0 LCM">SDXL 1.0 LCM</option>
|
||||||
|
<option value="SDXL Distilled">SDXL Distilled</option>
|
||||||
|
<option value="SDXL Hyper">SDXL Hyper</option>
|
||||||
|
<option value="SDXL Lightning">SDXL Lightning</option>
|
||||||
|
<option value="SDXL Turbo">SDXL Turbo</option>
|
||||||
|
<option value="SVD">SVD</option>
|
||||||
|
<option value="SVD XT">SVD XT</option>
|
||||||
|
<option value="Stable Cascade">Stable Cascade</option>
|
||||||
|
<option value="Wan Video">Wan Video</option>
|
||||||
|
<option value="Wan Video 1.3B t2v">Wan Video 1.3B t2v</option>
|
||||||
|
<option value="Wan Video 14B i2v 480p">Wan Video 14B i2v 480p</option>
|
||||||
|
<option value="Wan Video 14B i2v 720p">Wan Video 14B i2v 720p</option>
|
||||||
|
<option value="Wan Video 14B t2v">Wan Video 14B t2v</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Sort Option -->
|
<!-- Sort Option -->
|
||||||
<select id="sortOption" onchange="assets_downloader.searchT()">
|
<select id="sortOption" onchange="assets_downloader.searchT()">
|
||||||
@@ -113,6 +166,20 @@
|
|||||||
<option value="Other">Other</option>
|
<option value="Other">Other</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- Base Model Filter -->
|
||||||
|
<select id="baseModelFilterLibrary" data-placeholder="Base Model(s)" multiple data-library-multi-select>
|
||||||
|
<option value="SD 1.4">SD 1.4</option>
|
||||||
|
<option value="SD 1.5">SD 1.5</option>
|
||||||
|
<option value="SD 2.0">SD 2.0</option>
|
||||||
|
<option value="SD 2.0 768">SD 2.0 768</option>
|
||||||
|
<option value="SD 2.1">SD 2.1</option>
|
||||||
|
<option value="SD 2.1 768">SD 2.1 768</option>
|
||||||
|
<option value="SD 2.1 Unclip">SD 2.1 Unclip</option>
|
||||||
|
<option value="SDXL 0.9">SDXL 0.9</option>
|
||||||
|
<option value="SDXL 1.0">SDXL 1.0</option>
|
||||||
|
<option value="Other">Other</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
<!-- Sort Option -->
|
<!-- Sort Option -->
|
||||||
<select id="sortOptionLibrary" onchange="assets_downloader.searchInLibrary()">
|
<select id="sortOptionLibrary" onchange="assets_downloader.searchInLibrary()">
|
||||||
<option value="">Sort By</option>
|
<option value="">Sort By</option>
|
||||||
|
|||||||
@@ -622,9 +622,19 @@ setupWebSocket();
|
|||||||
// Get search query and filters
|
// Get search query and filters
|
||||||
const query = document.getElementById('searchTemplateInput').value;
|
const query = document.getElementById('searchTemplateInput').value;
|
||||||
const nsfwFilter = Array.from(document.getElementById('nsfwFilter').selectedOptions).map(option => option.value);
|
const nsfwFilter = Array.from(document.getElementById('nsfwFilter').selectedOptions).map(option => option.value);
|
||||||
const multiSelectElement = document.getElementById('typeFilter');
|
const typeMultiSelectElement = document.getElementById('typeFilter');
|
||||||
const hiddenInputs = multiSelectElement.querySelectorAll('input[type="hidden"]');
|
const typeHiddenInputs = typeMultiSelectElement.querySelectorAll('input[type="hidden"]');
|
||||||
const typeFilter = Array.from(hiddenInputs).map(input => input.value);
|
const typeFilter = Array.from(typeHiddenInputs).map(input => input.value);
|
||||||
|
|
||||||
|
const baseModelMultiSelectElement = document.getElementById('baseModelFilter');
|
||||||
|
const baseModelHiddenInputs = baseModelMultiSelectElement.querySelectorAll('input[type="hidden"]');
|
||||||
|
let baseModelFilter = Array.from(baseModelHiddenInputs).map(input => input.value);
|
||||||
|
|
||||||
|
let localBaseModelFilter = [];
|
||||||
|
if (baseModelFilter.length > 0) {
|
||||||
|
localBaseModelFilter = [...baseModelFilter]; // Salva per il filtraggio locale
|
||||||
|
baseModelFilter = []; // Rimuovi per la richiesta API
|
||||||
|
}
|
||||||
|
|
||||||
const sortOption = document.getElementById('sortOption').value;
|
const sortOption = document.getElementById('sortOption').value;
|
||||||
const periodOption = document.getElementById('periodOption').value;
|
const periodOption = document.getElementById('periodOption').value;
|
||||||
@@ -648,6 +658,11 @@ setupWebSocket();
|
|||||||
typeFilter.forEach(type => params.append("types", type));
|
typeFilter.forEach(type => params.append("types", type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add base model filter
|
||||||
|
if (baseModelFilter.length > 0) {
|
||||||
|
baseModelFilter.forEach(model => params.append("baseModels", model));
|
||||||
|
}
|
||||||
|
|
||||||
// Add sort option
|
// Add sort option
|
||||||
if (sortOption) {
|
if (sortOption) {
|
||||||
params.append("sort", sortOption);
|
params.append("sort", sortOption);
|
||||||
@@ -660,7 +675,7 @@ setupWebSocket();
|
|||||||
|
|
||||||
// Limit results to 10 and set pagination to first page
|
// Limit results to 10 and set pagination to first page
|
||||||
params.append("limit", 100);
|
params.append("limit", 100);
|
||||||
params.append("page", 1);
|
//params.append("page", 1);
|
||||||
|
|
||||||
apiUrl += params.toString();
|
apiUrl += params.toString();
|
||||||
|
|
||||||
@@ -685,6 +700,14 @@ setupWebSocket();
|
|||||||
|
|
||||||
// Render the results
|
// Render the results
|
||||||
data.items.forEach(async result => {
|
data.items.forEach(async result => {
|
||||||
|
// Applica il filtro locale per baseModels se presente
|
||||||
|
if (localBaseModelFilter.length > 0) {
|
||||||
|
const resultBaseModel = result.modelVersions[0]?.baseModel;
|
||||||
|
if (!resultBaseModel || !localBaseModelFilter.includes(resultBaseModel)) {
|
||||||
|
return; // Salta questa card se non corrisponde al filtro locale
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const card = document.createElement('div');
|
const card = document.createElement('div');
|
||||||
card.className = 'card';
|
card.className = 'card';
|
||||||
//card.id = result.id;
|
//card.id = result.id;
|
||||||
@@ -842,9 +865,14 @@ setupWebSocket();
|
|||||||
const nsfwFilter = document.getElementById('nsfwFilterLibrary').value;
|
const nsfwFilter = document.getElementById('nsfwFilterLibrary').value;
|
||||||
|
|
||||||
// Filtro tipo (multi-select)
|
// Filtro tipo (multi-select)
|
||||||
const multiSelectElement = document.getElementById('typeFilterLibrary');
|
const typeMultiSelectElement = document.getElementById('typeFilterLibrary');
|
||||||
const hiddenInputs = multiSelectElement.querySelectorAll('input[type="hidden"]');
|
const typeHiddenInputs = typeMultiSelectElement.querySelectorAll('input[type="hidden"]');
|
||||||
const selectedTypes = Array.from(hiddenInputs).map(option => option.value.toLowerCase());
|
const selectedTypes = Array.from(typeHiddenInputs).map(option => option.value.toLowerCase());
|
||||||
|
|
||||||
|
// Filtro baseModels (multi-select)
|
||||||
|
const baseModelMultiSelectElement = document.getElementById('baseModelFilterLibrary');
|
||||||
|
const baseModelHiddenInputs = baseModelMultiSelectElement.querySelectorAll('input[type="hidden"]');
|
||||||
|
const selectedBaseModels = Array.from(baseModelHiddenInputs).map(option => option.value.toLowerCase());
|
||||||
|
|
||||||
// Opzione di ordinamento
|
// Opzione di ordinamento
|
||||||
const sortOption = document.getElementById('sortOptionLibrary').value;
|
const sortOption = document.getElementById('sortOptionLibrary').value;
|
||||||
@@ -859,6 +887,7 @@ setupWebSocket();
|
|||||||
const cardNSFW = card.querySelector('input[name="nsfw"]').value;
|
const cardNSFW = card.querySelector('input[name="nsfw"]').value;
|
||||||
|
|
||||||
const cardTypes = Array.from(card.querySelectorAll('.main-stripe .sub-stripe div')).map(el => el.innerText.toLowerCase());
|
const cardTypes = Array.from(card.querySelectorAll('.main-stripe .sub-stripe div')).map(el => el.innerText.toLowerCase());
|
||||||
|
const cardBaseModel = card.querySelector('.main-stripe .sub-stripe div:nth-child(3)').innerText.toLowerCase();
|
||||||
|
|
||||||
// Filtra per testo (searchQuery)
|
// Filtra per testo (searchQuery)
|
||||||
let matchesSearch = searchQuery === "" || cardTitle.includes(searchQuery);
|
let matchesSearch = searchQuery === "" || cardTitle.includes(searchQuery);
|
||||||
@@ -869,8 +898,11 @@ setupWebSocket();
|
|||||||
// Filtra per tipo (se selezionati)
|
// Filtra per tipo (se selezionati)
|
||||||
let matchesType = selectedTypes.length === 0 || selectedTypes.some(type => cardTypes.includes(type));
|
let matchesType = selectedTypes.length === 0 || selectedTypes.some(type => cardTypes.includes(type));
|
||||||
|
|
||||||
|
// Filtra per baseModel (se selezionati)
|
||||||
|
let matchesBaseModel = selectedBaseModels.length === 0 || selectedBaseModels.includes(cardBaseModel);
|
||||||
|
|
||||||
// Mostra o nascondi la card in base ai filtri
|
// Mostra o nascondi la card in base ai filtri
|
||||||
if (matchesSearch && matchesNSFW && matchesType) {
|
if (matchesSearch && matchesNSFW && matchesType && matchesBaseModel) {
|
||||||
card.style.display = "block";
|
card.style.display = "block";
|
||||||
} else {
|
} else {
|
||||||
card.style.display = "none";
|
card.style.display = "none";
|
||||||
@@ -1169,7 +1201,7 @@ setupWebSocket();
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
document.querySelectorAll('[data-multi-select]').forEach(select => new MultiSelect(select, { onChange: debouncedSearchType }));
|
document.querySelectorAll('[data-multi-select]').forEach(select => new MultiSelect(select, { onChange: debouncedSearchT }));
|
||||||
document.querySelectorAll('[data-library-multi-select]').forEach(select => new MultiSelect(select, { onChange: debouncedSearchInLibrary }));
|
document.querySelectorAll('[data-library-multi-select]').forEach(select => new MultiSelect(select, { onChange: debouncedSearchInLibrary }));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -305,7 +305,9 @@ padding-bottom: 150px;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#baseModelFilter{
|
||||||
|
width: 157px !important;
|
||||||
|
}
|
||||||
#t1, #t2{
|
#t1, #t2{
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "comfyui-n-sidebar"
|
name = "comfyui-n-sidebar"
|
||||||
description = "A simple sidebar for ComfyUI."
|
description = "A simple sidebar for ComfyUI."
|
||||||
version = "1.6.0"
|
version = "1.6.5"
|
||||||
license = { file = "LICENSE" }
|
license = { file = "LICENSE" }
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
|
|||||||
Reference in New Issue
Block a user