raddiv's picture
Update app.py
4cad12b verified
Raw History Blame Contribute Delete
743 Bytes
from fastapi import FastAPI, UploadFile, File
from PIL import Image
import io, base64
app = FastAPI()
@app.post("/upscale")
async def upscale(file: UploadFile = File(...), scale: int = 2):
input_bytes = await file.read()
image = Image.open(io.BytesIO(input_bytes)).convert("RGB")
w, h = image.size
new_size = (w * scale, h * scale)
upscaled = image.resize(new_size, Image.LANCZOS)
buf = io.BytesIO()
upscaled.save(buf, format="PNG")
img_b64 = base64.b64encode(buf.getvalue()).decode()
return {"image_base64": img_b64, "format": "png", "scale": scale,
"original_size": f"{w}x{h}", "new_size": f"{new_size[0]}x{new_size[1]}"}
@app.get("/health")
async def health():
return {"status": "ok"}