-
Notifications
You must be signed in to change notification settings - Fork 3
/
api_main.py
37 lines (30 loc) · 1.04 KB
/
api_main.py
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
import shutil
import os
import uvicorn
from fastapi import FastAPI,File,UploadFile
from fastapi.responses import FileResponse
from fastapi.middleware.cors import CORSMiddleware
from helper import generate_image
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# def load_image_into_numpy_array(data):
# return np.array(Image.open(BytesIO(data)))
@app.get('/')
def index():
return {"GAN": 'This Model Generate satellite images into google map'}
@app.post("/uploadfile/")
async def create_upload_file(file: UploadFile = File(...)):
with open(os.path.join(f"images/input/", file.filename), 'wb+') as buffer:
shutil.copyfileobj(file.file, buffer)
input_file_path = f"images/input/{file.filename}"
output_file_name = generate_image(input_file_path)
output_file_path = f"images/output/{output_file_name}"
return FileResponse(output_file_path)
if __name__=="__main__":
uvicorn.run(app,host="127.0.0.1",port=8000)