Files
replicate.maui/Replicate.Maui/ModelPresets.cs
2025-12-10 21:59:12 -05:00

411 lines
14 KiB
C#

namespace MarketAlly.Replicate.Maui
{
/// <summary>
/// Predefined model presets for popular Replicate models.
/// </summary>
public static class ModelPresets
{
#region Image Models
/// <summary>
/// HiDream E1.1 by PrunaAI - Fast high-quality image generation/editing.
/// </summary>
public static ModelPreset HiDreamE1 => new()
{
Name = "HiDream E1.1",
ModelName = "prunaai/hidream-e1.1",
ModelVersion = "433436facdc1172b6efcb801eb6f345d7858a32200d24e5febaccfb4b44ad66f",
Type = ModelType.Image,
DefaultPrompt = "anime style portrait, soft clean lines, studio ghibli inspired, friendly expression, cinematic lighting",
DefaultParameters = new Dictionary<string, object>
{
{ "speed_mode", "Juiced 🔥 (more speed)" },
{ "seed", -1 },
{ "output_format", "webp" },
{ "output_quality", 100 },
{ "guidance_scale", 2.5 },
{ "num_inference_steps", 28 },
{ "image_guidance_scale", 1.0 },
{ "refine_strength", 0.3 },
{ "clip_cfg_norm", true }
},
ImageInputKey = "image",
PromptKey = "prompt",
TimeoutSeconds = 300,
PollingDelayMs = 1500
};
/// <summary>
/// Stable Diffusion XL - Popular open-source image generation model.
/// </summary>
public static ModelPreset StableDiffusionXL => new()
{
Name = "Stable Diffusion XL",
ModelName = "stability-ai/sdxl",
ModelVersion = "7762fd07cf82c948538e41f63f77d685e02b063e37e496e96eefd46c929f9bdc",
Type = ModelType.Image,
DefaultPrompt = "high quality, detailed",
DefaultParameters = new Dictionary<string, object>
{
{ "width", 1024 },
{ "height", 1024 },
{ "num_outputs", 1 },
{ "scheduler", "K_EULER" },
{ "num_inference_steps", 25 },
{ "guidance_scale", 7.5 },
{ "refine", "expert_ensemble_refiner" }
},
ImageInputKey = "image",
PromptKey = "prompt",
TimeoutSeconds = 300,
PollingDelayMs = 1500
};
/// <summary>
/// Ideogram V3 Turbo - Best model for generating images with realistic, legible text.
/// </summary>
public static ModelPreset IdeogramV3Turbo => new()
{
Name = "Ideogram V3 Turbo",
ModelName = "ideogram-ai/ideogram-v3-turbo",
ModelVersion = "d9b3748f95c0fe3e71f010f8cc5d80e8f5252acd0e74b1c294ee889eea52a47b",
Type = ModelType.Image,
DefaultPrompt = "high quality image",
DefaultParameters = new Dictionary<string, object>
{
{ "aspect_ratio", "1:1" },
{ "magic_prompt_option", "Auto" }
},
ImageInputKey = "image",
PromptKey = "prompt",
TimeoutSeconds = 300,
PollingDelayMs = 1500
};
/// <summary>
/// Recraft V3 SVG - First major text-to-image model that generates high quality SVG images, logos, and icons.
/// </summary>
public static ModelPreset RecraftV3Svg => new()
{
Name = "Recraft V3 SVG",
ModelName = "recraft-ai/recraft-v3-svg",
ModelVersion = "df041379628fa1d16bd406409930775b0904dc2bc0f3e3f38ecd2a4389e9329d",
Type = ModelType.Image,
DefaultPrompt = "clean vector illustration",
DefaultParameters = new Dictionary<string, object>
{
{ "size", "1024x1024" },
{ "style", "any" }
},
ImageInputKey = "image",
PromptKey = "prompt",
TimeoutSeconds = 300,
PollingDelayMs = 1500
};
#endregion
#region Video Models
/// <summary>
/// Seedance 1 Pro by ByteDance - High-quality video generation with image-to-video support.
/// </summary>
public static ModelPreset SeedancePro => new()
{
Name = "Seedance 1 Pro",
ModelName = "bytedance/seedance-1-pro",
ModelVersion = "5fe042776269a7262e69b14f0b835b88b8e5eff9f990cadf31b8f984ed0419ad",
Type = ModelType.Video,
DefaultPrompt = "animate smoothly, maintain consistency",
DefaultParameters = new Dictionary<string, object>
{
{ "duration", 5 },
{ "resolution", "720p" },
{ "aspect_ratio", "16:9" },
{ "fps", 24 },
{ "camera_fixed", false }
},
ImageInputKey = "image",
PromptKey = "prompt",
TimeoutSeconds = 600,
PollingDelayMs = 3000
};
/// <summary>
/// Ray Flash 2 720p by Luma - Fast video generation with camera control concepts.
/// </summary>
public static ModelPreset LumaRayFlash => new()
{
Name = "Luma Ray Flash 2",
ModelName = "luma/ray-flash-2-720p",
ModelVersion = "1cf3c6a9e26e7dadc776bca7497e003267acf1ec5b9ad3794d2a10a4bfa84751",
Type = ModelType.Video,
DefaultPrompt = "cinematic motion, smooth animation",
DefaultParameters = new Dictionary<string, object>
{
{ "duration", 5 },
{ "aspect_ratio", "16:9" },
{ "loop", false }
},
ImageInputKey = "start_image",
PromptKey = "prompt",
TimeoutSeconds = 600,
PollingDelayMs = 3000
};
/// <summary>
/// Kling 1.6 Pro by Kuaishou - Professional video generation.
/// </summary>
public static ModelPreset Kling16Pro => new()
{
Name = "Kling 1.6 Pro",
ModelName = "kwaivgi/kling-v1.6-pro",
ModelVersion = "974c9c5bc69f8f9c178ddea80d8936ba46c48081ad6b6ccca8843d44010c0642",
Type = ModelType.Video,
DefaultPrompt = "smooth cinematic video",
DefaultParameters = new Dictionary<string, object>
{
{ "duration", 5 },
{ "aspect_ratio", "16:9" }
},
ImageInputKey = "start_image",
PromptKey = "prompt",
TimeoutSeconds = 600,
PollingDelayMs = 3000
};
/// <summary>
/// Wan 2.1 by Alibaba - Image-to-video with 480p/720p support.
/// </summary>
public static ModelPreset Wan21 => new()
{
Name = "Wan 2.1",
ModelName = "alibaba/wan-2.1-i2v-480p",
ModelVersion = "67035bc8dd4a6058c0dcdeec7de3e65e4a5d0bf78258aeb2bb5e67096cb5cd45",
Type = ModelType.Video,
DefaultPrompt = "animate the image smoothly",
DefaultParameters = new Dictionary<string, object>
{
{ "max_area", "480p" },
{ "num_frames", 81 },
{ "fast_mode", "Balanced" }
},
ImageInputKey = "image",
PromptKey = "prompt",
TimeoutSeconds = 600,
PollingDelayMs = 3000
};
/// <summary>
/// MiniMax Video 01 - Text and image to video generation.
/// </summary>
public static ModelPreset MiniMaxVideo => new()
{
Name = "MiniMax Video 01",
ModelName = "minimax/video-01",
ModelVersion = "c8bcc4751328608bb75043b3af7bed677d1e77e765a065bb298b8b137b94e86b",
Type = ModelType.Video,
DefaultPrompt = "cinematic video generation",
DefaultParameters = new Dictionary<string, object>(),
ImageInputKey = "first_frame_image",
PromptKey = "prompt",
TimeoutSeconds = 600,
PollingDelayMs = 3000
};
/// <summary>
/// Google Veo 3 Fast - State of the art video generation from Google.
/// </summary>
public static ModelPreset GoogleVeo3Fast => new()
{
Name = "Google Veo 3 Fast",
ModelName = "google/veo-3-fast",
ModelVersion = "368d4063e21ecf73746b8e6d27989837d97ba07b5eca43a4e5488c852e10c2ec",
Type = ModelType.Video,
DefaultPrompt = "cinematic video with natural motion",
DefaultParameters = new Dictionary<string, object>
{
{ "duration", 8 },
{ "aspect_ratio", "16:9" },
{ "resolution", "1080p" },
{ "generate_audio", true }
},
ImageInputKey = "image",
PromptKey = "prompt",
TimeoutSeconds = 600,
PollingDelayMs = 3000
};
/// <summary>
/// Kling 2.5 Turbo Pro by Kuaishou - Latest high-quality video generation.
/// </summary>
public static ModelPreset Kling25TurboPro => new()
{
Name = "Kling 2.5 Turbo Pro",
ModelName = "kwaivgi/kling-v2.5-turbo-pro",
ModelVersion = "939cd1851c5b112f284681b57ee9b0f36d0f913ba97de5845a7eef92d52837df",
Type = ModelType.Video,
DefaultPrompt = "smooth cinematic video",
DefaultParameters = new Dictionary<string, object>
{
{ "duration", 5 },
{ "aspect_ratio", "16:9" },
{ "guidance_scale", 0.5 }
},
ImageInputKey = "start_image",
PromptKey = "prompt",
TimeoutSeconds = 600,
PollingDelayMs = 3000
};
#endregion
/// <summary>
/// Get all available presets.
/// </summary>
public static IReadOnlyList<ModelPreset> All => new[]
{
// Image models
HiDreamE1,
StableDiffusionXL,
IdeogramV3Turbo,
RecraftV3Svg,
// Video models
GoogleVeo3Fast,
Kling25TurboPro,
Kling16Pro,
SeedancePro,
LumaRayFlash,
Wan21,
MiniMaxVideo
};
/// <summary>
/// Get all image model presets.
/// </summary>
public static IReadOnlyList<ModelPreset> ImageModels => All.Where(p => p.Type == ModelType.Image).ToList();
/// <summary>
/// Get all video model presets.
/// </summary>
public static IReadOnlyList<ModelPreset> VideoModels => All.Where(p => p.Type == ModelType.Video).ToList();
/// <summary>
/// Find a preset by model name.
/// </summary>
public static ModelPreset? FindByName(string modelName)
{
return All.FirstOrDefault(p =>
p.ModelName.Equals(modelName, StringComparison.OrdinalIgnoreCase) ||
p.Name.Equals(modelName, StringComparison.OrdinalIgnoreCase));
}
}
/// <summary>
/// Type of model output.
/// </summary>
public enum ModelType
{
Image,
Video
}
/// <summary>
/// A preset configuration for a specific Replicate model.
/// </summary>
public class ModelPreset
{
/// <summary>
/// Display name for the preset.
/// </summary>
public string Name { get; set; } = string.Empty;
/// <summary>
/// Replicate model identifier (owner/model-name).
/// </summary>
public string ModelName { get; set; } = string.Empty;
/// <summary>
/// Specific model version hash.
/// </summary>
public string ModelVersion { get; set; } = string.Empty;
/// <summary>
/// Type of output (Image or Video).
/// </summary>
public ModelType Type { get; set; }
/// <summary>
/// Default prompt for this model.
/// </summary>
public string DefaultPrompt { get; set; } = string.Empty;
/// <summary>
/// Default parameters for this model's API.
/// </summary>
public Dictionary<string, object> DefaultParameters { get; set; } = new();
/// <summary>
/// The key name used for image input (e.g., "image", "start_image", "first_frame_image").
/// </summary>
public string ImageInputKey { get; set; } = "image";
/// <summary>
/// The key name used for the prompt (usually "prompt").
/// </summary>
public string PromptKey { get; set; } = "prompt";
/// <summary>
/// Timeout in seconds for this model.
/// </summary>
public int TimeoutSeconds { get; set; } = 300;
/// <summary>
/// Polling delay in milliseconds.
/// </summary>
public int PollingDelayMs { get; set; } = 2000;
/// <summary>
/// Create a copy of the default parameters that can be modified.
/// </summary>
public Dictionary<string, object> CloneParameters()
{
return new Dictionary<string, object>(DefaultParameters);
}
/// <summary>
/// Build the input dictionary for an API call.
/// </summary>
/// <param name="prompt">The prompt to use.</param>
/// <param name="imageData">Optional image data (base64 or URL).</param>
/// <param name="customParameters">Optional custom parameters to override defaults.</param>
public Dictionary<string, object> BuildInput(
string? prompt = null,
string? imageData = null,
Dictionary<string, object>? customParameters = null)
{
var input = CloneParameters();
// Set prompt
input[PromptKey] = prompt ?? DefaultPrompt;
// Set image if provided
if (!string.IsNullOrEmpty(imageData))
{
input[ImageInputKey] = imageData;
}
// Apply custom parameter overrides
if (customParameters != null)
{
foreach (var kvp in customParameters)
{
input[kvp.Key] = kvp.Value;
}
}
return input;
}
}
}