Commit d5720591 authored by Matteo's avatar Matteo
Browse files

update server endpoints

parent 2d316e30
PerformanceResults.xlsx PerformanceResults.xlsx
README.md README.md
.DS_Store .DS_Store
\ No newline at end of file server/venv
server/pycache
\ No newline at end of file
{"WorkingPath": "/data", "FilesName": "sad", "Brands": true, "Speed": 7.5, "TapeThresholdPercentual": 80, "CapstanThresholdPercentual": 50, "MinDist": 10, "AngleThresh": 10000, "ScaleThresh": 200, "PosThresh": 40, "MinDistCapstan": 1, "AngleThreshCapstan": 1000, "ScaleThreshCapstan": 30, "PosThreshCapstan": 10} {"WorkingPath": "./", "FilesName": "prova", "Brands": true, "Speed": 7.5, "TapeThresholdPercentual": 80, "CapstanThresholdPercentual": 50, "MinDist": 10, "AngleThresh": 10000, "ScaleThresh": 200, "PosThresh": 40, "MinDistCapstan": 1, "AngleThreshCapstan": 1000, "ScaleThreshCapstan": 30, "PosThreshCapstan": 10}
\ No newline at end of file \ No newline at end of file
...@@ -2,4 +2,11 @@ title: Video Analyser ...@@ -2,4 +2,11 @@ title: Video Analyser
description: > description: >
This is the API for the Video Analyser. This is the API for the Video Analyser.
It is used to upload videos and get the results of the analysis. It is used to upload videos and get the results of the analysis.
The analysis is done by the Video Analyser The analysis is done by the Video Analyser
\ No newline at end of file license_info:
name: GPL-3.0
url: https://www.gnu.org/licenses/gpl-3.0.en.html
contact:
name: Matteo Spanio
email: dev2@audioinnova.com
version: 1.0.0
\ No newline at end of file
import os
import subprocess
import json
import yaml
def analyze(files_name: str, working_path: str | None = None) -> subprocess.CompletedProcess:
executable = os.path.abspath("frame_extraction/bin/frame_extraction")
config = get_file_content("config/config.json", "json")
# 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 = subprocess.run([executable], capture_output=True)
return process
def get_file_content(file_name: str, format: str) -> dict:
with open(file_name) as fd:
if format == "yaml":
content = yaml.safe_load(fd)
return content
elif format == "json":
content = json.load(fd)
return content
import os
import subprocess
import json
import yaml
from fastapi import FastAPI, Response, status from fastapi import FastAPI, Response, status
with open("VideoAnalyser.json") as json_file: import server.functions as functions
info = json.load(json_file)
app = FastAPI( info = functions.get_file_content('server/documentation.yaml', 'yaml')
title="Video Analyser", app = FastAPI(**info)
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("/") @app.get("/")
def index(): def index():
return {"endpoints": ["analyze", "docs"]} return {"endpoints": ["irregularityFile1", "irregularityFile2", "description", "docs"]}
@app.get("/description") @app.get("/description")
async def get_description(): async def get_description():
with open('server/documentation.yaml') as yaml_file: return info
documentation = yaml.safe_load(yaml_file)
return documentation
@app.get("/analyze", status_code=200) @app.get("/irregularityFile/{id}", status_code=200)
async def analyze(files_name: str, response: Response, working_path: str | None = None ): def get_irregularity_file(files_name: str, id: int, response: Response, working_path: str | None = None):
executable = os.path.abspath("frame_extraction/bin/frame_extraction") required_file = f'VideoAnalyser_IrregularityFileOutput{id}.json'
try:
return functions.get_file_content(required_file, 'json')
# Read configuration file except:
with open("config/config.json") as json_file: process = functions.analyze(files_name, working_path)
config = json.load(json_file)
# Update configuration file with query parameters if process.returncode == 0:
config["FilesName"] = files_name return functions.get_file_content(required_file, 'json')
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 = [ else:
executable, response.status_code = status.HTTP_412_PRECONDITION_FAILED
] return {"error": {
"returncode": process.returncode,
cprocess = subprocess.run(process, capture_output=True) "stdout": process.stdout.decode("utf-8"),
"stderr": process.stderr.decode("utf-8"),
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"),
}}
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