Spaces:
Sleeping
Sleeping
File size: 5,551 Bytes
e76f467 41eb2e8 fcb27fb 41eb2e8 e423e8d a827413 e423e8d 0b22058 f48ecfa 0b22058 cb202cc e423e8d cb202cc 0b22058 e423e8d cb202cc 0b22058 4d4e4ab 0b22058 4f61531 0b22058 cb202cc d8c88bb 0b22058 cb202cc 85408e4 c92760e 0b22058 1b50209 41eb2e8 e423e8d 41eb2e8 0b22058 e423e8d 0b22058 e423e8d 4d4e4ab 0b22058 85408e4 7abaf33 e423e8d e76f467 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
import os
import gradio as gr
import json
from gradio_client import Client
with open('loras.json', 'r') as f:
loras = json.load(f)
def infer (selected_index, prompt, style_prompt, inf_steps, guidance_scale, width, height, seed, lora_weight, progress=gr.Progress(track_tqdm=True)):
if selected_index is None:
raise gr.Error("You must select a LoRA before proceeding.")
# custom_model="lichorosario/dott_remastered_style_lora_sdxl"
# weight_name="dott_style.safetensors"
selected_lora = loras[selected_index]
custom_model = selected_lora["repo"]
trigger_word = selected_lora["trigger_word"]
client = Client("fffiloni/sd-xl-custom-model")
result = client.predict(
custom_model=custom_model,
api_name="/load_model"
)
weight_name = result[2]['value']
client = Client("fffiloni/sd-xl-custom-model")
prompt = trigger_word+". "+prompt+". "+style_prompt
result = client.predict(
custom_model=custom_model,
weight_name=weight_name,
prompt=prompt,
inf_steps=inf_steps,
guidance_scale=guidance_scale,
width=width,
height=height,
seed=seed,
lora_weight=lora_weight,
api_name="/infer"
)
new_result = result + (prompt, )
return new_result
def update_selection(evt: gr.SelectData):
selected_lora = loras[evt.index]
new_placeholder = f"Type a prompt for {selected_lora['title']}"
lora_repo = selected_lora["repo"]
updated_text = f"### Selected: [{lora_repo}](https://huggingface.co/{lora_repo}) ✨"
return (
gr.update(placeholder=new_placeholder),
updated_text,
evt.index
)
css="""
#col-container{
margin: 0 auto;
max-width: 720px;
text-align: left;
}
div#warning-duplicate {
background-color: #ebf5ff;
padding: 0 16px 16px;
margin: 20px 0;
}
div#warning-duplicate > .gr-prose > h2, div#warning-duplicate > .gr-prose > p {
color: #0f4592!important;
}
div#warning-duplicate strong {
color: #0f4592;
}
p.actions {
display: flex;
align-items: center;
margin: 20px 0;
}
div#warning-duplicate .actions a {
display: inline-block;
margin-right: 10px;
}
button#load_model_btn{
height: 46px;
}
#status_info{
font-size: 0.9em;
}
.custom-color {
color: #030303 !important;
}
"""
with gr.Blocks(css=css) as demo:
gr.Markdown("# lichorosario LoRA Portfolio")
gr.Markdown(
"### This is my portfolio.\n"
"**Note**: Generation quality may vary. For best results, adjust the parameters.\n"
"Special thanks to [@artificialguybr](https://huggingface.co/artificialguybr) and [@fffiloni](https://huggingface.co/fffiloni)."
)
with gr.Row():
with gr.Column(scale=2):
prompt_in = gr.Textbox(
label="Your Prompt",
info = "Dont' forget to include your trigger word if necessary"
)
style_prompt_in = gr.Textbox(
label="Your Style Prompt"
)
selected_info = gr.Markdown("")
used_prompt = gr.Textbox(
label="Used prompt"
)
with gr.Column(scale=1):
gallery = gr.Gallery(
[(item["image"], item["title"]) for item in loras],
label="LoRA Gallery",
allow_preview=False,
columns=2
)
with gr.Column(elem_id="col-container"):
with gr.Accordion("Advanced Settings", open=False):
with gr.Row():
inf_steps = gr.Slider(
label="Inference steps",
minimum=12,
maximum=50,
step=1,
value=25
)
guidance_scale = gr.Slider(
label="Guidance scale",
minimum=0.0,
maximum=50.0,
step=0.1,
value=7.5
)
with gr.Row():
width = gr.Slider(
label="Width",
minimum=256,
maximum=2048,
step=32,
value=1024,
)
height = gr.Slider(
label="Height",
minimum=256,
maximum=2048,
step=32,
value=1024,
)
with gr.Row():
seed = gr.Slider(
label="Seed",
info = "-1 denotes a random seed",
minimum=-1,
maximum=423538377342,
step=1,
value=-1
)
last_used_seed = gr.Number(
label = "Last used seed",
info = "the seed used in the last generation",
)
lora_weight = gr.Slider(
label="LoRa weigth",
minimum=0.0,
maximum=1.0,
step=0.01,
value=1.0
)
submit_btn = gr.Button("Submit")
image_out = gr.Image(label="Image output")
selected_index = gr.State(None)
submit_btn.click(
fn = infer,
inputs = [selected_index, prompt_in, style_prompt_in, inf_steps, guidance_scale, width, height, seed, lora_weight],
outputs = [image_out, last_used_seed, used_prompt]
)
gallery.select(update_selection, outputs=[prompt_in, selected_info, selected_index])
demo.launch()
|