from typing import List from pydantic import BaseModel from lama_cleaner.server import process import uvicorn from fastapi import FastAPI app = FastAPI() @app.on_event("startup") async def app_start(): image_bytes = open('image.jpg', 'rb') mask_bytes = open('mask.jpg', 'rb') # 将字节数据转换为Base64编码的字符串 files = { "image": image_bytes, "mask":mask_bytes } payload = { "ldmSteps": 25, "ldmSampler": "plms", "zitsWireframe": True, "hdStrategy": "Crop", "hdStrategyCropMargin": 196, "hdStrategyCropTrigerSize": 800, "hdStrategyResizeLimit": 2048, "prompt": "", "negativePrompt": "", "croperX": 307, "croperY": 544, "croperHeight": 512, "croperWidth": 512, "useCroper": False, "sdMaskBlur": 5, "sdStrength": 0.75, "sdSteps": 50, "sdGuidanceScale": 7.5, "sdSampler": "uni_pc", "sdSeed": -1, "sdMatchHistograms": False, "sdScale": 1, "cv2Radius": 5, "cv2Flag": "INPAINT_NS", "paintByExampleSteps": 50, "paintByExampleGuidanceScale": 7.5, "paintByExampleSeed": -1, "paintByExampleMaskBlur": 5, "paintByExampleMatchHistograms": False, "p2pSteps": 50, "p2pImageGuidanceScale": 1.5, "p2pGuidanceScale": 7.5, "controlnet_conditioning_scale": 0.4, "controlnet_method": "control_v11p_sd15_canny" }#payload用data resp = process(files=files,payload=payload) print(resp) if __name__ == '__main__': uvicorn.run(app, host='0.0.0.0', port=7860)