Skip to content

Testing

Manual Testing With Ephemeral Deployments

Utilize Ephemeral Deployments to test your application through normal REST API calls.

Playground

Go to the autogenerated playground for your ephemeral deployment to test your application.

REST API

Use the REST API with your ephemeral deployment URL to test your application.

Python

Applications

import fal
from pydantic import BaseModel
from fal.toolkit import Image
class ImageModelInput(BaseModel):
seed: int | None = Field(
default=None,
description="""
The same seed and the same prompt given to the same version of Stable Diffusion
will output the same image every time.
""",
examples=[176400],
)
num_inference_steps: int = Field(
default=25,
description="""
Increasing the amount of steps tell the model that it should take more steps
to generate your final result which can increase the amount of detail in your image.
""",
gt=0,
le=100,
)
class MyApp(fal.App(keep_alive=300)):
machine_type = "GPU-A100"
requirements = [
"diffusers==0.29.0",
"torch==2.3.0",
"accelerate",
"transformers",
]
def setup(self):
import torch
from diffusers import StableDiffusionXLPipeline, DPMSolverSinglestepScheduler
self.pipe = StableDiffusionXLPipeline.from_pretrained(
"sd-community/sdxl-flash",
torch_dtype=torch.float16,
).to("cuda")
self.pipe.scheduler = DPMSolverSinglestepScheduler.from_config(
self.pipe.scheduler.config,
timestep_spacing="trailing",
)
@fal.endpoint("/")
def generate_image(self, request: ImageModelInput) -> Image:
result = self.pipe(request.prompt, num_inference_steps=7, guidance_scale=3)
image = Image.from_pil(result.images[0])
return image
def test_myapp():
with fal.app.AppClient(MyApp) as client:
client.generate_image(prompt="A cat holding a sign that says hello world")

Functions

Fal functions can be called directly in your python code and they will automatically run on a remote machine.

import fal
@fal.function(machine_type="GPU", requirements=["diffusers", "torch", "transformers"])
def generate_image(prompt: str):
import torch
from diffusers import FluxPipeline
from io import BytesIO
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16)
pipe.enable_model_cpu_offload()
out = pipe(
prompt=prompt,
guidance_scale=0.,
height=768,
width=1360,
num_inference_steps=4,
max_sequence_length=256,
).images[0]
buffer = BytesIO()
out.save(buffer, format="PNG")
image_bytes = buffer.getvalue()
return image_bytes
def test_myfunc():
image_bytes = generate_image("A cat holding a sign that says hello world")
assert image_bytes