Spaces:
Paused
Paused
Run Black formatter
Browse files
app.py
CHANGED
|
@@ -28,7 +28,16 @@ def ensure_image(img) -> Image.Image:
|
|
| 28 |
raise ValueError("Cannot convert input to a PIL Image.")
|
| 29 |
|
| 30 |
|
| 31 |
-
def call_baseten_generate(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
image = ensure_image(image)
|
| 33 |
b64_image = image_to_base64(image)
|
| 34 |
payload = {
|
|
@@ -63,15 +72,18 @@ def call_baseten_generate(image: Image.Image, prompt: str, steps: int, strength:
|
|
| 63 |
|
| 64 |
# ================== MODE CONFIG =====================
|
| 65 |
|
| 66 |
-
Mode = TypedDict(
|
| 67 |
-
"
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
MODE_DEFAULTS: dict[str, Mode] = {
|
| 77 |
"Subject Generation": {
|
|
@@ -125,14 +137,21 @@ MODE_DEFAULTS: dict[str, Mode] = {
|
|
| 125 |
|
| 126 |
MODE_EXAMPLES = {
|
| 127 |
"Subject Generation": [
|
| 128 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
["assets/subj2.jpg", "A penguin standing in snow", "assets/subj2_out.jpg"],
|
| 130 |
["assets/subj3.jpg", "A cat with glowing eyes", "assets/subj3_out.jpg"],
|
| 131 |
["assets/subj4.jpg", "A child playing with bubbles", "assets/subj4_out.jpg"],
|
| 132 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
["assets/subj6.jpg", "Old man with a mysterious look", "assets/subj6_out.jpg"],
|
| 134 |
],
|
| 135 |
-
|
| 136 |
"Background Generation": [
|
| 137 |
["assets/bg1.jpg", "Modern living room with plants", "assets/bg1_out.jpg"],
|
| 138 |
["assets/bg2.jpg", "Fantasy forest background", "assets/bg2_out.jpg"],
|
|
@@ -141,25 +160,58 @@ MODE_EXAMPLES = {
|
|
| 141 |
["assets/bg5.jpg", "Snowy mountain landscape", "assets/bg5_out.jpg"],
|
| 142 |
["assets/bg6.jpg", "Golden sunset over the sea", "assets/bg6_out.jpg"],
|
| 143 |
],
|
| 144 |
-
|
| 145 |
"Canny": [
|
| 146 |
["assets/canny1.jpg", "A neon cyberpunk city skyline", "assets/canny1_out.jpg"],
|
| 147 |
["assets/canny2.jpg", "A robot walking in the fog", "assets/canny2_out.jpg"],
|
| 148 |
-
[
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
],
|
| 153 |
-
|
| 154 |
"Depth": [
|
| 155 |
-
[
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
["assets/depth5.jpg", "A bridge over a deep canyon", "assets/depth5_out.jpg"],
|
| 160 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
],
|
| 162 |
-
|
| 163 |
"Deblurring": [
|
| 164 |
["assets/deblur1.jpg", "", "assets/deblur1_out.jpg"],
|
| 165 |
["assets/deblur2.jpg", "", "assets/deblur2_out.jpg"],
|
|
@@ -242,8 +294,19 @@ with gr.Blocks(title="🌍 ZenCtrl") as demo:
|
|
| 242 |
label="Width",
|
| 243 |
)
|
| 244 |
|
| 245 |
-
def on_generate_click(
|
| 246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
|
| 248 |
generate_button.click(
|
| 249 |
fn=on_generate_click,
|
|
|
|
| 28 |
raise ValueError("Cannot convert input to a PIL Image.")
|
| 29 |
|
| 30 |
|
| 31 |
+
def call_baseten_generate(
|
| 32 |
+
image: Image.Image,
|
| 33 |
+
prompt: str,
|
| 34 |
+
steps: int,
|
| 35 |
+
strength: float,
|
| 36 |
+
height: int,
|
| 37 |
+
width: int,
|
| 38 |
+
lora_name: str,
|
| 39 |
+
remove_bg: bool,
|
| 40 |
+
) -> Image.Image | None:
|
| 41 |
image = ensure_image(image)
|
| 42 |
b64_image = image_to_base64(image)
|
| 43 |
payload = {
|
|
|
|
| 72 |
|
| 73 |
# ================== MODE CONFIG =====================
|
| 74 |
|
| 75 |
+
Mode = TypedDict(
|
| 76 |
+
"Mode",
|
| 77 |
+
{
|
| 78 |
+
"model": str,
|
| 79 |
+
"prompt": str,
|
| 80 |
+
"default_strength": float,
|
| 81 |
+
"default_height": int,
|
| 82 |
+
"default_width": int,
|
| 83 |
+
"models": list[str],
|
| 84 |
+
"remove_bg": bool,
|
| 85 |
+
},
|
| 86 |
+
)
|
| 87 |
|
| 88 |
MODE_DEFAULTS: dict[str, Mode] = {
|
| 89 |
"Subject Generation": {
|
|
|
|
| 137 |
|
| 138 |
MODE_EXAMPLES = {
|
| 139 |
"Subject Generation": [
|
| 140 |
+
[
|
| 141 |
+
"assets/subj1.jpg",
|
| 142 |
+
"Close-up portrait of a fruit bowl",
|
| 143 |
+
"assets/subj1_out.jpg",
|
| 144 |
+
],
|
| 145 |
["assets/subj2.jpg", "A penguin standing in snow", "assets/subj2_out.jpg"],
|
| 146 |
["assets/subj3.jpg", "A cat with glowing eyes", "assets/subj3_out.jpg"],
|
| 147 |
["assets/subj4.jpg", "A child playing with bubbles", "assets/subj4_out.jpg"],
|
| 148 |
+
[
|
| 149 |
+
"assets/subj5.jpg",
|
| 150 |
+
"A stylish young man in neon lights",
|
| 151 |
+
"assets/subj5_out.jpg",
|
| 152 |
+
],
|
| 153 |
["assets/subj6.jpg", "Old man with a mysterious look", "assets/subj6_out.jpg"],
|
| 154 |
],
|
|
|
|
| 155 |
"Background Generation": [
|
| 156 |
["assets/bg1.jpg", "Modern living room with plants", "assets/bg1_out.jpg"],
|
| 157 |
["assets/bg2.jpg", "Fantasy forest background", "assets/bg2_out.jpg"],
|
|
|
|
| 160 |
["assets/bg5.jpg", "Snowy mountain landscape", "assets/bg5_out.jpg"],
|
| 161 |
["assets/bg6.jpg", "Golden sunset over the sea", "assets/bg6_out.jpg"],
|
| 162 |
],
|
|
|
|
| 163 |
"Canny": [
|
| 164 |
["assets/canny1.jpg", "A neon cyberpunk city skyline", "assets/canny1_out.jpg"],
|
| 165 |
["assets/canny2.jpg", "A robot walking in the fog", "assets/canny2_out.jpg"],
|
| 166 |
+
[
|
| 167 |
+
"assets/canny3.jpg",
|
| 168 |
+
"A futuristic vehicle parked under a bridge",
|
| 169 |
+
"assets/canny3_out.jpg",
|
| 170 |
+
],
|
| 171 |
+
[
|
| 172 |
+
"assets/canny4.jpg",
|
| 173 |
+
"Sci-fi lab interior with glowing machinery",
|
| 174 |
+
"assets/canny4_out.jpg",
|
| 175 |
+
],
|
| 176 |
+
[
|
| 177 |
+
"assets/canny5.jpg",
|
| 178 |
+
"A portrait of a woman outlined in neon",
|
| 179 |
+
"assets/canny5_out.jpg",
|
| 180 |
+
],
|
| 181 |
+
[
|
| 182 |
+
"assets/canny6.jpg",
|
| 183 |
+
"Post-apocalyptic abandoned street",
|
| 184 |
+
"assets/canny6_out.jpg",
|
| 185 |
+
],
|
| 186 |
],
|
|
|
|
| 187 |
"Depth": [
|
| 188 |
+
[
|
| 189 |
+
"assets/depth1.jpg",
|
| 190 |
+
"A narrow alleyway with deep perspective",
|
| 191 |
+
"assets/depth1_out.jpg",
|
| 192 |
+
],
|
| 193 |
+
[
|
| 194 |
+
"assets/depth2.jpg",
|
| 195 |
+
"A mountain road vanishing into the distance",
|
| 196 |
+
"assets/depth2_out.jpg",
|
| 197 |
+
],
|
| 198 |
+
[
|
| 199 |
+
"assets/depth3.jpg",
|
| 200 |
+
"A hallway with strong depth of field",
|
| 201 |
+
"assets/depth3_out.jpg",
|
| 202 |
+
],
|
| 203 |
+
[
|
| 204 |
+
"assets/depth4.jpg",
|
| 205 |
+
"A misty forest path stretching far away",
|
| 206 |
+
"assets/depth4_out.jpg",
|
| 207 |
+
],
|
| 208 |
["assets/depth5.jpg", "A bridge over a deep canyon", "assets/depth5_out.jpg"],
|
| 209 |
+
[
|
| 210 |
+
"assets/depth6.jpg",
|
| 211 |
+
"An underground tunnel with receding arches",
|
| 212 |
+
"assets/depth6_out.jpg",
|
| 213 |
+
],
|
| 214 |
],
|
|
|
|
| 215 |
"Deblurring": [
|
| 216 |
["assets/deblur1.jpg", "", "assets/deblur1_out.jpg"],
|
| 217 |
["assets/deblur2.jpg", "", "assets/deblur2_out.jpg"],
|
|
|
|
| 294 |
label="Width",
|
| 295 |
)
|
| 296 |
|
| 297 |
+
def on_generate_click(
|
| 298 |
+
model_name, prompt, steps, strength, height, width, remove_bg, image
|
| 299 |
+
):
|
| 300 |
+
return call_baseten_generate(
|
| 301 |
+
image,
|
| 302 |
+
prompt,
|
| 303 |
+
steps,
|
| 304 |
+
strength,
|
| 305 |
+
height,
|
| 306 |
+
width,
|
| 307 |
+
model_name,
|
| 308 |
+
remove_bg,
|
| 309 |
+
)
|
| 310 |
|
| 311 |
generate_button.click(
|
| 312 |
fn=on_generate_click,
|