Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -77,13 +77,19 @@ def load_pipeline():
|
|
| 77 |
@spaces.GPU(duration=30)
|
| 78 |
def generate(cell_type, custom_prompt, cfg, steps, seed):
|
| 79 |
"""Generate a blood cell image. GPU is allocated for this function."""
|
|
|
|
|
|
|
| 80 |
pipeline = load_pipeline()
|
| 81 |
|
| 82 |
prompt = custom_prompt.strip() if custom_prompt and custom_prompt.strip() else CELL_TYPES.get(cell_type, CELL_TYPES["Neutrophil"])
|
| 83 |
|
| 84 |
-
|
| 85 |
-
if int(seed)
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
result = pipeline(
|
| 89 |
prompt=prompt,
|
|
@@ -125,9 +131,9 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft(primary_hue="red")) as demo:
|
|
| 125 |
)
|
| 126 |
|
| 127 |
seed_box = gr.Number(
|
| 128 |
-
value=
|
| 129 |
label="Seed",
|
| 130 |
-
info="Random seed for reproducibility. Use -1 for random generation.",
|
| 131 |
precision=0
|
| 132 |
)
|
| 133 |
|
|
|
|
| 77 |
@spaces.GPU(duration=30)
|
| 78 |
def generate(cell_type, custom_prompt, cfg, steps, seed):
|
| 79 |
"""Generate a blood cell image. GPU is allocated for this function."""
|
| 80 |
+
import random
|
| 81 |
+
|
| 82 |
pipeline = load_pipeline()
|
| 83 |
|
| 84 |
prompt = custom_prompt.strip() if custom_prompt and custom_prompt.strip() else CELL_TYPES.get(cell_type, CELL_TYPES["Neutrophil"])
|
| 85 |
|
| 86 |
+
# Handle seed: -1 means truly random each time
|
| 87 |
+
if int(seed) < 0:
|
| 88 |
+
actual_seed = random.randint(0, 2**32 - 1)
|
| 89 |
+
else:
|
| 90 |
+
actual_seed = int(seed)
|
| 91 |
+
|
| 92 |
+
generator = torch.Generator(device="cuda").manual_seed(actual_seed)
|
| 93 |
|
| 94 |
result = pipeline(
|
| 95 |
prompt=prompt,
|
|
|
|
| 131 |
)
|
| 132 |
|
| 133 |
seed_box = gr.Number(
|
| 134 |
+
value=-1,
|
| 135 |
label="Seed",
|
| 136 |
+
info="Random seed for reproducibility. Use -1 for random generation each time.",
|
| 137 |
precision=0
|
| 138 |
)
|
| 139 |
|