mod constants;
mod dummy;
mod python;
#[cfg(feature = "comfy-renderer")]
mod comfyui;
pub use constants::OUTPUT_FILENAME;
pub use dummy::DummyRenderer;
pub use python::PythonRenderer;
#[cfg(feature = "comfy-renderer")]
pub use comfyui::ComfyUIRenderer;
pub use crate::config::model::PythonConfig;
use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::fmt;
use std::path::{Path, PathBuf};
use vc_shared::hashing::Sha256Digest;
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum RendererKind {
Dummy,
Python,
Comfy,
}
impl fmt::Display for RendererKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RendererKind::Dummy => write!(f, "dummy"),
RendererKind::Python => write!(f, "python"),
RendererKind::Comfy => write!(f, "comfy"),
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct RenderOutput {
pub image_path: PathBuf,
pub image_hash: Sha256Digest,
pub duration_ms: u64,
pub backend: RendererKind,
pub seed: u64,
}
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct RenderParams {
pub width: u32,
pub height: u32,
pub steps: u32,
pub cfg: f64,
pub backend_options: serde_json::Value,
}
impl RenderParams {
pub fn new(width: u32, height: u32, steps: u32, cfg: f64) -> Self {
Self {
width,
height,
steps,
cfg,
backend_options: serde_json::Value::Object(serde_json::Map::new()),
}
}
pub fn with_backend_options(mut self, options: serde_json::Value) -> Self {
self.backend_options = options;
self
}
}
impl Default for RenderParams {
fn default() -> Self {
Self::new(1024, 1024, 30, 7.0)
}
}
pub trait ImageRenderer: Send + Sync {
fn render(
&self,
prompt: &str,
negative_prompt: &str,
seed: u64,
output_dir: &Path,
params: &RenderParams,
) -> Result<RenderOutput>;
}