Commit de57d05b authored by Karunarathna P.M.J.I.'s avatar Karunarathna P.M.J.I.

Upload main.py

parent 01a0ab68
import uvicorn
from fastapi import FastAPI, File, UploadFile
from fastapi.middleware.cors import CORSMiddleware
from tempfile import NamedTemporaryFile
import os
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
import cv2
from cv2CCTV import read_vid
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
# change to speed
@app.post("/video/detect-faces")
def detect_faces(file: UploadFile = File(...)):
temp = NamedTemporaryFile(delete=False)
try:
try:
contents = file.file.read()
with temp as f:
f.write(contents)
except Exception:
return {"message": "There was an error uploading the file"}
finally:
file.file.close()
res = process_video(temp.name) # Pass temp.name to VideoCapture()
except Exception:
return {"message": "There was an error processing the file"}
finally:
#temp.close() # the `with` statement above takes care of closing the file
os.remove(temp.name)
return res
def process_video(vid):
data=read_vid(vid)
print(data)
# cap = cv2.VideoCapture(vid)
return {"results":data}
if __name__ == "__main__":
uvicorn.run("main:app", host="127.0.0.1",port=8000, log_level="info")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment