-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
56 lines (43 loc) · 1.32 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import fastapi
from fastapi import UploadFile, File
from fastapi.middleware.cors import CORSMiddleware
# from io import BytesIO
from model.battingShotClassification.model import classifyBattingShot
from model.bowlingTypeClassificationModels.model import classifyBowlingType
import cv2
import os
# import asyncio
# asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
# import uvicorn
origins = ["*"]
# Create a FastAPI app.
app = fastapi.FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"])
@app.get("/")
def index():
return {"lol": "hahah"}
def read_video(file) -> cv2.VideoCapture:
video = cv2.VideoCapture(file)
return video
@app.post("/predict/video")
async def predict(video: UploadFile = File(...)):
with open("temp.mp4", "wb") as buffer:
buffer.write(await video.read())
video = read_video("temp.mp4")
battingType = classifyBattingShot(video)
bowlingType = classifyBowlingType()
prediction = {}
prediction.update(bowlingType)
prediction.update(battingType)
video.release()
os.remove("temp.mp4")
return prediction
# app.include_router(ToolsRoutes.router)
# Run the app.
# if __name__ == "__main__":
# uvicorn.run(app, port=8000, host="0.0.0.0")