Commit 92fed87d authored by Matteo's avatar Matteo
Browse files

refactor project structure

parent 2c47cd80
......@@ -10,4 +10,4 @@ RUN pip install --no-cache-dir -r requirements.txt
VOLUME [ "/data" ]
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "80", "--log-config", "config/logger.yaml"]
\ No newline at end of file
CMD ["uvicorn", "src.server:app", "--host", "0.0.0.0", "--port", "80", "--log-config", "config/logger.yaml"]
\ No newline at end of file
# Working path
WORKING_PATH: "/data"
# Name of the Preservation files (without extension)
FILES_NAME: "test"
FILES_NAME: test
FilesName: filename
WORKING_PATH: /data
WorkingPath: /home/user/preservation
title: Packager
description: |
[![MPAI CAE-ARP](https://img.shields.io/badge/MPAI%20CAE--ARP-gray?style=for-the-badge&logo=AppleMusic&logoColor=cyan&link=https://mpai.community/standards/mpai-cae/about-mpai-cae/)](https://mpai.community/standards/mpai-cae/about-mpai-cae/)
Implements the Technical Specification of [MPAI CAE-ARP](https://mpai.community/standards/mpai-cae/about-mpai-cae/#Figure2) *Packager* AIM, providing:
* Access Copy Files:
1. Restored Audio Files;
2. Editing List;
3. Set of Irregularity Images in a .zip file;
4. Irregularity File.
* Preservation Master Files:
1. Preservation Audio File;
2. Preservation Audio-Visual File where the audio has been replaced with the Audio of the Preservation Audio File
fully synchronised with the video;
3. Set of Irregularity Images in a .zip file;
4. Irregularity File.
version: "1.0.1"
contact:
name: Nadir Dalla Pozza
email: nadir.dallapozza@unipd.it
license_info:
name: GNU General Public License v3.0
url: https://www.gnu.org/licenses/gpl-3.0.en.html
\ No newline at end of file
anyio==3.6.2
appdirs==1.4.4
audioread==3.0.0
certifi==2022.12.7
cffi==1.15.1
charset-normalizer==3.1.0
click==8.1.3
decorator==4.4.2
......@@ -15,20 +18,35 @@ imageio==2.27.0
imageio-ffmpeg==0.4.8
itsdangerous==2.1.2
Jinja2==3.1.2
joblib==1.2.0
lazy_loader==0.2
librosa==0.10.0.post2
llvmlite==0.39.1
MarkupSafe==2.1.2
moviepy==1.0.3
numpy==1.24.2
mpai-cae-arp==0.2.0
msgpack==1.0.5
numba==0.56.4
numpy==1.23.3
orjson==3.8.9
packaging==23.0
Pillow==9.5.0
pooch==1.6.0
proglog==0.1.10
pycparser==2.21
pydantic==1.10.7
python-dotenv==1.0.0
python-multipart==0.0.6
PyYAML==6.0
requests==2.28.2
rfc3986==1.5.0
scikit-learn==1.2.2
scipy==1.10.1
sniffio==1.3.0
soundfile==0.12.1
soxr==0.3.4
starlette==0.26.1
threadpoolctl==3.1.0
tqdm==4.65.0
typing_extensions==4.5.0
ujson==5.7.0
......
import subprocess
import yaml
from fastapi import FastAPI, Response, status
from packager import __author__, __version__, __license__, __email__, __maintainer__
description ="""
[![MPAI CAE-ARP](https://img.shields.io/badge/MPAI%20CAE--ARP-gray?style=for-the-badge&logo=AppleMusic&logoColor=cyan&link=https://mpai.community/standards/mpai-cae/about-mpai-cae/)](https://mpai.community/standards/mpai-cae/about-mpai-cae/)
Implements the Technical Specification of [MPAI CAE-ARP](https://mpai.community/standards/mpai-cae/about-mpai-cae/#Figure2) *Packager* AIM, providing:
* Access Copy Files:
1. Restored Audio Files;
2. Editing List;
3. Set of Irregularity Images in a .zip file;
4. Irregularity File.
* Preservation Master Files:
1. Preservation Audio File;
2. Preservation Audio-Visual File where the audio has been replaced with the Audio of the Preservation Audio File
fully synchronised with the video;
3. Set of Irregularity Images in a .zip file;
4. Irregularity File.
"""
app = FastAPI(
title="Tape Audio Restoration",
description=description,
version=__version__,
contact={
"name": __maintainer__,
"email": __email__
},
license_info={
"name": __license__,
}
)
@app.get("/")
def index() -> list[str]:
return ["restore", "description" "docs"]
@app.get("/description")
def get_server_info():
return {
"name": "Packager",
"version": __version__,
"author": __author__,
"email": __email__,
"license": __license__,
"maintainer": __maintainer__,
"description": description
}
@app.get("/package", status_code=200)
async def predict(response: Response, files_name: str, working_path: str | None = None):
process = [
"python",
"packager.py",
]
# Read configuration file
with open("config.yaml") as yaml_file:
config = yaml.safe_load(yaml_file)
# Update configuration file with query parameters
config["FilesName"] = files_name
if working_path is not None:
config["WorkingPath"] = working_path
with open("config.yaml", "w") as yaml_file:
yaml.dump(config, yaml_file)
cprocess = subprocess.run(process, capture_output=True)
if cprocess.returncode == 0:
return {"message": "Package created successfully"}
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"),
}}
......@@ -4,7 +4,7 @@
MPAI CAE-ARP Packager.
Implements MPAI CAE-ARP Packager Technical Specification, providing:
- Access Copy Files:
- Access Copy Files:Images
1. Restored Audio Files.
2. Editing List.
3. Set of Irregularity Images in a .zip file.
......@@ -53,8 +53,8 @@ class CC:
def get_arguments() -> tuple[str, str]:
"""
Method to obtain arguments from config.yaml file or command line.
Default config.yaml, ignored if a command line argument is passed.
Method to obtain arguments from config/args.yaml file or command line.
Default config/args.yaml, ignored if a command line argument is passed.
:return: tuple consisting of two strings:
1) the working path;
2) the name of the Preservation files, which is key element to retrieve necessary files.
......@@ -65,7 +65,7 @@ def get_arguments() -> tuple[str, str]:
prog="python3 packager.py",
formatter_class=RawTextHelpFormatter,
description="A tool that implements MPAI CAE-ARP Packager Technical Specification.\n"
"By default, the configuration parameters are loaded from ./config.yaml file,\n"
"By default, the configuration parameters are loaded from ./config/args.yaml file,\n"
"but, alternately, you can pass command line arguments to replace them."
)
parser.add_argument(
......@@ -87,15 +87,15 @@ def get_arguments() -> tuple[str, str]:
# Read from configuration file
config = object
try:
config = yaml.safe_load(open('./config.yaml', 'r'))
config = yaml.safe_load(open('./config/args.yaml', 'r'))
if 'WORKING_PATH' not in config:
print(CC.RED + 'WORKING_PATH key not found in config.yaml!' + CC.END)
print(CC.RED + 'WORKING_PATH key not found in config/args.yaml!' + CC.END)
quit(os.EX_CONFIG)
if 'FILES_NAME' not in config:
print(CC.RED + 'FILES_NAME key not found in config.yaml!' + CC.END)
print(CC.RED + 'FILES_NAME key not found in config/args.yaml!' + CC.END)
quit(os.EX_CONFIG)
except FileNotFoundError:
print(CC.RED + 'config.yaml file not found!' + CC.END)
print(CC.RED + 'config/args.yaml file not found!' + CC.END)
quit(os.EX_NOINPUT)
working_path = config['WORKING_PATH']
files_name = config['FILES_NAME']
......@@ -159,7 +159,7 @@ def main():
print(CC.BOLD + "\nWelcome to ARP Packager!" + CC.END)
print("You are using Python version: " + sys.version)
# Get the input from config.yaml or command line
# Get the input from config/args.yaml or command line
working_path, files_name = get_arguments()
# Check if input is correct
temp_path = check_input(working_path, files_name)
......
import subprocess
from fastapi import FastAPI, Response, status, Query
from typing import Annotated
from mpai_cae_arp.files import File, FileType
from mpai_cae_arp.types.schema import Info
info = File("config/server.yaml", FileType.YAML).get_content()
app = FastAPI(**info)
@app.get("/")
def list_all_entrypoints() -> list[str]:
"""
Get the list of available main routes.
"""
return ["restore", "description", "docs"]
@app.get("/description")
def get_server_info() -> Info:
"""
Retrieve all the informations about the software running on the server.
"""
return info
@app.get("/package", status_code=200)
async def predict(
response: Response,
files_name: Annotated[str, Query(
description="Name of the audio/video file to be analyzed without the extension.",
example="filename"
)],
working_path: Annotated[str, Query(
description="Path to the directory containing the preservation files.",
examples={
"Absolute path": {"value": "/home/user/preservation"},
"Relative path": {"value": "preservation"}
}
)] = None
):
process = [
"python",
"src/packager.py",
]
config_file = File("config/args.yaml", FileType.YAML)
# Read configuration file
config = config_file.get_content()
# Update configuration file with query parameters
config["FilesName"] = files_name
if working_path is not None:
config["WorkingPath"] = working_path
config_file.write_content(config)
cprocess = subprocess.run(process, capture_output=True)
if cprocess.returncode == 0:
return {"message": "Package created successfully"}
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