Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,6 @@ import cv2
|
|
6 |
import os
|
7 |
|
8 |
from typing import Dict
|
9 |
-
from torchvision.transforms.functional import to_tensor, center_crop, resize
|
10 |
from PIL import Image
|
11 |
from huggingface_hub import Repository
|
12 |
|
@@ -14,7 +13,8 @@ token = os.environ['model_fetch']
|
|
14 |
|
15 |
engine_repo = Repository(local_dir="engine", clone_from="felixrosberg/EngageDiffusion", use_auth_token=token)
|
16 |
|
17 |
-
from engine.ui_model import fetch_model,
|
|
|
18 |
|
19 |
engage_logo = Image.open("engage_studios_logo.png").resize((700, 88), Image.Resampling.BICUBIC)
|
20 |
engage_logo_mask = np.array(engage_logo.split()[-1])[..., None] / 255
|
@@ -103,133 +103,5 @@ def inference(user_state, condition_image, settings, prompt, neg_prompt, inferen
|
|
103 |
return user_state["IMAGE_GALLERY"], user_state
|
104 |
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
radius_size="none",
|
109 |
-
).set(
|
110 |
-
body_text_color_dark='*neutral_800',
|
111 |
-
embed_radius='*radius_xxs',
|
112 |
-
button_primary_background_fill='*primary_700',
|
113 |
-
button_primary_background_fill_hover='*primary_400',
|
114 |
-
button_primary_background_fill_hover_dark='*primary_400',
|
115 |
-
button_primary_border_color_dark='*primary_200',
|
116 |
-
button_primary_text_color='*primary_50',
|
117 |
-
button_primary_text_color_dark='*primary_50',
|
118 |
-
button_primary_text_color_hover='*primary_50'
|
119 |
-
)
|
120 |
-
with gr.Blocks(theme=theme) as engage_automotive_lora_demo:
|
121 |
-
session_state = gr.State(value={"IMAGE_GALLERY": [],
|
122 |
-
"SELECTED_IMAGE": None
|
123 |
-
})
|
124 |
-
diffused_image_out = gr.Gallery(label='Results', show_label=False,
|
125 |
-
columns=[3], rows=[1], object_fit="contain", height="auto",
|
126 |
-
format="png")
|
127 |
-
with gr.Group():
|
128 |
-
with gr.Row():
|
129 |
-
prompt_box = gr.Textbox("futuristic dark red car in a white studio",
|
130 |
-
label='Prompt')
|
131 |
-
generate_button = gr.Button("Generate", scale=0)
|
132 |
-
with gr.Row():
|
133 |
-
settings_dropdown = gr.Dropdown(
|
134 |
-
["Text to image", "From sketch", "Inpaint", "Inpaint sketch"], value="Text to image",
|
135 |
-
label="Mode", info="Text to image, prompt only. "
|
136 |
-
"From sketch, upload an initial image / sketch in the image editor. "
|
137 |
-
"Inpaint sketch, edits the chosen area of an image. Uses the initial "
|
138 |
-
"image as base for sketches."
|
139 |
-
)
|
140 |
-
with gr.Accordion("Image Editor", open=False):
|
141 |
-
condition_image = gr.ImageEditor(type='pil', show_label=False,
|
142 |
-
brush=gr.Brush(colors=["#000000"], color_mode="fixed"))
|
143 |
-
with gr.Row():
|
144 |
-
with gr.Accordion("Settings", open=False):
|
145 |
-
neg_prompt_box = gr.Textbox(
|
146 |
-
"blurry, poor quality, unrealistic",
|
147 |
-
label='Negative Prompt')
|
148 |
-
seed_box = gr.Number(42, label='Seed')
|
149 |
-
inference_steps = gr.Slider(0, 20, value=8,
|
150 |
-
label='Inference Steps', step=1)
|
151 |
-
num_images = gr.Slider(1, 3, value=2, label='Number of Images', step=1)
|
152 |
-
guidance_scale = gr.Slider(0, 10, value=1.5,
|
153 |
-
label='Guidance Scale', step=0.1)
|
154 |
-
guidance_rescale = gr.Slider(0.0, 1.0, value=0.0,
|
155 |
-
label='Guidance Rescale', step=0.1)
|
156 |
-
height = gr.Slider(128, 2048, value=1024, label='Image Height', step=64)
|
157 |
-
width = gr.Slider(128, 2048, value=1024, label='Image Width', step=64)
|
158 |
-
condition_influence = gr.Slider(0.0, 1.0, value=0.5, label='Condition Influence')
|
159 |
-
sketch_detail = gr.Slider(0.0, 1.0, value=0.5, label='Sketch Detail')
|
160 |
-
sketch_softness = gr.Slider(0.0, 1.0, value=0.5, label='Sketch Softness')
|
161 |
-
inpaint_strength = gr.Slider(0.0, 1.0, value=0.8, label='Inpaint Strength')
|
162 |
-
enable_freeu = gr.Checkbox(True, label='FreeU',
|
163 |
-
info='Enables FreeU scaling factors.')
|
164 |
-
with gr.Accordion("Stylation (Experimental)", open=False):
|
165 |
-
with gr.Row():
|
166 |
-
exposure = gr.Slider(-1.0, 1.0, value=0.0, label='Exposure')
|
167 |
-
enable_stylation = gr.Checkbox(label='Enable Stylation',
|
168 |
-
info='EXPERIMENTAL: We apologize for the ambiguity, '
|
169 |
-
'please play around with the sliders to '
|
170 |
-
'find a style you like!'
|
171 |
-
'Warning: Will slow down the generation time.')
|
172 |
-
with gr.Accordion("Style A - Engage Studios Futuristic", open=False):
|
173 |
-
style_A_down = gr.Slider(-1.0, 1.0, value=0.0, label='down')
|
174 |
-
style_A_mid = gr.Slider(-1.0, 1.0, value=0.0, label='mid')
|
175 |
-
style_A_up = gr.Slider(-1.0, 1.0, value=0.0, label='up')
|
176 |
-
with gr.Accordion("Style B - Lighting", open=False):
|
177 |
-
style_B_down = gr.Slider(-1.0, 1.0, value=0.0, label='down')
|
178 |
-
style_B_mid = gr.Slider(-1.0, 1.0, value=0.0, label='mid')
|
179 |
-
style_B_up = gr.Slider(-1.0, 1.0, value=0.0, label='up')
|
180 |
-
with gr.Accordion("Style C - Details A", open=False):
|
181 |
-
style_C_down = gr.Slider(-1.0, 1.0, value=0.0, label='down')
|
182 |
-
style_C_mid = gr.Slider(-1.0, 1.0, value=0.0, label='mid')
|
183 |
-
style_C_up = gr.Slider(-1.0, 1.0, value=0.0, label='up')
|
184 |
-
with gr.Accordion("Style D - Details B", open=False):
|
185 |
-
style_D_down = gr.Slider(-1.0, 1.0, value=0.0, label='down')
|
186 |
-
style_D_mid = gr.Slider(-1.0, 1.0, value=0.0, label='mid')
|
187 |
-
style_D_up = gr.Slider(-1.0, 1.0, value=0.0, label='up')
|
188 |
-
|
189 |
-
generate_button.click(inference,
|
190 |
-
inputs=[session_state,
|
191 |
-
condition_image,
|
192 |
-
settings_dropdown,
|
193 |
-
prompt_box,
|
194 |
-
neg_prompt_box,
|
195 |
-
|
196 |
-
inference_steps,
|
197 |
-
num_images,
|
198 |
-
|
199 |
-
guidance_scale,
|
200 |
-
guidance_rescale,
|
201 |
-
enable_freeu,
|
202 |
-
|
203 |
-
height,
|
204 |
-
width,
|
205 |
-
|
206 |
-
condition_influence,
|
207 |
-
|
208 |
-
sketch_detail,
|
209 |
-
sketch_softness,
|
210 |
-
inpaint_strength,
|
211 |
-
|
212 |
-
exposure,
|
213 |
-
enable_stylation,
|
214 |
-
|
215 |
-
style_A_down,
|
216 |
-
style_A_mid,
|
217 |
-
style_A_up,
|
218 |
-
|
219 |
-
style_B_down,
|
220 |
-
style_B_mid,
|
221 |
-
style_B_up,
|
222 |
-
|
223 |
-
style_C_down,
|
224 |
-
style_C_mid,
|
225 |
-
style_C_up,
|
226 |
-
|
227 |
-
style_D_down,
|
228 |
-
style_D_mid,
|
229 |
-
style_D_up,
|
230 |
-
|
231 |
-
seed_box],
|
232 |
-
outputs=[diffused_image_out, session_state],
|
233 |
-
show_progress=True)
|
234 |
-
|
235 |
-
engage_automotive_lora_demo.launch()
|
|
|
6 |
import os
|
7 |
|
8 |
from typing import Dict
|
|
|
9 |
from PIL import Image
|
10 |
from huggingface_hub import Repository
|
11 |
|
|
|
13 |
|
14 |
engine_repo = Repository(local_dir="engine", clone_from="felixrosberg/EngageDiffusion", use_auth_token=token)
|
15 |
|
16 |
+
from engine.ui_model import fetch_model, run_model
|
17 |
+
from engine.ui_gradio import fetch_ui
|
18 |
|
19 |
engage_logo = Image.open("engage_studios_logo.png").resize((700, 88), Image.Resampling.BICUBIC)
|
20 |
engage_logo_mask = np.array(engage_logo.split()[-1])[..., None] / 255
|
|
|
103 |
return user_state["IMAGE_GALLERY"], user_state
|
104 |
|
105 |
|
106 |
+
engage_demo = fetch_ui(inference)
|
107 |
+
engage_demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|