Spaces:
Sleeping
Sleeping
Refactor for separate buttons for each function
Browse files
app.py
CHANGED
|
@@ -137,7 +137,7 @@ def create_passport(img: Image.Image) -> Image.Image:
|
|
| 137 |
return bg
|
| 138 |
|
| 139 |
@spaces.GPU
|
| 140 |
-
def create_avatar(img: Image.Image) -> Image.Image:
|
| 141 |
"""Stylized AI avatar using Stable Diffusion Img2Img with user inputs"""
|
| 142 |
# Enhance face
|
| 143 |
img_enhanced = enhance_face(img)
|
|
@@ -223,29 +223,37 @@ with gr.Blocks(theme=gr.themes.Soft(), title="FaceForge AI") as demo:
|
|
| 223 |
step=0.5
|
| 224 |
)
|
| 225 |
|
| 226 |
-
process_btn = gr.Button("✨ Generate All Images", variant="primary", size="lg")
|
| 227 |
-
|
| 228 |
with gr.Column(scale=1):
|
| 229 |
gr.Markdown("### Results")
|
|
|
|
|
|
|
| 230 |
output_headshot = gr.Image(label="💼 Professional Headshot", type="pil")
|
|
|
|
|
|
|
| 231 |
output_passport = gr.Image(label="🛂 Passport Photo", type="pil")
|
|
|
|
|
|
|
| 232 |
output_avatar = gr.Image(label="🎭 AI Avatar", type="pil")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
|
| 234 |
-
# ---
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
final_prompt = custom.strip() if custom and custom.strip() != "" else preset_prompt
|
| 240 |
-
headshot = create_headshot(img)
|
| 241 |
-
passport = create_passport(img)
|
| 242 |
-
avatar = create_avatar(img, final_prompt, strength, guidance)
|
| 243 |
-
return headshot, passport, avatar
|
| 244 |
-
|
| 245 |
-
process_btn.click(
|
| 246 |
-
fn=process_all_with_params,
|
| 247 |
inputs=[input_image, preset_prompt, custom_prompt, strength_slider, guidance_slider],
|
| 248 |
-
outputs=[
|
| 249 |
)
|
| 250 |
|
| 251 |
gr.Markdown(
|
|
|
|
| 137 |
return bg
|
| 138 |
|
| 139 |
@spaces.GPU
|
| 140 |
+
def create_avatar(img: Image.Image, prompt: str, strength: float, guidance_scale: float) -> Image.Image:
|
| 141 |
"""Stylized AI avatar using Stable Diffusion Img2Img with user inputs"""
|
| 142 |
# Enhance face
|
| 143 |
img_enhanced = enhance_face(img)
|
|
|
|
| 223 |
step=0.5
|
| 224 |
)
|
| 225 |
|
|
|
|
|
|
|
| 226 |
with gr.Column(scale=1):
|
| 227 |
gr.Markdown("### Results")
|
| 228 |
+
|
| 229 |
+
# --- Independent Outputs & Buttons ---
|
| 230 |
output_headshot = gr.Image(label="💼 Professional Headshot", type="pil")
|
| 231 |
+
btn_headshot = gr.Button("📸 Generate Headshot", variant="secondary")
|
| 232 |
+
|
| 233 |
output_passport = gr.Image(label="🛂 Passport Photo", type="pil")
|
| 234 |
+
btn_passport = gr.Button("🪪 Generate Passport", variant="secondary")
|
| 235 |
+
|
| 236 |
output_avatar = gr.Image(label="🎭 AI Avatar", type="pil")
|
| 237 |
+
btn_avatar = gr.Button("✨ Generate Avatar", variant="primary")
|
| 238 |
+
|
| 239 |
+
# --- Functions for individual generations ---
|
| 240 |
+
def run_headshot(img):
|
| 241 |
+
return create_headshot(img)
|
| 242 |
+
|
| 243 |
+
def run_passport(img):
|
| 244 |
+
return create_passport(img)
|
| 245 |
+
|
| 246 |
+
def run_avatar(img, preset_label, custom, strength, guidance):
|
| 247 |
+
final_prompt = custom.strip() if custom and custom.strip() != "" else PROMPT_MAP[preset_label]
|
| 248 |
+
return create_avatar(img, final_prompt, strength, guidance)
|
| 249 |
|
| 250 |
+
# --- Button actions ---
|
| 251 |
+
btn_headshot.click(fn=run_headshot, inputs=[input_image], outputs=[output_headshot])
|
| 252 |
+
btn_passport.click(fn=run_passport, inputs=[input_image], outputs=[output_passport])
|
| 253 |
+
btn_avatar.click(
|
| 254 |
+
fn=run_avatar,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
inputs=[input_image, preset_prompt, custom_prompt, strength_slider, guidance_slider],
|
| 256 |
+
outputs=[output_avatar]
|
| 257 |
)
|
| 258 |
|
| 259 |
gr.Markdown(
|