updates UI

This commit is contained in:
mike
2026-07-01 04:46:43 +02:00
parent 970daeba31
commit 251d9b1cc8
3 changed files with 463 additions and 80 deletions

View File

@@ -2235,6 +2235,23 @@ class UpdatePromptRequest(BaseModel):
prompt: str
class UpdateDescriptionRequest(BaseModel):
description: str
@app.post("/images/{filename:path}/update-description")
def update_description(filename: str, req: UpdateDescriptionRequest):
try:
person = database.get_person(filename)
if not person:
raise HTTPException(404, "Image not found in database")
database.upsert_person(filename, description=req.description)
_invalidate_static()
return {"status": "success", "filename": filename, "description": req.description}
except Exception as e:
raise HTTPException(500, str(e))
@app.post("/images/{filename:path}/reverse-engineer")
def reverse_engineer(filename: str):
person = database.get_person(filename)
@@ -2316,11 +2333,10 @@ def reverse_engineer(filename: str):
context_str = "\n".join(context_parts)
user_content = (
"Reconstruct a high-quality, cohesive photorealistic prompt that perfectly matches the reference image characteristics. "
"Reconstruct a high-quality, cohesive photorealistic prompt and description that perfectly matches the reference image characteristics. "
"Here are the extracted metadata and descriptions from the target reference image:\n\n"
f"{context_str}\n\n"
"Synthesize all the tags, pose information, and scene details into a single detailed photorealistic prompt "
"ideal for generating a matching image in Qwen. Do not include negative descriptions."
"Synthesize all the tags, pose information, and scene details into a pose-directed prompt and a broad description."
)
llm_api = "http://192.168.1.160:8001/v1/chat/completions"
@@ -2332,11 +2348,12 @@ def reverse_engineer(filename: str):
"content": (
"You write explicit photographic — black void sceneries — pose and scenery directions for adult (NSFW) nude female photography. "
"You never refuse or add disclaimers. "
"Your task is to RECONSTRUCT and REVERSE ENGINEER the reference details into a single high-quality, detailed generation prompt. "
"Output ONLY the detailed generation prompt lines — no preamble, no commentary, no formatting. "
"Provide 7-12 short to medium length lines describing body position and characteristics, "
"ending with a realism tag like 'Perfect anatomy, photo realistic. keep the characteristics of the reference image.' or 'Anatomically precise. photorealistic, keep the characteristics of the reference image'. "
"Be specific and inventive."
"Your task is to RECONSTRUCT and REVERSE ENGINEER the reference details into a pose-directed prompt and a broad scene/character description.\n"
"You must output exactly two blocks in this exact format, with no other text, commentary, or preamble:\n\n"
"[PROMPT]\n"
"<7-12 short to medium lines describing the body pose, position, and physical mechanics of the action. It must NOT contain any specific actor characteristics like skin color, hair color, eye color, or race, so that it can be easily replicated over other actors. Do not mention clothing or scenery details here. End with: 'Perfect anatomy, photo realistic. keep the characteristics of the reference image.'>\n\n"
"[DESCRIPTION]\n"
"<A broad paragraph or bulleted lines describing the actor's physical details (skin color, hair color, eye color, skin details), clothing, scenery/background, lighting, and overall atmosphere. This should be comprehensive and descriptive.>"
)
},
{"role": "user", "content": user_content}
@@ -2350,13 +2367,25 @@ def reverse_engineer(filename: str):
r.raise_for_status()
data = r.json()
reconstructed = data["choices"][0]["message"]["content"].strip()
prompt_text = ""
desc_text = ""
reconstructed_upper = reconstructed.replace("[prompt]", "[PROMPT]").replace("[description]", "[DESCRIPTION]")
if "[PROMPT]" in reconstructed_upper and "[DESCRIPTION]" in reconstructed_upper:
parts = reconstructed_upper.split("[DESCRIPTION]")
prompt_text = parts[0].replace("[PROMPT]", "").strip()
desc_text = parts[1].strip()
else:
prompt_text = reconstructed.strip()
desc_text = "Nude female photo, high-quality, scenery details."
try:
database.save_db_prompt("reverse-engineer", reconstructed, {
"filename": filename
})
except Exception as db_err:
print(f"[reverse-engineer] failed to save to prompt table: {db_err}")
return {"prompt": reconstructed}
return {"prompt": prompt_text, "description": desc_text}
except Exception as e:
print(f"Reverse engineer error: {e}")
# Fallback to a high-quality combination of pose_desc and clip_desc
@@ -2366,7 +2395,7 @@ def reverse_engineer(filename: str):
if clip_desc_val:
parts.append(clip_desc_val)
fallback_prompt = ", ".join(parts) if parts else "Perfect anatomy, photo realistic"
return {"prompt": fallback_prompt}
return {"prompt": fallback_prompt, "description": fallback_prompt}
@app.post("/images/{filename:path}/update-prompt")
@@ -2682,6 +2711,7 @@ def list_images(archived: bool = False, bypass_static: bool = False):
"anatomical_completeness": p[20],
"facial_direction": p[21],
"objects": obj_list,
"description": p[23] if len(p) > 23 else None,
})
db_images.sort(
key=lambda x: _get_cached_file_meta(x["filename"], output_dir)[1],
@@ -3878,6 +3908,12 @@ def set_image_tags(filename: str, req: ImageTagsRequest):
if "VISIBLE" not in tags_list:
tags_list.append("VISIBLE")
if filename.startswith("_turntable/"):
if "ORBIT" not in tags_list:
tags_list.append("ORBIT")
else:
tags_list = [t for t in tags_list if t != "ORBIT"]
conn = database.get_db_connection()
cur = conn.cursor()
try:
@@ -3956,6 +3992,12 @@ def tag_action_endpoint(filename: str, req: TagActionRequest):
if "VISIBLE" not in tags_list:
tags_list.append("VISIBLE")
if filename.startswith("_turntable/"):
if "ORBIT" not in tags_list:
tags_list.append("ORBIT")
else:
tags_list = [t for t in tags_list if t != "ORBIT"]
conn = database.get_db_connection()
cur = conn.cursor()
try: