Brazela commited on
Commit
2a74393
·
verified ·
1 Parent(s): 36e881d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, UploadFile, File
2
+ from fastapi.responses import Response
3
+ from PIL import Image
4
+ import io
5
+
6
+ from model import upscale_image
7
+
8
+ app = FastAPI()
9
+
10
+ @app.get("/")
11
+ def home():
12
+ return {"status": "upscale API running"}
13
+
14
+ @app.post("/upscale")
15
+ async def upscale(image: UploadFile = File(...)):
16
+ input_data = await image.read()
17
+
18
+ img = Image.open(io.BytesIO(input_data))
19
+
20
+ output_img = upscale_image(img)
21
+
22
+ buffer = io.BytesIO()
23
+ output_img.save(buffer, format="PNG")
24
+
25
+ return Response(content=buffer.getvalue(), media_type="image/png")