Spaces:
Running on Zero
Running on Zero
Tune duration, examples
Browse files
app.py
CHANGED
|
@@ -159,16 +159,17 @@ def _extract_answer(texts) -> str:
|
|
| 159 |
return ""
|
| 160 |
|
| 161 |
|
| 162 |
-
def _duration(image, question, max_images=
|
| 163 |
-
#
|
| 164 |
-
|
|
|
|
| 165 |
|
| 166 |
|
| 167 |
@spaces.GPU(duration=_duration)
|
| 168 |
def reason(
|
| 169 |
image: Image.Image | None,
|
| 170 |
question: str,
|
| 171 |
-
max_images: int =
|
| 172 |
max_text_tokens: int = 1024,
|
| 173 |
num_timesteps: int = 50,
|
| 174 |
cfg_text_scale: float = 3.0,
|
|
@@ -331,7 +332,7 @@ CSS = """
|
|
| 331 |
|
| 332 |
EXAMPLES = [
|
| 333 |
["examples/living_room_blue_couch.jpg",
|
| 334 |
-
"Imagine you are standing behind the fireplace looking toward the sofa. Is the TV on your left or your right?"],
|
| 335 |
["examples/cafe_interior.jpg",
|
| 336 |
"Which is closer to the camera: the teapot on the nearest table or the turquoise cabinet? Think about the depth of the scene."],
|
| 337 |
["examples/sign_beach.jpg",
|
|
@@ -362,7 +363,7 @@ with gr.Blocks(title="ThinkMorph-SSL") as demo:
|
|
| 362 |
)
|
| 363 |
run_btn = gr.Button("Reason", variant="primary")
|
| 364 |
with gr.Accordion("Advanced settings", open=False):
|
| 365 |
-
max_images = gr.Slider(1,
|
| 366 |
max_text_tokens = gr.Slider(256, 2048, value=1024, step=64, label="Max text tokens (whole trace)")
|
| 367 |
num_timesteps = gr.Slider(10, 50, value=50, step=1, label="Denoising steps per image")
|
| 368 |
cfg_text_scale = gr.Slider(1.0, 8.0, value=3.0, step=0.1, label="CFG text scale")
|
|
|
|
| 159 |
return ""
|
| 160 |
|
| 161 |
|
| 162 |
+
def _duration(image, question, max_images=2, max_text_tokens=1024, num_timesteps=50, *args, **kwargs):
|
| 163 |
+
# Measured on ZeroGPU: ~0.95 s per denoising step for a ~1024px image (CFG), ~10 s of text decoding.
|
| 164 |
+
est = 15 + int(max_images) * 0.95 * int(num_timesteps) + int(max_text_tokens) * 0.01
|
| 165 |
+
return int(min(300, est * 1.15))
|
| 166 |
|
| 167 |
|
| 168 |
@spaces.GPU(duration=_duration)
|
| 169 |
def reason(
|
| 170 |
image: Image.Image | None,
|
| 171 |
question: str,
|
| 172 |
+
max_images: int = 2,
|
| 173 |
max_text_tokens: int = 1024,
|
| 174 |
num_timesteps: int = 50,
|
| 175 |
cfg_text_scale: float = 3.0,
|
|
|
|
| 332 |
|
| 333 |
EXAMPLES = [
|
| 334 |
["examples/living_room_blue_couch.jpg",
|
| 335 |
+
"Imagine you are standing behind the fireplace looking toward the sofa. Is the TV on your left or your right? Answer with a word, not a letter."],
|
| 336 |
["examples/cafe_interior.jpg",
|
| 337 |
"Which is closer to the camera: the teapot on the nearest table or the turquoise cabinet? Think about the depth of the scene."],
|
| 338 |
["examples/sign_beach.jpg",
|
|
|
|
| 363 |
)
|
| 364 |
run_btn = gr.Button("Reason", variant="primary")
|
| 365 |
with gr.Accordion("Advanced settings", open=False):
|
| 366 |
+
max_images = gr.Slider(1, 5, value=2, step=1, label="Max generated images")
|
| 367 |
max_text_tokens = gr.Slider(256, 2048, value=1024, step=64, label="Max text tokens (whole trace)")
|
| 368 |
num_timesteps = gr.Slider(10, 50, value=50, step=1, label="Denoising steps per image")
|
| 369 |
cfg_text_scale = gr.Slider(1.0, 8.0, value=3.0, step=0.1, label="CFG text scale")
|