-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
67 lines (54 loc) · 1.79 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
57
58
59
60
61
62
63
64
65
66
67
from typing import Union
from fastapi import HTTPException
from stream_service import init_steam, threads, source_queue, source_sl, app, validate_rtsp, fetch_data, fetch_all_data, \
fetch_all_cameras
from fastapi.middleware.cors import CORSMiddleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# single_thread, my_queue, sl, app = init_threads()
@app.get("/", status_code=202)
async def root():
return {"msg": "RESTful de IA. Helmet-Detection"}
@app.get("/stream", status_code=200)
async def root(
stream_url: Union[str, None] = None,
stream_save: Union[str, None] = None,
camera_name: Union[str, None] = None
):
type_url = validate_rtsp(stream_url)
if type_url == -2:
raise HTTPException(status_code=404, detail="Recurso incorrecto")
threads.submit(init_steam, stream_url, source_sl, source_queue, type_url, stream_save, camera_name)
return {"msg": "Iniciando procesado de stream"}
@app.get("/stop", status_code=202)
async def say_hello():
source_queue.put(True)
return {"msg": "Deteniendo procesamiento de stream"}
@app.get("/fetch", status_code=200)
async def get_dates(date: Union[str, None] = None, camara: Union[str, None] = None):
dates = fetch_data(date, camara)
return {
"msg": "exito",
'data': dates
}
@app.get("/fetchAll", status_code=200)
async def get_all_dates():
dates = fetch_all_data()
return {
"msg": "exito",
'data': dates
}
@app.get("/fetchAllCameras", status_code=200)
async def get_all_cameras():
cameras = fetch_all_cameras()
return {
"msg": "exito",
'data': cameras
}
# if __name__ == '__main__':
# uvicorn.run(app, port=8080, host='0.0.0.0')