Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,8 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import login
|
| 3 |
import os
|
| 4 |
|
|
|
|
|
|
|
| 5 |
hf_token = os.environ.get("HF_TOKEN")
|
| 6 |
login(token=hf_token)
|
| 7 |
|
|
@@ -59,6 +61,9 @@ def infer(use_custom_model, model_name, custom_lora_weight, image_in, prompt, ne
|
|
| 59 |
prompt = prompt
|
| 60 |
negative_prompt = negative_prompt
|
| 61 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
image_in = resize_image(image_in, "resized_input.jpg", 1024)
|
| 64 |
|
|
@@ -73,6 +78,10 @@ def infer(use_custom_model, model_name, custom_lora_weight, image_in, prompt, ne
|
|
| 73 |
image = Image.fromarray(image)
|
| 74 |
|
| 75 |
if use_custom_model:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
custom_model = model_name
|
| 77 |
|
| 78 |
# This is where you load your trained weights
|
|
@@ -111,9 +120,46 @@ css="""
|
|
| 111 |
max-width: 680px;
|
| 112 |
text-align: left;
|
| 113 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
"""
|
|
|
|
| 115 |
with gr.Blocks(css=css) as demo:
|
| 116 |
with gr.Column(elem_id="col-container"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
gr.HTML("""
|
| 118 |
<h2 style="text-align: center;">SD-XL Control LoRas</h2>
|
| 119 |
<p style="text-align: center;">Use StableDiffusion XL with <a href="https://huggingface.co/collections/diffusers/sdxl-controlnets-64f9c35846f3f06f5abe351f">Diffusers' SDXL ControlNets</a></p>
|
|
|
|
| 2 |
from huggingface_hub import login
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
is_shared_ui = True if "fffiloni/sdxl-control-loras" in os.environ['SPACE_ID'] else False
|
| 6 |
+
|
| 7 |
hf_token = os.environ.get("HF_TOKEN")
|
| 8 |
login(token=hf_token)
|
| 9 |
|
|
|
|
| 61 |
prompt = prompt
|
| 62 |
negative_prompt = negative_prompt
|
| 63 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
| 64 |
+
|
| 65 |
+
if image_in == None:
|
| 66 |
+
raise gr.Error("You forgot to upload a source image.")
|
| 67 |
|
| 68 |
image_in = resize_image(image_in, "resized_input.jpg", 1024)
|
| 69 |
|
|
|
|
| 78 |
image = Image.fromarray(image)
|
| 79 |
|
| 80 |
if use_custom_model:
|
| 81 |
+
|
| 82 |
+
if custom_model == "":
|
| 83 |
+
raise gr.Error("you forgot to set a custom model name.")
|
| 84 |
+
|
| 85 |
custom_model = model_name
|
| 86 |
|
| 87 |
# This is where you load your trained weights
|
|
|
|
| 120 |
max-width: 680px;
|
| 121 |
text-align: left;
|
| 122 |
}
|
| 123 |
+
div#warning-duplicate {
|
| 124 |
+
background-color: #ebf5ff;
|
| 125 |
+
padding: 0 10px 5px;
|
| 126 |
+
margin: 20px 0;
|
| 127 |
+
}
|
| 128 |
+
div#warning-duplicate > .gr-prose > h2, div#warning-duplicate > .gr-prose > p {
|
| 129 |
+
color: #0f4592!important;
|
| 130 |
+
}
|
| 131 |
+
div#warning-duplicate strong {
|
| 132 |
+
color: #0f4592;
|
| 133 |
+
}
|
| 134 |
+
p.actions {
|
| 135 |
+
display: flex;
|
| 136 |
+
align-items: center;
|
| 137 |
+
margin: 20px 0;
|
| 138 |
+
}
|
| 139 |
+
div#warning-duplicate .actions a {
|
| 140 |
+
display: inline-block;
|
| 141 |
+
margin-right: 10px;
|
| 142 |
+
}
|
| 143 |
"""
|
| 144 |
+
|
| 145 |
with gr.Blocks(css=css) as demo:
|
| 146 |
with gr.Column(elem_id="col-container"):
|
| 147 |
+
if is_shared_ui:
|
| 148 |
+
top_description = gr.HTML(f'''
|
| 149 |
+
<div class="gr-prose">
|
| 150 |
+
<h2><svg xmlns="http://www.w3.org/2000/svg" width="18px" height="18px" style="margin-right: 0px;display: inline-block;"fill="none"><path fill="#fff" d="M7 13.2a6.3 6.3 0 0 0 4.4-10.7A6.3 6.3 0 0 0 .6 6.9 6.3 6.3 0 0 0 7 13.2Z"/><path fill="#fff" fill-rule="evenodd" d="M7 0a6.9 6.9 0 0 1 4.8 11.8A6.9 6.9 0 0 1 0 7 6.9 6.9 0 0 1 7 0Zm0 0v.7V0ZM0 7h.6H0Zm7 6.8v-.6.6ZM13.7 7h-.6.6ZM9.1 1.7c-.7-.3-1.4-.4-2.2-.4a5.6 5.6 0 0 0-4 1.6 5.6 5.6 0 0 0-1.6 4 5.6 5.6 0 0 0 1.6 4 5.6 5.6 0 0 0 4 1.7 5.6 5.6 0 0 0 4-1.7 5.6 5.6 0 0 0 1.7-4 5.6 5.6 0 0 0-1.7-4c-.5-.5-1.1-.9-1.8-1.2Z" clip-rule="evenodd"/><path fill="#000" fill-rule="evenodd" d="M7 2.9a.8.8 0 1 1 0 1.5A.8.8 0 0 1 7 3ZM5.8 5.7c0-.4.3-.6.6-.6h.7c.3 0 .6.2.6.6v3.7h.5a.6.6 0 0 1 0 1.3H6a.6.6 0 0 1 0-1.3h.4v-3a.6.6 0 0 1-.6-.7Z" clip-rule="evenodd"/></svg>
|
| 151 |
+
Note: you might want to duplicate this space to use a private model</h2>
|
| 152 |
+
<p class="main-message">
|
| 153 |
+
To do so, <strong>duplicate the Space</strong> and run it on your own profile using and eventually <strong>your own access token</strong> and eventually a GPU (T4-small or A10G-small).<br />
|
| 154 |
+
</p>
|
| 155 |
+
<p class="actions">
|
| 156 |
+
<a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}?duplicate=true">
|
| 157 |
+
<img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-lg-dark.svg" alt="Duplicate this Space" />
|
| 158 |
+
</a>
|
| 159 |
+
to start using private models and skip the queue
|
| 160 |
+
</p>
|
| 161 |
+
</div>
|
| 162 |
+
''', elem_id="warning-duplicate")
|
| 163 |
gr.HTML("""
|
| 164 |
<h2 style="text-align: center;">SD-XL Control LoRas</h2>
|
| 165 |
<p style="text-align: center;">Use StableDiffusion XL with <a href="https://huggingface.co/collections/diffusers/sdxl-controlnets-64f9c35846f3f06f5abe351f">Diffusers' SDXL ControlNets</a></p>
|