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"), }}