C# => Python Diffusers Inferface
- ChromaPipeline
- ChromaImg2ImgPipeline
- QwenImagePipeline
- QwenImageImg2ImgPipeline
- QwenImageEditPipeline
- WanPipeline
- WanImageToVideoPipeline
- ZImagePipeline
- ZImageImg2ImgPipeline
The PythonService can be used to download and install Python and create virtual environments
// Virtual Environment Config
var serverConfig = new EnvironmentConfig
{
Environment = "default-cuda",
Directory = "PythonRuntime",
Requirements =
[
"--extra-index-url https://download.pytorch.org/whl/cu118",
"torch==2.7.0+cu118",
"typing",
"wheel",
"transformers",
"accelerate",
"diffusers",
"protobuf",
"sentencepiece",
"pillow",
"ftfy",
"scipy",
"peft"
]
};
// PythonManager
var pythonService = new PythonManager(serverConfig);
// Create/Load Virtual Environment
await pythonService.CreateEnvironmentAsync(PipelineProgress.ConsoleCallback);Once you have created a virtual environment you can now load a pipeline
// Pipeline Config
var pipelineConfig = new PipelineConfig
{
Path = "Qwen/Qwen-Image-Edit",
Pipeline = "QwenImagePipeline",
ProcessType = ProcessType.ImageEdit,
DataType = DataType.Bfloat16,
MemoryMode = MemoryModeType.OffloadCPU
};
// Create Pipeline Proxy
using (var pythonPipeline = new PythonPipeline(pipelineConfig, PipelineProgress.ConsoleCallback))
{
// Download/Load Model
await pythonPipeline.LoadAsync();
// Generate Option
var options = new PipelineOptions
{
Prompt = "Yarn art style",
Steps = 30,
Width = 1024,
Height = 1024,
GuidanceScale = 4f,
Scheduler = SchedulerType.FlowMatchEulerDiscrete,
ImageInput = new ImageInput("Image.png")
};
// Generate
var response = await pythonPipeline.GenerateAsync(options);
// Save Image
await response
.AsImageTensor()
.SaveAsync("Result.png");
}