Spaces:
Running on Zero
Running on Zero
A newer version of the Gradio SDK is available: 6.22.0
API Documentation
ModelHandler
generate(prompt, **kwargs)
Generate an image from a text prompt.
Parameters:
prompt(str): Text prompt for generationnegative_prompt(str, optional): Negative prompt. Default: ""guidance_scale(float, optional): Guidance scale. Default: 7.5num_inference_steps(int, optional): Number of inference steps. Default: 50seed(int, optional): Random seed. Default: None (random)width(int, optional): Image width. Default: 1024height(int, optional): Image height. Default: 1024cfg_scale(float, optional): CFG scale. Default: None (uses guidance_scale)lora_strength(float, optional): LoRA strength. Default: 1.0
Returns:
tuple: (image, metadata_dict)
Example:
from src.model_handler import ModelHandler
handler = ModelHandler()
image, metadata = handler.generate(
prompt="seamless wood texture",
guidance_scale=7.5,
num_inference_steps=50,
seed=12345,
)
generate_batch(prompts, base_params=None)
Generate multiple images in batch.
Parameters:
prompts(List[str]): List of prompts to generatebase_params(dict, optional): Base parameters for all generations
Returns:
Generator: Yields (image, metadata, index) tuples
Example:
prompts = ["wood texture", "fabric texture", "metal texture"]
for image, metadata, idx in handler.generate_batch(prompts):
# Process each image
pass
Image Processor
save_image(image, prompt, params, metadata=None)
Save an image with metadata.
Parameters:
image(PIL.Image): Image to saveprompt(str): Prompt usedparams(dict): Generation parametersmetadata(dict, optional): Additional metadata
Returns:
Path: Path to saved image file
create_thumbnail(image, size=(256, 256))
Create a thumbnail from an image.
Parameters:
image(PIL.Image): Source imagesize(tuple): Thumbnail size (width, height)
Returns:
PIL.Image: Thumbnail image
create_zip(files, output_path)
Create a ZIP archive from multiple files.
Parameters:
files(List[Path]): List of file pathsoutput_path(Path): Output ZIP path
Returns:
Path: Path to created ZIP file
Presets
get_preset(name)
Get a preset by name.
Parameters:
name(str): Preset name
Returns:
dictorNone: Preset dictionary
list_presets()
List all available preset names.
Returns:
List[str]: List of preset names
Utils
validate_prompt(prompt, max_length=500)
Validate a prompt string.
Parameters:
prompt(str): Prompt to validatemax_length(int): Maximum allowed length
Returns:
tuple: (is_valid, error_message)
validate_params(params)
Validate generation parameters.
Parameters:
params(dict): Parameters to validate
Returns:
tuple: (is_valid, error_message)