Spaces:
Sleeping
Sleeping
File size: 1,621 Bytes
1ba6b4e 1731700 1ba6b4e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | import io
from PIL import Image
import runner
class FakePipeline:
def __init__(self):
self.calls = []
def __call__(self, **kwargs):
self.calls.append(kwargs)
seed = kwargs["generator"].initial_seed()
return type("Output", (), {"images": [Image.new("RGB", (kwargs["width"], kwargs["height"]), (seed % 255, 40, 90))]})()
class SafeClassifier:
def __call__(self, image):
return [{"label": "normal", "score": 0.999}, {"label": "nsfw", "score": 0.001}]
def test_grid_uses_coordinator_controls_and_distinct_seeds(monkeypatch):
pipe = FakePipeline()
monkeypatch.setattr(runner, "PIPELINE", pipe)
monkeypatch.setattr(runner, "SAFETY", SafeClassifier())
task = {"id": "j", "prompt": "rat", "operation": "grid", "seed": 10,
"outputCount": 4, "width": 512, "height": 512, "steps": 16,
"assignmentToken": "a"}
result = runner.render_task(task, None)
assert len(result["images"]) == 4
assert len({call["generator"].initial_seed() for call in pipe.calls}) == 4
assert all(call["num_inference_steps"] == 16 for call in pipe.calls)
grid = Image.open(io.BytesIO(result["grid"]["bytes"]))
assert grid.size == (1024, 1024)
assert result["grid"]["localSafety"]["unsafe"] is False
def test_gpu_duration_is_bounded():
assert runner.gpu_duration({"operation": "grid", "outputCount": 4, "steps": 16}) > runner.gpu_duration({"outputCount": 1, "steps": 16})
assert runner.gpu_duration({"outputCount": 1, "steps": 16}, b"source") >= 60
assert runner.gpu_duration({"outputCount": 99, "steps": 999}) <= 300
|