Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import spaces # MUST come before torch
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
import hashlib
|
| 5 |
import pathlib
|
| 6 |
import tempfile
|
| 7 |
import time
|
|
@@ -48,9 +47,15 @@ def euler_sample(batch, steps, seed):
|
|
| 48 |
return (x.clamp(-1, 1) + 1) / 2
|
| 49 |
|
| 50 |
|
| 51 |
-
def _duration(batch, steps, *args, **kwargs):
|
| 52 |
-
#
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
@spaces.GPU(duration=_duration)
|
|
@@ -94,7 +99,7 @@ CSS = """
|
|
| 94 |
.dark .gradio-container { color: var(--body-text-color); }
|
| 95 |
"""
|
| 96 |
|
| 97 |
-
with gr.Blocks(
|
| 98 |
gr.Markdown(
|
| 99 |
"""
|
| 100 |
# Agent-GenPath — Pathology Patch Synthesis
|
|
@@ -135,4 +140,4 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
|
|
| 135 |
)
|
| 136 |
run.click(generate, inputs=[seed, batch, steps], outputs=gallery, api_name="generate")
|
| 137 |
|
| 138 |
-
demo.launch(mcp_server=True)
|
|
|
|
| 1 |
import spaces # MUST come before torch
|
| 2 |
import os
|
| 3 |
|
|
|
|
| 4 |
import pathlib
|
| 5 |
import tempfile
|
| 6 |
import time
|
|
|
|
| 47 |
return (x.clamp(-1, 1) + 1) / 2
|
| 48 |
|
| 49 |
|
| 50 |
+
def _duration(seed, batch, steps, *args, **kwargs):
|
| 51 |
+
# Positional args mirror generate()'s signature (Gradio also injects progress=,
|
| 52 |
+
# which lands in *args). Keep the estimate at the realistic worst case.
|
| 53 |
+
try:
|
| 54 |
+
batch = max(1, min(int(batch), 8))
|
| 55 |
+
steps = max(1, min(int(steps), 100))
|
| 56 |
+
except (TypeError, ValueError):
|
| 57 |
+
batch, steps = 8, 50
|
| 58 |
+
return min(180, 20 + steps * 1.6 * max(1, (batch + 3) // 4))
|
| 59 |
|
| 60 |
|
| 61 |
@spaces.GPU(duration=_duration)
|
|
|
|
| 99 |
.dark .gradio-container { color: var(--body-text-color); }
|
| 100 |
"""
|
| 101 |
|
| 102 |
+
with gr.Blocks() as demo:
|
| 103 |
gr.Markdown(
|
| 104 |
"""
|
| 105 |
# Agent-GenPath — Pathology Patch Synthesis
|
|
|
|
| 140 |
)
|
| 141 |
run.click(generate, inputs=[seed, batch, steps], outputs=gallery, api_name="generate")
|
| 142 |
|
| 143 |
+
demo.launch(mcp_server=True, theme=gr.themes.Citrus(), css=CSS)
|