Spaces:
Sleeping
Sleeping
File size: 1,981 Bytes
0ed2ee7 c5484f6 ee259c3 e07c4e9 04d0e09 423e05a cef2c6e 1e2deb3 1a9d9e0 aa021ca 697988f d687e0e 0ed2ee7 d687e0e e07c4e9 7f49cda f208512 423e05a f208512 7f49cda 423e05a f208512 423e05a f208512 423e05a f208512 423e05a f208512 423e05a cef2c6e aa021ca 45144b6 04d0e09 cef2c6e 423e05a e07c4e9 22c4eb1 cef2c6e 0950a65 ee259c3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
from fastapi import FastAPI,Body
import uvicorn
import json
import logging
from PIL import Image
import time
from constants import DESCRIPTION, LOGO
from model import get_pipeline
from utils import replace_background
from diffusers.utils import load_image
import base64
import io
from datetime import datetime
app = FastAPI(name="mutilParam")
pipeline = get_pipeline()
#Endpoints
#Root endpoints
@app.get("/")
def root():
return {"API": "Sum of 2 Squares"}
@app.post("/img2img")
async def predict(prompt=Body(...),imgbase64data=Body(...),userId=Body(None)):
pipeline = get_pipeline()
MAX_QUEUE_SIZE = 4
start = time.time()
print("参数",imgbase64data,prompt)
image_data = base64.b64decode(imgbase64data)
image1 = Image.open(io.BytesIO(image_data))
w, h = image1.size
newW = 512
newH = int(h * newW / w)
img = image1.resize((newW, newH))
end1 = time.time()
now = datetime.now()
print(now)
print("图像:", img.size)
print("加载管道:", end1 - start)
result = pipeline(
prompt=prompt,
image=image1,
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)
# 将图片对象转换为bytes
image_data = io.BytesIO()
# 将图像保存到BytesIO对象中,格式为JPEG
output_image.save(image_data, format='JPEG')
# 将BytesIO对象的内容转换为字节串
image_data_bytes = image_data.getvalue()
output_image_base64 = base64.b64encode(image_data_bytes).decode('utf-8')
print("完成的图片:", output_image_base64)
logger = logging.getLogger('')
logger.info(output_image_base64)
return output_image_base64
@app.post("/predict")
async def predict(prompt=Body(...)):
return f"您好,{prompt}"
|