Spaces:
Sleeping
Sleeping
Cache examples
#1
by
thompsonmj
- opened
- app.py +33 -32
- examples/eg1.webp +0 -0
- examples/eg2.webp +0 -0
- examples/eg3.webp +0 -0
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import torch
|
2 |
import gradio as gr
|
3 |
|
4 |
-
|
5 |
import argparse, os, sys, glob
|
6 |
import torch
|
7 |
import pickle
|
@@ -16,6 +15,7 @@ from ldm.util import instantiate_from_config
|
|
16 |
from ldm.models.diffusion.ddim import DDIMSampler
|
17 |
from ldm.models.diffusion.plms import PLMSSampler
|
18 |
|
|
|
19 |
|
20 |
def load_model_from_config(config, ckpt, verbose=False):
|
21 |
print(f"Loading model from {ckpt}")
|
@@ -206,33 +206,33 @@ if __name__ == "__main__":
|
|
206 |
gr.Markdown("### Write the Species name to generate a fish image")
|
207 |
gr.Markdown("### 1. Trait Masking: Specify the Level information to mask")
|
208 |
gr.Markdown("### 2. Trait Swapping: Specify the species name to swap trait with and at what level")
|
209 |
-
|
210 |
with gr.Row():
|
211 |
with gr.Column():
|
212 |
-
# gr.Markdown("## Generate Images Based on Prompts")
|
213 |
gr.Markdown("**NOTE:** The demo is currently running on free CPU resources provided by Hugging Face, so it may take up to 10 minutes to generate an image. We're working on securing additional resources to speed up the process. Thank you for your patience!")
|
214 |
prompt_input = gr.Textbox(label="Species Name")
|
215 |
-
|
216 |
# Radio button to select experiment type, with no default selection
|
217 |
experiment_choice = gr.Radio(label="Select Experiment", choices=["Trait Masking", "Trait Swapping"], value=None)
|
218 |
-
|
219 |
# Trait Masking Inputs (hidden initially)
|
220 |
masking_level_input = gr.Dropdown(label="Select Ancestral Level", choices=["None", "Level 3", "Level 2"], value="None", visible=False)
|
221 |
-
|
222 |
# Trait Swapping Inputs (hidden initially)
|
223 |
swap_fish_name = gr.Textbox(label="Species Name to swap trait with:", visible=False)
|
224 |
swap_level_input = gr.Dropdown(label="Level of swapping", choices=["Level 3", "Level 2"], value="Level 3", visible=False)
|
225 |
-
|
226 |
submit_button = gr.Button("Generate")
|
227 |
-
|
228 |
gr.Markdown("## Phylogeny Tree")
|
229 |
architecture_image = "phylogeny_tree.jpg" # Update this with the actual path
|
230 |
gr.Image(value=architecture_image, label="Phylogeny Tree")
|
231 |
-
|
232 |
with gr.Column():
|
233 |
gr.Markdown("## Generated Image")
|
234 |
output_image = gr.Image(label="Generated Image", width=256, height=256)
|
235 |
-
|
236 |
# Place to put example buttons
|
237 |
gr.Markdown("## Select an example:")
|
238 |
examples = [
|
@@ -240,29 +240,30 @@ if __name__ == "__main__":
|
|
240 |
("Lepomis Auritus", "Level 3", "", "Level 3"),
|
241 |
("Noturus nocturnus", "None", "Notropis dorsalis", "Level 2")
|
242 |
]
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
button.click(
|
257 |
-
fn=lambda
|
258 |
-
|
259 |
-
|
260 |
-
inputs=[],
|
261 |
-
outputs=[prompt_input, masking_level_input, swap_fish_name, swap_level_input, experiment_choice]
|
262 |
-
).then(
|
263 |
-
fn=generate_image,
|
264 |
-
inputs=[prompt_input, masking_level_input, swap_fish_name, swap_level_input],
|
265 |
-
outputs=output_image
|
266 |
)
|
267 |
|
268 |
# Update visibility of inputs based on experiment selection
|
|
|
1 |
import torch
|
2 |
import gradio as gr
|
3 |
|
|
|
4 |
import argparse, os, sys, glob
|
5 |
import torch
|
6 |
import pickle
|
|
|
15 |
from ldm.models.diffusion.ddim import DDIMSampler
|
16 |
from ldm.models.diffusion.plms import PLMSSampler
|
17 |
|
18 |
+
CACHE_DIR = "examples"
|
19 |
|
20 |
def load_model_from_config(config, ckpt, verbose=False):
|
21 |
print(f"Loading model from {ckpt}")
|
|
|
206 |
gr.Markdown("### Write the Species name to generate a fish image")
|
207 |
gr.Markdown("### 1. Trait Masking: Specify the Level information to mask")
|
208 |
gr.Markdown("### 2. Trait Swapping: Specify the species name to swap trait with and at what level")
|
209 |
+
|
210 |
with gr.Row():
|
211 |
with gr.Column():
|
212 |
+
# gr.Markdown("## Generate Images Based on Prompts")
|
213 |
gr.Markdown("**NOTE:** The demo is currently running on free CPU resources provided by Hugging Face, so it may take up to 10 minutes to generate an image. We're working on securing additional resources to speed up the process. Thank you for your patience!")
|
214 |
prompt_input = gr.Textbox(label="Species Name")
|
215 |
+
|
216 |
# Radio button to select experiment type, with no default selection
|
217 |
experiment_choice = gr.Radio(label="Select Experiment", choices=["Trait Masking", "Trait Swapping"], value=None)
|
218 |
+
|
219 |
# Trait Masking Inputs (hidden initially)
|
220 |
masking_level_input = gr.Dropdown(label="Select Ancestral Level", choices=["None", "Level 3", "Level 2"], value="None", visible=False)
|
221 |
+
|
222 |
# Trait Swapping Inputs (hidden initially)
|
223 |
swap_fish_name = gr.Textbox(label="Species Name to swap trait with:", visible=False)
|
224 |
swap_level_input = gr.Dropdown(label="Level of swapping", choices=["Level 3", "Level 2"], value="Level 3", visible=False)
|
225 |
+
|
226 |
submit_button = gr.Button("Generate")
|
227 |
+
|
228 |
gr.Markdown("## Phylogeny Tree")
|
229 |
architecture_image = "phylogeny_tree.jpg" # Update this with the actual path
|
230 |
gr.Image(value=architecture_image, label="Phylogeny Tree")
|
231 |
+
|
232 |
with gr.Column():
|
233 |
gr.Markdown("## Generated Image")
|
234 |
output_image = gr.Image(label="Generated Image", width=256, height=256)
|
235 |
+
|
236 |
# Place to put example buttons
|
237 |
gr.Markdown("## Select an example:")
|
238 |
examples = [
|
|
|
240 |
("Lepomis Auritus", "Level 3", "", "Level 3"),
|
241 |
("Noturus nocturnus", "None", "Notropis dorsalis", "Level 2")
|
242 |
]
|
243 |
+
|
244 |
+
example_images = [
|
245 |
+
"eg1.webp",
|
246 |
+
"eg2.webp",
|
247 |
+
"eg3.webp",
|
248 |
+
]
|
249 |
+
|
250 |
+
for idx, (species, masking, swap_species, swap_level) in enumerate(examples):
|
251 |
+
# Descriptive button text
|
252 |
+
if masking != "None" and swap_species == "":
|
253 |
+
button_text = f"Species: {species} | Masking: {masking}"
|
254 |
+
elif swap_species:
|
255 |
+
button_text = f"Species: {species} | Swapping with {swap_species} at {swap_level}"
|
256 |
+
else:
|
257 |
+
button_text = f"Species: {species}"
|
258 |
+
|
259 |
+
# Create button
|
260 |
+
button = gr.Button(button_text)
|
261 |
+
|
262 |
+
# Attach the function to load cached images
|
263 |
button.click(
|
264 |
+
fn=lambda index=idx: os.path.join(CACHE_DIR, example_images[index]),
|
265 |
+
inputs=[], # No inputs required
|
266 |
+
outputs=output_image # Display the cached image
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
)
|
268 |
|
269 |
# Update visibility of inputs based on experiment selection
|
examples/eg1.webp
ADDED
examples/eg2.webp
ADDED
examples/eg3.webp
ADDED