Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,21 +45,6 @@ def save_generated_image(image, prompt):
|
|
| 45 |
|
| 46 |
return filepath
|
| 47 |
|
| 48 |
-
def load_generated_images():
|
| 49 |
-
if not os.path.exists(SAVE_DIR):
|
| 50 |
-
return []
|
| 51 |
-
|
| 52 |
-
# Load all images from the directory
|
| 53 |
-
image_files = [os.path.join(SAVE_DIR, f) for f in os.listdir(SAVE_DIR)
|
| 54 |
-
if f.endswith(('.png', '.jpg', '.jpeg', '.webp'))]
|
| 55 |
-
# Sort by creation time (newest first)
|
| 56 |
-
image_files.sort(key=lambda x: os.path.getctime(x), reverse=True)
|
| 57 |
-
return image_files
|
| 58 |
-
|
| 59 |
-
def load_predefined_images():
|
| 60 |
-
# Return empty list since we're not using predefined images
|
| 61 |
-
return []
|
| 62 |
-
|
| 63 |
@spaces.GPU(duration=120)
|
| 64 |
def inference(
|
| 65 |
prompt: str,
|
|
@@ -89,8 +74,8 @@ def inference(
|
|
| 89 |
# Save the generated image
|
| 90 |
filepath = save_generated_image(image, prompt)
|
| 91 |
|
| 92 |
-
# Return the image
|
| 93 |
-
return image, seed
|
| 94 |
|
| 95 |
|
| 96 |
examples = [
|
|
@@ -118,106 +103,80 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, analytics_enabled=False) as demo
|
|
| 118 |
gr.HTML("""<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fginigen-cartoon.hf.space">
|
| 119 |
<img src="https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fginigen-cartoon.hf.space&countColor=%23263759" />
|
| 120 |
</a>""")
|
| 121 |
-
|
| 122 |
|
| 123 |
-
with gr.
|
| 124 |
-
with gr.
|
| 125 |
-
with gr.
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
label="Prompt",
|
| 129 |
-
show_label=False,
|
| 130 |
-
max_lines=1,
|
| 131 |
-
placeholder="Enter your prompt",
|
| 132 |
-
container=False,
|
| 133 |
-
)
|
| 134 |
-
run_button = gr.Button("Run", scale=0)
|
| 135 |
-
|
| 136 |
-
# Modified to include the default image
|
| 137 |
-
result = gr.Image(
|
| 138 |
-
label="Result",
|
| 139 |
show_label=False,
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
with gr.Accordion("Advanced Settings", open=False):
|
| 144 |
-
seed = gr.Slider(
|
| 145 |
-
label="Seed",
|
| 146 |
-
minimum=0,
|
| 147 |
-
maximum=MAX_SEED,
|
| 148 |
-
step=1,
|
| 149 |
-
value=42,
|
| 150 |
-
)
|
| 151 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 152 |
-
|
| 153 |
-
with gr.Row():
|
| 154 |
-
width = gr.Slider(
|
| 155 |
-
label="Width",
|
| 156 |
-
minimum=256,
|
| 157 |
-
maximum=MAX_IMAGE_SIZE,
|
| 158 |
-
step=32,
|
| 159 |
-
value=1024,
|
| 160 |
-
)
|
| 161 |
-
height = gr.Slider(
|
| 162 |
-
label="Height",
|
| 163 |
-
minimum=256,
|
| 164 |
-
maximum=MAX_IMAGE_SIZE,
|
| 165 |
-
step=32,
|
| 166 |
-
value=768,
|
| 167 |
-
)
|
| 168 |
-
|
| 169 |
-
with gr.Row():
|
| 170 |
-
guidance_scale = gr.Slider(
|
| 171 |
-
label="Guidance scale",
|
| 172 |
-
minimum=0.0,
|
| 173 |
-
maximum=10.0,
|
| 174 |
-
step=0.1,
|
| 175 |
-
value=3.5,
|
| 176 |
-
)
|
| 177 |
-
num_inference_steps = gr.Slider(
|
| 178 |
-
label="Number of inference steps",
|
| 179 |
-
minimum=1,
|
| 180 |
-
maximum=50,
|
| 181 |
-
step=1,
|
| 182 |
-
value=30,
|
| 183 |
-
)
|
| 184 |
-
lora_scale = gr.Slider(
|
| 185 |
-
label="LoRA scale",
|
| 186 |
-
minimum=0.0,
|
| 187 |
-
maximum=1.0,
|
| 188 |
-
step=0.1,
|
| 189 |
-
value=1.0,
|
| 190 |
-
)
|
| 191 |
-
|
| 192 |
-
gr.Examples(
|
| 193 |
-
examples=examples,
|
| 194 |
-
inputs=[prompt],
|
| 195 |
-
outputs=[result, seed],
|
| 196 |
)
|
|
|
|
| 197 |
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
generated_gallery = gr.Gallery(
|
| 201 |
-
label="Generated Images",
|
| 202 |
-
columns=6,
|
| 203 |
show_label=False,
|
| 204 |
-
value=
|
| 205 |
-
elem_id="generated_gallery",
|
| 206 |
-
height="auto"
|
| 207 |
)
|
| 208 |
-
refresh_btn = gr.Button("🔄 Refresh Gallery")
|
| 209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
gr.on(
|
| 222 |
triggers=[run_button.click, prompt.submit],
|
| 223 |
fn=inference,
|
|
@@ -231,8 +190,8 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, analytics_enabled=False) as demo
|
|
| 231 |
num_inference_steps,
|
| 232 |
lora_scale,
|
| 233 |
],
|
| 234 |
-
outputs=[result, seed
|
| 235 |
)
|
| 236 |
|
| 237 |
demo.queue()
|
| 238 |
-
demo.launch()
|
|
|
|
| 45 |
|
| 46 |
return filepath
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
@spaces.GPU(duration=120)
|
| 49 |
def inference(
|
| 50 |
prompt: str,
|
|
|
|
| 74 |
# Save the generated image
|
| 75 |
filepath = save_generated_image(image, prompt)
|
| 76 |
|
| 77 |
+
# Return the image and seed (gallery removed)
|
| 78 |
+
return image, seed
|
| 79 |
|
| 80 |
|
| 81 |
examples = [
|
|
|
|
| 103 |
gr.HTML("""<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fginigen-cartoon.hf.space">
|
| 104 |
<img src="https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fginigen-cartoon.hf.space&countColor=%23263759" />
|
| 105 |
</a>""")
|
|
|
|
| 106 |
|
| 107 |
+
with gr.Tab("Generation"):
|
| 108 |
+
with gr.Column(elem_id="col-container"):
|
| 109 |
+
with gr.Row():
|
| 110 |
+
prompt = gr.Text(
|
| 111 |
+
label="Prompt",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
show_label=False,
|
| 113 |
+
max_lines=1,
|
| 114 |
+
placeholder="Enter your prompt",
|
| 115 |
+
container=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
)
|
| 117 |
+
run_button = gr.Button("Run", scale=0)
|
| 118 |
|
| 119 |
+
result = gr.Image(
|
| 120 |
+
label="Result",
|
|
|
|
|
|
|
|
|
|
| 121 |
show_label=False,
|
| 122 |
+
value=DEFAULT_IMAGE_PATH
|
|
|
|
|
|
|
| 123 |
)
|
|
|
|
| 124 |
|
| 125 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 126 |
+
seed = gr.Slider(
|
| 127 |
+
label="Seed",
|
| 128 |
+
minimum=0,
|
| 129 |
+
maximum=MAX_SEED,
|
| 130 |
+
step=1,
|
| 131 |
+
value=42,
|
| 132 |
+
)
|
| 133 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 134 |
|
| 135 |
+
with gr.Row():
|
| 136 |
+
width = gr.Slider(
|
| 137 |
+
label="Width",
|
| 138 |
+
minimum=256,
|
| 139 |
+
maximum=MAX_IMAGE_SIZE,
|
| 140 |
+
step=32,
|
| 141 |
+
value=1024,
|
| 142 |
+
)
|
| 143 |
+
height = gr.Slider(
|
| 144 |
+
label="Height",
|
| 145 |
+
minimum=256,
|
| 146 |
+
maximum=MAX_IMAGE_SIZE,
|
| 147 |
+
step=32,
|
| 148 |
+
value=768,
|
| 149 |
+
)
|
| 150 |
|
| 151 |
+
with gr.Row():
|
| 152 |
+
guidance_scale = gr.Slider(
|
| 153 |
+
label="Guidance scale",
|
| 154 |
+
minimum=0.0,
|
| 155 |
+
maximum=10.0,
|
| 156 |
+
step=0.1,
|
| 157 |
+
value=3.5,
|
| 158 |
+
)
|
| 159 |
+
num_inference_steps = gr.Slider(
|
| 160 |
+
label="Number of inference steps",
|
| 161 |
+
minimum=1,
|
| 162 |
+
maximum=50,
|
| 163 |
+
step=1,
|
| 164 |
+
value=30,
|
| 165 |
+
)
|
| 166 |
+
lora_scale = gr.Slider(
|
| 167 |
+
label="LoRA scale",
|
| 168 |
+
minimum=0.0,
|
| 169 |
+
maximum=1.0,
|
| 170 |
+
step=0.1,
|
| 171 |
+
value=1.0,
|
| 172 |
+
)
|
| 173 |
|
| 174 |
+
gr.Examples(
|
| 175 |
+
examples=examples,
|
| 176 |
+
inputs=[prompt],
|
| 177 |
+
outputs=[result, seed],
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
gr.on(
|
| 181 |
triggers=[run_button.click, prompt.submit],
|
| 182 |
fn=inference,
|
|
|
|
| 190 |
num_inference_steps,
|
| 191 |
lora_scale,
|
| 192 |
],
|
| 193 |
+
outputs=[result, seed],
|
| 194 |
)
|
| 195 |
|
| 196 |
demo.queue()
|
| 197 |
+
demo.launch()
|