Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import spaces
|
|
| 5 |
import gradio as gr
|
| 6 |
import os
|
| 7 |
|
| 8 |
-
from config import PRESETS, DEFAULT_PARAMS, TRIGGER_WORD
|
| 9 |
from generator import RetroArtConverter
|
| 10 |
|
| 11 |
|
|
@@ -42,6 +42,7 @@ def process_image(
|
|
| 42 |
depth_control_scale,
|
| 43 |
identity_control_scale,
|
| 44 |
expression_control_scale, # <-- NEW
|
|
|
|
| 45 |
lora_scale,
|
| 46 |
identity_preservation,
|
| 47 |
strength,
|
|
@@ -65,6 +66,7 @@ def process_image(
|
|
| 65 |
depth_control_scale=depth_control_scale,
|
| 66 |
identity_control_scale=identity_control_scale,
|
| 67 |
expression_control_scale=expression_control_scale, # <-- NEW
|
|
|
|
| 68 |
lora_scale=lora_scale,
|
| 69 |
identity_preservation=identity_preservation,
|
| 70 |
strength=strength,
|
|
@@ -107,10 +109,29 @@ def get_model_status():
|
|
| 107 |
if converter.models_loaded:
|
| 108 |
status_text = "**[OK] Loaded Models:**\n"
|
| 109 |
status_text += f"- Custom Checkpoint (Horizon): {'[OK] Loaded' if converter.models_loaded['custom_checkpoint'] else '[OK] Using SDXL base'}\n"
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
status_text += f"- InstantID: {'[OK] Loaded' if converter.models_loaded['instantid'] else ' Disabled'}\n"
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
status_text += f"- IP-Adapter (Face Embeddings): {'[OK] Loaded' if converter.models_loaded.get('ip_adapter', False) else ' Keypoints only'}\n"
|
| 115 |
return status_text
|
| 116 |
return "**Model status unavailable**"
|
|
@@ -177,7 +198,8 @@ with gr.Blocks(title="Pixagram - AI Pixel Art Generator", theme=gr.themes.Soft()
|
|
| 177 |
scheduler_info = f"""
|
| 178 |
**[CONFIG] Advanced Configuration:**
|
| 179 |
- Pipeline: **Img2Img** (structure preservation)
|
| 180 |
-
- Face System: **CLIP + InsightFace** (
|
|
|
|
| 181 |
- **[NEW] Expression Control:** OpenPose-Face (68 keypoints)
|
| 182 |
- **[ADVANCED] Enhanced Resampler:** 10 layers, 20 heads (+3-5% quality)
|
| 183 |
- **[ADVANCED] Adaptive Attention:** Context-aware scaling (+2-3% quality)
|
|
@@ -268,12 +290,21 @@ with gr.Blocks(title="Pixagram - AI Pixel Art Generator", theme=gr.themes.Soft()
|
|
| 268 |
label="Depth ControlNet Scale"
|
| 269 |
)
|
| 270 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
lora_scale = gr.Slider(
|
| 272 |
-
minimum=0.
|
| 273 |
maximum=2.0,
|
| 274 |
value=DEFAULT_PARAMS['lora_scale'],
|
| 275 |
step=0.05,
|
| 276 |
-
label="
|
| 277 |
)
|
| 278 |
|
| 279 |
with gr.Accordion(" InstantID Settings (for portraits)", open=True):
|
|
@@ -367,7 +398,7 @@ with gr.Blocks(title="Pixagram - AI Pixel Art Generator", theme=gr.themes.Soft()
|
|
| 367 |
**[ADAPTIVE] Automatic Adjustments:**
|
| 368 |
- Small faces (< 50K px): Boosts identity preservation to 1.8
|
| 369 |
- Low confidence (< 80%): Increases identity control to 0.9
|
| 370 |
-
- Profile views (> 20
|
| 371 |
- Good quality faces: Uses your selected parameters
|
| 372 |
|
| 373 |
**[PARAMETERS] Parameter Relationships:**
|
|
@@ -447,13 +478,13 @@ with gr.Blocks(title="Pixagram - AI Pixel Art Generator", theme=gr.themes.Soft()
|
|
| 447 |
outputs=all_sliders
|
| 448 |
)
|
| 449 |
|
| 450 |
-
# --- MODIFIED: generate_btn.click (added expression_control_scale) ---
|
| 451 |
generate_btn.click(
|
| 452 |
fn=process_image,
|
| 453 |
inputs=[
|
| 454 |
input_image, prompt, negative_prompt, steps, guidance_scale,
|
| 455 |
depth_control_scale, identity_control_scale, expression_control_scale,
|
| 456 |
-
lora_scale, identity_preservation, strength, enable_color_matching,
|
| 457 |
consistency_mode, seed_input, enable_captions
|
| 458 |
],
|
| 459 |
outputs=[output_image, caption_output]
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
import os
|
| 7 |
|
| 8 |
+
from config import PRESETS, DEFAULT_PARAMS, TRIGGER_WORD, LORA_CHOICES
|
| 9 |
from generator import RetroArtConverter
|
| 10 |
|
| 11 |
|
|
|
|
| 42 |
depth_control_scale,
|
| 43 |
identity_control_scale,
|
| 44 |
expression_control_scale, # <-- NEW
|
| 45 |
+
lora_choice,
|
| 46 |
lora_scale,
|
| 47 |
identity_preservation,
|
| 48 |
strength,
|
|
|
|
| 66 |
depth_control_scale=depth_control_scale,
|
| 67 |
identity_control_scale=identity_control_scale,
|
| 68 |
expression_control_scale=expression_control_scale, # <-- NEW
|
| 69 |
+
lora_choice=lora_choice,
|
| 70 |
lora_scale=lora_scale,
|
| 71 |
identity_preservation=identity_preservation,
|
| 72 |
strength=strength,
|
|
|
|
| 109 |
if converter.models_loaded:
|
| 110 |
status_text = "**[OK] Loaded Models:**\n"
|
| 111 |
status_text += f"- Custom Checkpoint (Horizon): {'[OK] Loaded' if converter.models_loaded['custom_checkpoint'] else '[OK] Using SDXL base'}\n"
|
| 112 |
+
|
| 113 |
+
# Updated LORA status
|
| 114 |
+
lora_status = 'Disabled'
|
| 115 |
+
if converter.models_loaded['lora']:
|
| 116 |
+
loaded_count = sum(1 for loaded in converter.loaded_loras.values() if loaded)
|
| 117 |
+
if loaded_count > 0:
|
| 118 |
+
lora_status = f"[OK] Loaded {loaded_count}/3"
|
| 119 |
+
else:
|
| 120 |
+
lora_status = "[ERROR] All failed"
|
| 121 |
+
status_text += f"- LORAs (Retro, VGA, ...): {lora_status}\n"
|
| 122 |
+
|
| 123 |
status_text += f"- InstantID: {'[OK] Loaded' if converter.models_loaded['instantid'] else ' Disabled'}\n"
|
| 124 |
+
|
| 125 |
+
# Show depth detector type
|
| 126 |
+
depth_type = converter.models_loaded.get('depth_type', 'unknown')
|
| 127 |
+
depth_loaded = converter.models_loaded.get('depth_detector', False)
|
| 128 |
+
if depth_loaded and depth_type:
|
| 129 |
+
status_text += f"- Depth Detector: [OK] {depth_type.upper()} Loaded\n"
|
| 130 |
+
else:
|
| 131 |
+
status_text += f"- Depth Detector: Fallback (grayscale)\n"
|
| 132 |
+
|
| 133 |
+
status_text += f"- OpenPose (Expression): {'[OK] Loaded' if converter.models_loaded.get('openpose', False) else ' Disabled'}\n"
|
| 134 |
+
status_text += f"- MediapipeFace: {'[OK] Loaded' if converter.models_loaded.get('mediapipe_face', False) else ' Disabled'}\n"
|
| 135 |
status_text += f"- IP-Adapter (Face Embeddings): {'[OK] Loaded' if converter.models_loaded.get('ip_adapter', False) else ' Keypoints only'}\n"
|
| 136 |
return status_text
|
| 137 |
return "**Model status unavailable**"
|
|
|
|
| 198 |
scheduler_info = f"""
|
| 199 |
**[CONFIG] Advanced Configuration:**
|
| 200 |
- Pipeline: **Img2Img** (structure preservation)
|
| 201 |
+
- Face System: **CLIP + InsightFace + MediapipeFace** (triple detection)
|
| 202 |
+
- **Depth Detection:** Hierarchical (Leres → Zoe → Midas) - best available automatically selected
|
| 203 |
- **[NEW] Expression Control:** OpenPose-Face (68 keypoints)
|
| 204 |
- **[ADVANCED] Enhanced Resampler:** 10 layers, 20 heads (+3-5% quality)
|
| 205 |
- **[ADVANCED] Adaptive Attention:** Context-aware scaling (+2-3% quality)
|
|
|
|
| 290 |
label="Depth ControlNet Scale"
|
| 291 |
)
|
| 292 |
|
| 293 |
+
# --- NEW: LORA Dropdown ---
|
| 294 |
+
lora_choice = gr.Dropdown(
|
| 295 |
+
label="LORA Style",
|
| 296 |
+
choices=LORA_CHOICES,
|
| 297 |
+
value=DEFAULT_PARAMS['lora_choice'],
|
| 298 |
+
)
|
| 299 |
+
# --- END NEW ---
|
| 300 |
+
|
| 301 |
+
with gr.Row():
|
| 302 |
lora_scale = gr.Slider(
|
| 303 |
+
minimum=0.0,
|
| 304 |
maximum=2.0,
|
| 305 |
value=DEFAULT_PARAMS['lora_scale'],
|
| 306 |
step=0.05,
|
| 307 |
+
label="LORA Scale\nIntensity for selected style" # <-- Modified Label
|
| 308 |
)
|
| 309 |
|
| 310 |
with gr.Accordion(" InstantID Settings (for portraits)", open=True):
|
|
|
|
| 398 |
**[ADAPTIVE] Automatic Adjustments:**
|
| 399 |
- Small faces (< 50K px): Boosts identity preservation to 1.8
|
| 400 |
- Low confidence (< 80%): Increases identity control to 0.9
|
| 401 |
+
- Profile views (> 20° yaw): Enhances preservation to 1.7
|
| 402 |
- Good quality faces: Uses your selected parameters
|
| 403 |
|
| 404 |
**[PARAMETERS] Parameter Relationships:**
|
|
|
|
| 478 |
outputs=all_sliders
|
| 479 |
)
|
| 480 |
|
| 481 |
+
# --- MODIFIED: generate_btn.click (added lora_choice, expression_control_scale) ---
|
| 482 |
generate_btn.click(
|
| 483 |
fn=process_image,
|
| 484 |
inputs=[
|
| 485 |
input_image, prompt, negative_prompt, steps, guidance_scale,
|
| 486 |
depth_control_scale, identity_control_scale, expression_control_scale,
|
| 487 |
+
lora_choice, lora_scale, identity_preservation, strength, enable_color_matching,
|
| 488 |
consistency_mode, seed_input, enable_captions
|
| 489 |
],
|
| 490 |
outputs=[output_image, caption_output]
|