Spaces:
Running
Running
add all
Browse files4 unmodified lines56789105 unmodified lines16171819202122234 unmodified linesimport uvicornimport jsonapp = FastAPI()5 unmodified lines@app.post("/img2img")async def predict(url:str,prompt:str):return f"您好,{url+prompt}"@app.post("/predict")async def predict(request:Request):4 unmodified lines567891011121314151617185 unmodified lines2425262728293031323334353637383940414243444546474849505152535455565758596061626364654 unmodified linesimport uvicornimport jsonfrom PIL import Imageimport timefrom constants import DESCRIPTION, LOGOfrom model import get_pipelinefrom utils import replace_backgroundfrom diffusers.utils import load_imageimport base64app = FastAPI()5 unmodified lines@app.post("/img2img")async def predict(url:str,prompt:str):MAX_QUEUE_SIZE = 4start = time.time()pipeline = get_pipeline()url = "https://img2.baidu.com/it/u=1845675188,2679793929&fm=253&fmt=auto&app=138&f=JPEG?w=667&h=500"prompt = "a nice Comfortable and clean. According to Baidu Education Information, the adjectives for a room include: comfortable, clean, beautiful, spacious, warm, quiet, luxurious, pleasant, exquisite, and warm ,colorful, light room width sofa,8k"init_image = load_image(url).convert("RGB")# image1 = replace_background(init_image.resize((256, 256)))w, h = init_image.sizenewW = 512newH = int(h * newW / w)img = init_image.resize((newW, newH))end1 = time.time()print("加载管道:", end1 - start)result = pipeline(prompt=prompt,image=img,strength=0.6,seed=10,width=256,height=256,guidance_scale=1,num_inference_steps=4,)output_image = result.images[0]end2 = time.time()print("测试",output_image)print("s生成完成:", end2 - end1)output_image.save("./imageclm5.png")with open(output_image, 'rb') as image_file:encoded_string = base64.b64encode(image_file.read()).decode('utf-8')print(encoded_string)return encoded_string@app.post("/predict")async def predict(request:Request):
main.py+44-2