Commit c5a56e37 authored by Matteo's avatar Matteo
Browse files

add server script

parent 6c86aca6
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/tape-audio-restoration/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
click==8.1.3
contourpy==1.0.7
control==0.9.3.post2
cycler==0.11.0
dnspython==2.3.0
email-validator==1.3.1
fastapi==0.95.0
fonttools==4.39.3
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
kiwisolver==1.4.4
MarkupSafe==2.1.2
matplotlib==3.7.1
numpy==1.23.5
orjson==3.8.9
packaging==23.0
Pillow==9.5.0
pydantic==1.10.7
pyparsing==3.0.9
python-dateutil==2.8.2
python-dotenv==1.0.0
python-multipart==0.0.6
PyYAML==6.0
rfc3986==1.5.0
scipy==1.10.0
six==1.16.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
import subprocess
import json
import yaml
from fastapi import FastAPI, Response, status
from tapeAudioRestoration 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) *Tape Audio Restoration* AIM, providing:
* Restored Audio Files;
* Editing List.
""",
version=__version__,
contact={
"name": __maintainer__,
"email": __email__
},
license_info={
"name": __license__,
}
)
@app.get("/")
def index():
return {"endpoints": ["restore", "docs"]}
@app.get("/restore", status_code=200)
async def restore(files_name: str, equalization_w: str, equalization_r: str, speed_w: str, speed_r: str, response: Response, working_path: str | None = None):
process = [
"python",
"tapeAudioRestoration.py",
"--files_name", files_name,
"--equalization-w", equalization_w,
"--equalization-r", equalization_r,
"--speed-w", speed_w,
"--speed-r", speed_r
]
if working_path is not None:
process.extend(["--working_path", working_path])
else:
with open("config.yaml") as yaml_file:
config = yaml.safe_load(yaml_file)
process.extend(["--working_path", config["WorkingPath"]])
cprocess = subprocess.run(process, capture_output=True)
if cprocess.returncode == 0:
with open('EditingList.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