1 API document
joseph edited this page 2025-07-30 16:28:27 +10:00

📘 API Documentation

🧠 POST /api/v1/gen-info

🎯 Mục đích:

Trích xuất thông tin promptnegative_prompt từ ảnh có chứa metadata được tạo bởi các công cụ như Stable Diffusion (txt2img, inpainting, v.v.). => Tải ảnh vào hệ thống


📥 Request:

  • Content-Type: multipart/form-data
  • Body:
    Field Type Required Description
    file UploadFile Ảnh định dạng PNG/JPEG chứa thông tin parameters trong metadata.

📘 Request Mẫu:

curl -X POST http://localhost:8000/api/v1/gen-info   -F "file=@/path/to/image.png"

📤 Response:

{
  "prompt": "a beautiful landscape, mountain, 8k",
  "negative_prompt": "blurry, low quality"
}

🖌️ POST /api/v1/inpaint

🎯 Mục đích:

Tiến hành inpainting ảnh bằng cách sử dụng prompt mô tả và mask vùng cần thay thế. Kết quả là một ảnh mới được tạo ra theo yêu cầu. => Remove vật thể


📥 Request:

  • Content-Type: application/json
  • Body:
Field Type Default Description
image string Bắt buộc Ảnh gốc (base64 có header data:image/...).
mask string Bắt buộc Ảnh mask (base64).
prompt string "" Mô tả mong muốn tạo ra.
negative_prompt string "" Prompt phủ định (tránh những gì không muốn).
sd_model string "stabilityai/stable-diffusion-2-1" Model diffusion sử dụng.
sd_vae string "" Custom VAE (nếu có).
sd_lora string "" Đường dẫn tới model LoRA.
sd_lora_scale float 1.0 Độ ảnh hưởng của LoRA.
sd_seed int -1 Seed khởi tạo (-1 là random).
sd_steps int 20 Số bước sampling.
sd_guidance_scale float 7.5 Mức độ bám prompt.
sd_strength float 0.75 Độ lệch ảnh gốc.
sd_sampler string "uni_pc" Sampling method.
hd_strategy string "Original" Chiến lược xử lý ảnh lớn (Crop, Resize, Tile, v.v.).
hd_strategy_crop_margin int 128 Lề khi crop.
hd_strategy_crop_trigger_size int 1280 Kích thước bắt đầu crop.
hd_strategy_resize_limit int 2048 Giới hạn khi resize.
ldm_sr_model string "" Super-resolution model.
ldm_sr_scale int 4 Tỉ lệ phóng to.
enable_hr bool false Bật chế độ high-res fix.
hr_scale float 2.0 Tỉ lệ upscale.
hr_upscaler string "RealESRGAN_x4plus" Upscaler sử dụng.
hr_second_pass_steps int 20 Bước xử lý lần 2.
hr_resize_x int 0 Resize X.
hr_resize_y int 0 Resize Y.
controlnet_method string "" Tên model ControlNet.
controlnet_condition string "" Base64 ảnh điều kiện.
controlnet_condition_image string "" Alias cho controlnet_condition.
controlnet_guess_mode bool false Đoán threshold tự động.
controlnet_guidance_start float 0.0 Giai đoạn bắt đầu áp dụng ControlNet.
controlnet_guidance_end float 1.0 Giai đoạn kết thúc ControlNet.
controlnet_processor_res int 512 Kích thước processor.
controlnet_threshold_a int 64 Ngưỡng A.
controlnet_threshold_b int 64 Ngưỡng B.
use_refiner bool false Có dùng model refiner không.
refiner_switch_at float 0.8 Ngưỡng chuyển refiner.
prompt_processor string "" Bộ xử lý prompt tự động.
cropper string "none" Cách crop ảnh.
extender string "none" Chiến lược mở rộng ảnh.
sam_model_name string "vit_h" Model SAM segmentation.

📘 Request Mẫu:

{
  "brushnet_conditioning_scale": 1,
  "brushnet_method": "random_mask",
  "controlnet_conditioning_scale": 0.4,
  "controlnet_method": "",
  "croper_height": 512,
  "croper_width": 512,
  "croper_x": -64,
  "croper_y": -64,
  "cv2_flag": "INPAINT_TELEA",
  "cv2_radius": 40,
  "enable_brushnet": false,
  "enable_controlnet": false,
  "enable_powerpaint_v2": false,
  "extender_height": 384,
  "extender_width": 384,
  "extender_x": 0,
  "extender_y": 0,
  "hd_strategy": "Crop",
  "hd_strategy_crop_margin": 128,
  "hd_strategy_crop_triger_size": 640,
  "hd_trategy_resize_imit": 2048,
  "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYA...",
  "ldm_sampler": "ddim",
  "ldm_steps": 30,
  "mask": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYAAAAGACAYAAACkx7W/AAAAAXNSR0IArs4c6QAA...",
  "negative_prompt": "out of frame, lowres, error, cropped, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, out of frame, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, disfigured, gross proportions, malformed limbs, watermark, signature",
  "p2p_image_guidance_scale": 1.5,
  "paint_by_example_example_image": null,
  "powerpaint_task": "text-guided",
  "prompt": "",
  "sd_guidance_scale": 7.5,
  "sd_lcm_lora": false,
  "sd_mask_blur": 12,
  "sd_match_histograms": false,
  "sd_sampler": "DPM++ 2M",
  "sd_seed": -1,
  "sd_steps": 50,
  "sd_strength": 1,
  "use_croper": false,
  "use_extender": false,
  "zits_wireframe": true
}


---

### 📤 Response:

- **Content-Type**: `image/png`
- **Body**: ảnh đã xử lý.
- **Headers**:
  - `X-Seed`: giá trị seed được sử dụng trong quá trình tạo ảnh.

📸 POST /api/v1/run_plugin_gen_image

🧾 Mục đích

Sinh ảnh từ plugin xử lý ảnh đầu vào (base64). => Remove background


📥 Request

Trường Kiểu dữ liệu Bắt buộc Mô tả
name string Tên plugin cần sử dụng (ví dụ: RemoveBG)
image string (base64) Ảnh đầu vào được mã hóa base64, có thể có tiền tố data:image/...
upscale float Tỷ lệ phóng ảnh, mặc định 1

📦 Request mẫu

{
  "name": "RemoveBG",
  "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYA...",
  "upscale": 1
}

🎭 POST /api/v1/run_plugin_gen_mask

🧾 Mục đích

Sinh ra mask ảnh từ plugin hỗ trợ gen_mask, dựa trên ảnh đầu vào và các thao tác tương tác (nếu có). => Tạo một cái mặt nạ bao quanh chủ thể


📥 Request

Trường Kiểu dữ liệu Bắt buộc Mô tả
name string Tên plugin cần sử dụng (ví dụ: RemoveBG)
image string (base64) Ảnh đầu vào được mã hóa base64, có thể có tiền tố data:image/...
clicks List[List[int]] Danh sách điểm tương tác dạng [[x, y, 0/1], ...], với 0 là negative, 1 là positive
upscale float Tỷ lệ phóng ảnh, mặc định 2.0

📦 Request mẫu

{
  "name": "RemoveBG",
  "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYA...",
  "upscale": 1
}