Commit fa141ccd authored by Matteo's avatar Matteo
Browse files

add server script

parent 8e65c57d
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/packager/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
anyio==3.6.2
certifi==2022.12.7
charset-normalizer==3.1.0
click==8.1.3
decorator==4.4.2
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
imageio==2.27.0
imageio-ffmpeg==0.4.8
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.2
moviepy==1.0.3
numpy==1.24.2
orjson==3.8.9
Pillow==9.5.0
proglog==0.1.10
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
sniffio==1.3.0
starlette==0.26.1
tqdm==4.65.0
typing_extensions==4.5.0
ujson==5.7.0
urllib3==1.26.15
uvicorn==0.21.1
uvloop==0.17.0
watchfiles==0.19.0
websockets==11.0
import subprocess
import yaml
from fastapi import FastAPI, Response, status
from packager import __author__, __version__, __license__, __email__, __maintainer__
app = FastAPI(
title="Tape Audio Restoration",
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=__version__,
contact={
"name": __maintainer__,
"email": __email__
},
license_info={
"name": __license__,
}
)
@app.get("/")
def index():
return {"endpoints": ["restore", "docs"]}
@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"),
}}
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