Update app_inference.py
Browse files- app_inference.py +102 -108
app_inference.py
CHANGED
|
@@ -43,6 +43,9 @@ body {
|
|
| 43 |
}
|
| 44 |
"""
|
| 45 |
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
def get_choices(hf_token):
|
| 48 |
api = HfApi(token=hf_token)
|
|
@@ -129,112 +132,103 @@ class InferenceUtil:
|
|
| 129 |
raise type(e)(f'failed to update_model_info, due to: {e}')
|
| 130 |
|
| 131 |
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
with gr.
|
| 135 |
-
with gr.
|
| 136 |
-
with gr.
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
with gr.
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
with gr.
|
| 151 |
-
with gr.
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
content_alpha = gr.Slider(label='Content B-LoRA alpha',
|
| 161 |
-
minimum=0,
|
| 162 |
-
maximum=2,
|
| 163 |
-
step=0.05,
|
| 164 |
-
value=1)
|
| 165 |
-
style_alpha = gr.Slider(label='Style B-LoRA alpha',
|
| 166 |
-
minimum=0,
|
| 167 |
-
maximum=2,
|
| 168 |
-
step=0.05,
|
| 169 |
-
value=1)
|
| 170 |
-
seed = gr.Slider(label='Seed',
|
| 171 |
-
minimum=0,
|
| 172 |
-
maximum=100000,
|
| 173 |
-
step=1,
|
| 174 |
-
value=8888)
|
| 175 |
-
num_steps = gr.Slider(label='Number of Steps',
|
| 176 |
minimum=0,
|
| 177 |
-
maximum=
|
| 178 |
-
step=
|
| 179 |
-
value=
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
}
|
| 44 |
"""
|
| 45 |
|
| 46 |
+
hf_token = os.getenv('HF_TOKEN')
|
| 47 |
+
pipe = InferencePipeline(hf_token)
|
| 48 |
+
app = InferenceUtil(hf_token)
|
| 49 |
|
| 50 |
def get_choices(hf_token):
|
| 51 |
api = HfApi(token=hf_token)
|
|
|
|
| 132 |
raise type(e)(f'failed to update_model_info, due to: {e}')
|
| 133 |
|
| 134 |
|
| 135 |
+
|
| 136 |
+
with gr.Blocks(css=css) as demo:
|
| 137 |
+
with gr.Row(elem_classes="gr-row"):
|
| 138 |
+
with gr.Column():
|
| 139 |
+
with gr.Group(elem_classes="lora-column"):
|
| 140 |
+
gr.Markdown('## Content B-LoRA')
|
| 141 |
+
content_checkbox = gr.Checkbox(label='Use Content Only', value=False)
|
| 142 |
+
content_lora_model_id = gr.Dropdown(label='Model ID', choices=[])
|
| 143 |
+
content_prompt = gr.Text(label='Content instance prompt', interactive=False, max_lines=1)
|
| 144 |
+
content_image = gr.Image(label='Content Image', elem_classes="gr-image")
|
| 145 |
+
with gr.Column():
|
| 146 |
+
with gr.Group(elem_classes="lora-column"):
|
| 147 |
+
gr.Markdown('## Style B-LoRA')
|
| 148 |
+
style_checkbox = gr.Checkbox(label='Use Style Only', value=False)
|
| 149 |
+
style_lora_model_id = gr.Dropdown(label='Model ID', choices=[])
|
| 150 |
+
style_prompt = gr.Text(label='Style instance prompt', interactive=False, max_lines=1)
|
| 151 |
+
style_image = gr.Image(label='Style Image', elem_classes="gr-image")
|
| 152 |
+
with gr.Row(elem_classes="gr-row"):
|
| 153 |
+
with gr.Column():
|
| 154 |
+
with gr.Group():
|
| 155 |
+
prompt = gr.Textbox(
|
| 156 |
+
label='Prompt',
|
| 157 |
+
max_lines=1,
|
| 158 |
+
placeholder='Example: "A [c] in [s] style"'
|
| 159 |
+
)
|
| 160 |
+
result = gr.Image(label='Result')
|
| 161 |
+
with gr.Accordion('Other Parameters', open=False, elem_classes="gr-accordion"):
|
| 162 |
+
content_alpha = gr.Slider(label='Content B-LoRA alpha',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
minimum=0,
|
| 164 |
+
maximum=2,
|
| 165 |
+
step=0.05,
|
| 166 |
+
value=1)
|
| 167 |
+
style_alpha = gr.Slider(label='Style B-LoRA alpha',
|
| 168 |
+
minimum=0,
|
| 169 |
+
maximum=2,
|
| 170 |
+
step=0.05,
|
| 171 |
+
value=1)
|
| 172 |
+
seed = gr.Slider(label='Seed',
|
| 173 |
+
minimum=0,
|
| 174 |
+
maximum=100000,
|
| 175 |
+
step=1,
|
| 176 |
+
value=8888)
|
| 177 |
+
num_steps = gr.Slider(label='Number of Steps',
|
| 178 |
+
minimum=0,
|
| 179 |
+
maximum=100,
|
| 180 |
+
step=1,
|
| 181 |
+
value=50)
|
| 182 |
+
guidance_scale = gr.Slider(label='CFG Scale',
|
| 183 |
+
minimum=0,
|
| 184 |
+
maximum=50,
|
| 185 |
+
step=0.1,
|
| 186 |
+
value=7.5)
|
| 187 |
+
run_button = gr.Button('Generate')
|
| 188 |
+
demo.load(demo_init, inputs=[],
|
| 189 |
+
outputs=[content_lora_model_id, content_prompt, content_image, style_lora_model_id, style_prompt,
|
| 190 |
+
style_image, prompt], queue=False, show_progress="hidden")
|
| 191 |
+
content_lora_model_id.change(
|
| 192 |
+
fn=app.update_model_info,
|
| 193 |
+
inputs=content_lora_model_id,
|
| 194 |
+
outputs=[
|
| 195 |
+
content_prompt,
|
| 196 |
+
content_image,
|
| 197 |
+
])
|
| 198 |
+
style_lora_model_id.change(
|
| 199 |
+
fn=app.update_model_info,
|
| 200 |
+
inputs=style_lora_model_id,
|
| 201 |
+
outputs=[
|
| 202 |
+
style_prompt,
|
| 203 |
+
style_image,
|
| 204 |
+
])
|
| 205 |
+
style_prompt.change(
|
| 206 |
+
fn=lambda content_blora_prompt,
|
| 207 |
+
style_blora_prompt: f'{content_blora_prompt} in {style_blora_prompt[0].lower() + style_blora_prompt[1:]} style' if style_blora_prompt else content_blora_prompt,
|
| 208 |
+
inputs=[content_prompt, style_prompt],
|
| 209 |
+
outputs=prompt,
|
| 210 |
+
)
|
| 211 |
+
content_prompt.change(
|
| 212 |
+
fn=lambda content_blora_prompt,
|
| 213 |
+
style_blora_prompt: f'{content_blora_prompt} in {style_blora_prompt[0].lower() + style_blora_prompt[1:]} style' if content_blora_prompt else style_blora_prompt,
|
| 214 |
+
inputs=[content_prompt, style_prompt],
|
| 215 |
+
outputs=prompt,
|
| 216 |
+
)
|
| 217 |
+
content_checkbox.change(toggle_column, inputs=[content_checkbox],
|
| 218 |
+
outputs=[style_lora_model_id])
|
| 219 |
+
style_checkbox.change(toggle_column, inputs=[style_checkbox],
|
| 220 |
+
outputs=[content_lora_model_id])
|
| 221 |
+
inputs = [
|
| 222 |
+
content_lora_model_id,
|
| 223 |
+
style_lora_model_id,
|
| 224 |
+
prompt,
|
| 225 |
+
content_alpha,
|
| 226 |
+
style_alpha,
|
| 227 |
+
seed,
|
| 228 |
+
num_steps,
|
| 229 |
+
guidance_scale,
|
| 230 |
+
]
|
| 231 |
+
prompt.submit(fn=pipe.run, inputs=inputs, outputs=result)
|
| 232 |
+
run_button.click(fn=pipe.run, inputs=inputs, outputs=result)
|
| 233 |
+
|
| 234 |
+
demo.queue(max_size=10).launch(share=False)
|