Spaces:
Sleeping
Sleeping
refactor: change structure
Browse files- app.py +13 -8
- inference_api.py +37 -7
- inference_models/__init__.py +7 -0
- ccddpm_pipeline.py β inference_models/ccddpm_pipeline.py +0 -0
- class_guidance_inference.py β inference_models/class_guidance_inference.py +1 -1
- stable_diffusion_inference.py β inference_models/stable_diffusion_inference.py +0 -0
- unconditional_diffusion_inference.py β inference_models/unconditional_diffusion_inference.py +0 -0
- local_app.py +254 -0
- test/test_inference.py +1 -1
app.py
CHANGED
|
@@ -7,10 +7,10 @@
|
|
| 7 |
"""
|
| 8 |
import gradio as gr
|
| 9 |
|
| 10 |
-
from unconditional_diffusion_inference import inference_unconditional
|
| 11 |
-
from class_guidance_inference import inference_class_guidance, GENDER_CHOICES
|
| 12 |
-
from stable_diffusion_inference import inference_sd, MAX_SEED
|
| 13 |
-
from inference_api import
|
| 14 |
from utils import timer
|
| 15 |
|
| 16 |
MAX_IMAGE_SIZE = 1024
|
|
@@ -24,11 +24,16 @@ examples = [
|
|
| 24 |
]
|
| 25 |
|
| 26 |
css = """
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
.gradio-container {
|
| 28 |
background-image: url('https://lh3.googleusercontent.com/d/1y7H4WIjnBAcNvvi-3qOV_ORE-jMXP4fr');
|
| 29 |
background-repeat: no-repeat;
|
| 30 |
background-attachment: fixed;
|
| 31 |
background-position: center;
|
|
|
|
| 32 |
}
|
| 33 |
#col-container {
|
| 34 |
margin: 0 auto;
|
|
@@ -209,12 +214,12 @@ with gr.Blocks(theme=theme, css=css) as demo:
|
|
| 209 |
value=50,
|
| 210 |
)
|
| 211 |
|
| 212 |
-
gr.Examples(examples=examples, inputs=[prompt], outputs=[result_3], fn=
|
| 213 |
cache_examples=True, cache_mode="lazy")
|
| 214 |
|
| 215 |
gr.on(
|
| 216 |
triggers=[run_button_1.click],
|
| 217 |
-
fn=
|
| 218 |
inputs=[
|
| 219 |
seed_1,
|
| 220 |
randomize_seed_1,
|
|
@@ -225,7 +230,7 @@ with gr.Blocks(theme=theme, css=css) as demo:
|
|
| 225 |
|
| 226 |
gr.on(
|
| 227 |
triggers=[run_button_2.click],
|
| 228 |
-
fn=
|
| 229 |
inputs=[
|
| 230 |
gender_select_radio,
|
| 231 |
seed_2,
|
|
@@ -237,7 +242,7 @@ with gr.Blocks(theme=theme, css=css) as demo:
|
|
| 237 |
|
| 238 |
gr.on(
|
| 239 |
triggers=[run_button_3.click, prompt.submit],
|
| 240 |
-
fn=
|
| 241 |
inputs=[
|
| 242 |
prompt,
|
| 243 |
negative_prompt,
|
|
|
|
| 7 |
"""
|
| 8 |
import gradio as gr
|
| 9 |
|
| 10 |
+
from inference_models.unconditional_diffusion_inference import inference_unconditional
|
| 11 |
+
from inference_models.class_guidance_inference import inference_class_guidance, GENDER_CHOICES
|
| 12 |
+
from inference_models.stable_diffusion_inference import inference_sd, MAX_SEED
|
| 13 |
+
from inference_api import api_unconditional, api_class_guidance, api_sd
|
| 14 |
from utils import timer
|
| 15 |
|
| 16 |
MAX_IMAGE_SIZE = 1024
|
|
|
|
| 24 |
]
|
| 25 |
|
| 26 |
css = """
|
| 27 |
+
body {
|
| 28 |
+
background: linear-gradient(135deg, #f9e2e6 0%, #e8f3fc 50%, #e2f9f2 100%);
|
| 29 |
+
min-height: 100vh;
|
| 30 |
+
}
|
| 31 |
.gradio-container {
|
| 32 |
background-image: url('https://lh3.googleusercontent.com/d/1y7H4WIjnBAcNvvi-3qOV_ORE-jMXP4fr');
|
| 33 |
background-repeat: no-repeat;
|
| 34 |
background-attachment: fixed;
|
| 35 |
background-position: center;
|
| 36 |
+
background-size: contain;
|
| 37 |
}
|
| 38 |
#col-container {
|
| 39 |
margin: 0 auto;
|
|
|
|
| 214 |
value=50,
|
| 215 |
)
|
| 216 |
|
| 217 |
+
gr.Examples(examples=examples, inputs=[prompt], outputs=[result_3], fn=api_sd,
|
| 218 |
cache_examples=True, cache_mode="lazy")
|
| 219 |
|
| 220 |
gr.on(
|
| 221 |
triggers=[run_button_1.click],
|
| 222 |
+
fn=api_unconditional,
|
| 223 |
inputs=[
|
| 224 |
seed_1,
|
| 225 |
randomize_seed_1,
|
|
|
|
| 230 |
|
| 231 |
gr.on(
|
| 232 |
triggers=[run_button_2.click],
|
| 233 |
+
fn=api_class_guidance,
|
| 234 |
inputs=[
|
| 235 |
gender_select_radio,
|
| 236 |
seed_2,
|
|
|
|
| 242 |
|
| 243 |
gr.on(
|
| 244 |
triggers=[run_button_3.click, prompt.submit],
|
| 245 |
+
fn=api_sd,
|
| 246 |
inputs=[
|
| 247 |
prompt,
|
| 248 |
negative_prompt,
|
inference_api.py
CHANGED
|
@@ -10,12 +10,42 @@ from gradio_client import Client
|
|
| 10 |
inference_url = "https://a6e7d20f9bf8c7fb66.gradio.live/"
|
| 11 |
|
| 12 |
|
| 13 |
-
def
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
client = Client(inference_url)
|
| 20 |
|
| 21 |
result = client.predict(
|
|
@@ -25,6 +55,6 @@ def inference(prompt,
|
|
| 25 |
randomize_seed=randomize_seed,
|
| 26 |
guidance_scale=guidance_scale,
|
| 27 |
num_inference_steps=num_inference_steps,
|
| 28 |
-
api_name="/
|
| 29 |
)
|
| 30 |
return result
|
|
|
|
| 10 |
inference_url = "https://a6e7d20f9bf8c7fb66.gradio.live/"
|
| 11 |
|
| 12 |
|
| 13 |
+
def api_unconditional(seed,
|
| 14 |
+
randomize_seed=False,
|
| 15 |
+
num_inference_steps=20):
|
| 16 |
+
client = Client(inference_url)
|
| 17 |
+
|
| 18 |
+
result = client.predict(
|
| 19 |
+
seed=seed,
|
| 20 |
+
randomize_seed=randomize_seed,
|
| 21 |
+
num_inference_steps=num_inference_steps,
|
| 22 |
+
api_name="/inference_unconditional"
|
| 23 |
+
)
|
| 24 |
+
return result
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def api_class_guidance(label_name,
|
| 28 |
+
seed=0,
|
| 29 |
+
randomize_seed=False,
|
| 30 |
+
num_inference_steps=20):
|
| 31 |
+
client = Client(inference_url)
|
| 32 |
+
|
| 33 |
+
result = client.predict(
|
| 34 |
+
label_name=label_name,
|
| 35 |
+
seed=seed,
|
| 36 |
+
randomize_seed=randomize_seed,
|
| 37 |
+
num_inference_steps=num_inference_steps,
|
| 38 |
+
api_name="/inference_class_guidance"
|
| 39 |
+
)
|
| 40 |
+
return result
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def api_sd(prompt,
|
| 44 |
+
negative_prompt="",
|
| 45 |
+
seed=0,
|
| 46 |
+
randomize_seed=False,
|
| 47 |
+
guidance_scale=7.5,
|
| 48 |
+
num_inference_steps=20):
|
| 49 |
client = Client(inference_url)
|
| 50 |
|
| 51 |
result = client.predict(
|
|
|
|
| 55 |
randomize_seed=randomize_seed,
|
| 56 |
guidance_scale=guidance_scale,
|
| 57 |
num_inference_steps=num_inference_steps,
|
| 58 |
+
api_name="/inference_sd"
|
| 59 |
)
|
| 60 |
return result
|
inference_models/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: UTF-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
@Time : 30/05/2025 23:56
|
| 4 |
+
@Author : xiaoguangliang
|
| 5 |
+
@File : __init__.py.py
|
| 6 |
+
@Project : Faice_text2face
|
| 7 |
+
"""
|
ccddpm_pipeline.py β inference_models/ccddpm_pipeline.py
RENAMED
|
File without changes
|
class_guidance_inference.py β inference_models/class_guidance_inference.py
RENAMED
|
@@ -8,7 +8,7 @@
|
|
| 8 |
import torch
|
| 9 |
import random
|
| 10 |
import numpy as np
|
| 11 |
-
from ccddpm_pipeline import CCDDPMPipeline
|
| 12 |
from accelerate import Accelerator
|
| 13 |
import gradio as gr
|
| 14 |
import spaces
|
|
|
|
| 8 |
import torch
|
| 9 |
import random
|
| 10 |
import numpy as np
|
| 11 |
+
from inference_models.ccddpm_pipeline import CCDDPMPipeline
|
| 12 |
from accelerate import Accelerator
|
| 13 |
import gradio as gr
|
| 14 |
import spaces
|
stable_diffusion_inference.py β inference_models/stable_diffusion_inference.py
RENAMED
|
File without changes
|
unconditional_diffusion_inference.py β inference_models/unconditional_diffusion_inference.py
RENAMED
|
File without changes
|
local_app.py
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: UTF-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
@Time : 28/05/2025 16:29
|
| 4 |
+
@Author : xiaoguangliang
|
| 5 |
+
@File : app.py
|
| 6 |
+
@Project : Faice_text2face
|
| 7 |
+
"""
|
| 8 |
+
import gradio as gr
|
| 9 |
+
|
| 10 |
+
from inference_models.unconditional_diffusion_inference import inference_unconditional
|
| 11 |
+
from inference_models.class_guidance_inference import inference_class_guidance, GENDER_CHOICES
|
| 12 |
+
from inference_models.stable_diffusion_inference import inference_sd, MAX_SEED
|
| 13 |
+
from utils import timer
|
| 14 |
+
|
| 15 |
+
MAX_IMAGE_SIZE = 1024
|
| 16 |
+
|
| 17 |
+
examples = [
|
| 18 |
+
"Portrait of a young woman with long wavy hair, soft studio lighting, high contrast, 4k resolution, professional headshot",
|
| 19 |
+
"Close-up of a smiling man with sharp jawline, cinematic lighting, shallow depth of field, bokeh background",
|
| 20 |
+
"Candid portrait, natural light, slight smile, outdoor background, wind-blown hair",
|
| 21 |
+
"Retro 80s style portrait, neon colors, grainy texture, bold shadows, high contrast",
|
| 22 |
+
"Black and white portrait of an elderly woman with wrinkles, deep shadows, textured background"
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
css = """
|
| 26 |
+
.gradio-container {
|
| 27 |
+
background-image: url('https://lh3.googleusercontent.com/d/1y7H4WIjnBAcNvvi-3qOV_ORE-jMXP4fr');
|
| 28 |
+
background-repeat: no-repeat;
|
| 29 |
+
background-attachment: fixed;
|
| 30 |
+
background-position: center;
|
| 31 |
+
}
|
| 32 |
+
#col-container {
|
| 33 |
+
margin: 0 auto;
|
| 34 |
+
max-width: 960px;
|
| 35 |
+
background-color: rgba(255, 255, 255, 0.85);
|
| 36 |
+
border-radius: 20px;
|
| 37 |
+
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
|
| 38 |
+
padding: 24px;
|
| 39 |
+
backdrop-filter: blur(20px);
|
| 40 |
+
}
|
| 41 |
+
.gr-button-primary {
|
| 42 |
+
background: linear-gradient(90deg, #6b9dfc, #8c6bfc) !important;
|
| 43 |
+
border: none !important;
|
| 44 |
+
transition: all 0.3s ease;
|
| 45 |
+
}
|
| 46 |
+
.gr-button-primary:hover {
|
| 47 |
+
transform: translateY(-2px);
|
| 48 |
+
box-shadow: 0 5px 15px rgba(108, 99, 255, 0.3);
|
| 49 |
+
}
|
| 50 |
+
.gr-form {
|
| 51 |
+
border-radius: 12px;
|
| 52 |
+
background-color: rgba(255, 255, 255, 0.7);
|
| 53 |
+
}
|
| 54 |
+
.gr-accordion {
|
| 55 |
+
border-radius: 12px;
|
| 56 |
+
overflow: hidden;
|
| 57 |
+
}
|
| 58 |
+
h1 {
|
| 59 |
+
background: linear-gradient(90deg, #6b9dfc, #8c6bfc);
|
| 60 |
+
-webkit-background-clip: text;
|
| 61 |
+
-webkit-text-fill-color: transparent;
|
| 62 |
+
font-weight: 800;
|
| 63 |
+
}
|
| 64 |
+
"""
|
| 65 |
+
|
| 66 |
+
theme = gr.themes.Ocean(
|
| 67 |
+
primary_hue="fuchsia",
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
with gr.Blocks(theme=theme, css=css) as demo:
|
| 71 |
+
with gr.Column(elem_id="col-container"):
|
| 72 |
+
gr.HTML("""
|
| 73 |
+
<div align="center" style="margin-bottom: 20px;">
|
| 74 |
+
<img src='https://lh3.googleusercontent.com/d/1dmZMaOhZxcC_93Rc0ReYTB9oQEUuFJFu' width="160">
|
| 75 |
+
<p style="font-size: 16px; max-width: 960px; margin: 5px auto;">
|
| 76 |
+
Human Faces Generation with Diffusion Models.
|
| 77 |
+
</p>
|
| 78 |
+
<p style="font-size: 15px;">
|
| 79 |
+
π <a href="https://github.com/frankcholula/faice/blob/main/paper/human_faces_generation_with_diffusion_models.pdf" target="_blank">Report</a>
|
| 80 |
+
|
|
| 81 |
+
π» <a href="https://github.com/frankcholula/faice" target="_blank">Code</a>
|
| 82 |
+
</p>
|
| 83 |
+
</div>
|
| 84 |
+
""")
|
| 85 |
+
|
| 86 |
+
gr.Markdown("---")
|
| 87 |
+
with gr.Row():
|
| 88 |
+
gr.Markdown("## Part 1. Unconditional Face Generation")
|
| 89 |
+
run_button_1 = gr.Button("Run", scale=0, variant="primary", elem_classes="gr-button-primary")
|
| 90 |
+
|
| 91 |
+
result_1 = gr.Image(label="Result", show_label=False)
|
| 92 |
+
|
| 93 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 94 |
+
seed_1 = gr.Slider(
|
| 95 |
+
label="Seed",
|
| 96 |
+
minimum=0,
|
| 97 |
+
maximum=MAX_SEED,
|
| 98 |
+
step=1,
|
| 99 |
+
value=0,
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
randomize_seed_1 = gr.Checkbox(label="Randomize seed", value=True)
|
| 103 |
+
|
| 104 |
+
with gr.Row():
|
| 105 |
+
num_inference_steps_1 = gr.Slider(
|
| 106 |
+
label="Number of inference steps",
|
| 107 |
+
minimum=20,
|
| 108 |
+
maximum=1000,
|
| 109 |
+
step=1,
|
| 110 |
+
value=100,
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
gr.Markdown("---")
|
| 114 |
+
with gr.Row():
|
| 115 |
+
gr.Markdown("## Part 2. Class Guidance Face Generation")
|
| 116 |
+
run_button_2 = gr.Button("Run", scale=0, variant="primary")
|
| 117 |
+
|
| 118 |
+
gender_select_radio = gr.Radio(
|
| 119 |
+
label="Select Gender",
|
| 120 |
+
choices=GENDER_CHOICES,
|
| 121 |
+
value=GENDER_CHOICES[0],
|
| 122 |
+
)
|
| 123 |
+
result_2 = gr.Image(label="Result", show_label=False)
|
| 124 |
+
|
| 125 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 126 |
+
seed_2 = gr.Slider(
|
| 127 |
+
label="Seed",
|
| 128 |
+
minimum=0,
|
| 129 |
+
maximum=MAX_SEED,
|
| 130 |
+
step=1,
|
| 131 |
+
value=0,
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
randomize_seed_2 = gr.Checkbox(label="Randomize seed", value=True)
|
| 135 |
+
|
| 136 |
+
with gr.Row():
|
| 137 |
+
num_inference_steps_2 = gr.Slider(
|
| 138 |
+
label="Number of inference steps",
|
| 139 |
+
minimum=20,
|
| 140 |
+
maximum=1000,
|
| 141 |
+
step=1,
|
| 142 |
+
value=100,
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
gr.Markdown("---")
|
| 146 |
+
gr.Markdown("## Part 3. Text-to-Face Generation")
|
| 147 |
+
with gr.Row():
|
| 148 |
+
prompt = gr.Text(
|
| 149 |
+
label="Prompt",
|
| 150 |
+
show_label=False,
|
| 151 |
+
max_lines=1,
|
| 152 |
+
placeholder="Enter your prompt",
|
| 153 |
+
container=False,
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
run_button_3 = gr.Button("Run", scale=0, variant="primary")
|
| 157 |
+
|
| 158 |
+
result_3 = gr.Image(label="Result", show_label=False)
|
| 159 |
+
|
| 160 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 161 |
+
negative_prompt = gr.Text(
|
| 162 |
+
label="Negative prompt",
|
| 163 |
+
max_lines=1,
|
| 164 |
+
placeholder="Enter a negative prompt",
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
seed_3 = gr.Slider(
|
| 168 |
+
label="Seed",
|
| 169 |
+
minimum=0,
|
| 170 |
+
maximum=MAX_SEED,
|
| 171 |
+
step=1,
|
| 172 |
+
value=0,
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
randomize_seed_3 = gr.Checkbox(label="Randomize seed", value=True)
|
| 176 |
+
|
| 177 |
+
# with gr.Row():
|
| 178 |
+
# width = gr.Slider(
|
| 179 |
+
# label="Width",
|
| 180 |
+
# minimum=512,
|
| 181 |
+
# maximum=MAX_IMAGE_SIZE,
|
| 182 |
+
# step=32,
|
| 183 |
+
# value=1024,
|
| 184 |
+
# )
|
| 185 |
+
#
|
| 186 |
+
# height = gr.Slider(
|
| 187 |
+
# label="Height",
|
| 188 |
+
# minimum=512,
|
| 189 |
+
# maximum=MAX_IMAGE_SIZE,
|
| 190 |
+
# step=32,
|
| 191 |
+
# value=1024,
|
| 192 |
+
# )
|
| 193 |
+
|
| 194 |
+
with gr.Row():
|
| 195 |
+
guidance_scale = gr.Slider(
|
| 196 |
+
label="Guidance scale",
|
| 197 |
+
minimum=0.0,
|
| 198 |
+
maximum=7.5,
|
| 199 |
+
step=0.1,
|
| 200 |
+
value=7.5,
|
| 201 |
+
)
|
| 202 |
+
|
| 203 |
+
num_inference_steps_3 = gr.Slider(
|
| 204 |
+
label="Number of inference steps",
|
| 205 |
+
minimum=1,
|
| 206 |
+
maximum=100,
|
| 207 |
+
step=1,
|
| 208 |
+
value=50,
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
gr.Examples(examples=examples, inputs=[prompt], outputs=[result_3], fn=inference_sd,
|
| 212 |
+
cache_examples=True, cache_mode="lazy")
|
| 213 |
+
|
| 214 |
+
gr.on(
|
| 215 |
+
triggers=[run_button_1.click],
|
| 216 |
+
fn=inference_unconditional,
|
| 217 |
+
inputs=[
|
| 218 |
+
seed_1,
|
| 219 |
+
randomize_seed_1,
|
| 220 |
+
num_inference_steps_1,
|
| 221 |
+
],
|
| 222 |
+
outputs=[result_1],
|
| 223 |
+
)
|
| 224 |
+
|
| 225 |
+
gr.on(
|
| 226 |
+
triggers=[run_button_2.click],
|
| 227 |
+
fn=inference_class_guidance,
|
| 228 |
+
inputs=[
|
| 229 |
+
gender_select_radio,
|
| 230 |
+
seed_2,
|
| 231 |
+
randomize_seed_2,
|
| 232 |
+
num_inference_steps_2,
|
| 233 |
+
],
|
| 234 |
+
outputs=[result_2],
|
| 235 |
+
)
|
| 236 |
+
|
| 237 |
+
gr.on(
|
| 238 |
+
triggers=[run_button_3.click, prompt.submit],
|
| 239 |
+
fn=inference_sd,
|
| 240 |
+
inputs=[
|
| 241 |
+
prompt,
|
| 242 |
+
negative_prompt,
|
| 243 |
+
seed_3,
|
| 244 |
+
randomize_seed_3,
|
| 245 |
+
guidance_scale,
|
| 246 |
+
num_inference_steps_3,
|
| 247 |
+
],
|
| 248 |
+
outputs=[result_3],
|
| 249 |
+
)
|
| 250 |
+
|
| 251 |
+
if __name__ == "__main__":
|
| 252 |
+
with timer("All tasks"):
|
| 253 |
+
# demo.launch(mcp_server=True)
|
| 254 |
+
demo.launch(share=True, allowed_paths=["./"])
|
test/test_inference.py
CHANGED
|
@@ -5,7 +5,7 @@
|
|
| 5 |
@File : test_inference.py
|
| 6 |
@Project : Faice_text2face
|
| 7 |
"""
|
| 8 |
-
from stable_diffusion_inference import inference_sd
|
| 9 |
from utils import timer
|
| 10 |
|
| 11 |
prompt = "Portrait of a young woman with long wavy hair, soft studio lighting, high contrast, 4k resolution, professional headshot"
|
|
|
|
| 5 |
@File : test_inference.py
|
| 6 |
@Project : Faice_text2face
|
| 7 |
"""
|
| 8 |
+
from inference_models.stable_diffusion_inference import inference_sd
|
| 9 |
from utils import timer
|
| 10 |
|
| 11 |
prompt = "Portrait of a young woman with long wavy hair, soft studio lighting, high contrast, 4k resolution, professional headshot"
|