Commit 05a31479 authored by Matteo's avatar Matteo
Browse files

add server script

parent 8a30163b
venv
__pycache__
\ No newline at end of file
version: 1
formatters:
brief:
format: '%(message)s'
precise:
format: '[%(levelname)s %(name)s %(module)s:%(lineno)s - %(funcName)s() - %(asctime)s]\n\t %(message)s \n'
datefmt: '%d/%m/%Y %H:%M:%S'
handlers:
file:
class: logging.handlers.RotatingFileHandler
formatter: precise
filename: /var/log/video-analyzer/server.log
maxBytes: 10485760
backupCount: 3
console:
class: logging.StreamHandler
formatter: brief
loggers:
uvicorn:
level: INFO
handlers: [file, console]
propagate: no
\ No newline at end of file
title: Video Analyser
description: >
This is the API for the Video Analyser.
It is used to upload videos and get the results of the analysis.
The analysis is done by the Video Analyser
\ No newline at end of file
import os
import subprocess
import json
import yaml
from fastapi import FastAPI, Response, status
with open("VideoAnalyser.json") as json_file:
info = json.load(json_file)
app = FastAPI(
title="Video Analyser",
description=info["Description"],
version=info["Identifier"]["Specification"]["Version"],
contact={
"name": "Matteo Spanio",
"email": "dev2@audioinnova.com",
},
license_info={
"name": "GPL-3.0 License",
"url": "http://www.gnu.org/licenses/gpl-3.0.html"
}
)
@app.get("/")
def index():
return {"endpoints": ["analyze", "docs"]}
@app.get("/description")
async def get_description():
with open('server/documentation.yaml') as yaml_file:
documentation = yaml.safe_load(yaml_file)
return documentation
@app.get("/analyze", status_code=200)
async def analyze(files_name: str, response: Response, working_path: str | None = None ):
executable = os.path.abspath("frame_extraction/bin/frame_extraction")
# Read configuration file
with open("config/config.json") as json_file:
config = json.load(json_file)
# Update configuration file with query parameters
config["FilesName"] = files_name
if working_path is not None:
config["WorkingPath"] = working_path
with open("config/config.json", "w") as json_file:
json.dump(config, json_file)
process = [
executable,
]
cprocess = subprocess.run(process, capture_output=True)
if cprocess.returncode == 0:
with open('AudioAnalyser_IrregularityFileOutput1.json') as json_file:
editing_list = json.load(json_file)
return editing_list
else:
response.status_code = status.HTTP_412_PRECONDITION_FAILED
return {"error": {
"returncode": cprocess.returncode,
"stdout": cprocess.stdout.decode("utf-8"),
"stderr": cprocess.stderr.decode("utf-8"),
}}
anyio==3.6.2
certifi==2022.12.7
click==8.1.3
dnspython==2.3.0
email-validator==1.3.1
fastapi==0.95.0
h11==0.14.0
httpcore==0.16.3
httptools==0.5.0
httpx==0.23.3
idna==3.4
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.2
orjson==3.8.9
pydantic==1.10.7
python-dotenv==1.0.0
python-multipart==0.0.6
PyYAML==6.0
rfc3986==1.5.0
sniffio==1.3.0
starlette==0.26.1
typing_extensions==4.5.0
ujson==5.7.0
uvicorn==0.21.1
uvloop==0.17.0
watchfiles==0.19.0
websockets==11.0
Supports Markdown
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