File size: 805 Bytes
d59aeff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from pathlib import Path
from flask_restx import Namespace, Resource, fields

api = Namespace('synthesizers', description='Synthesizers related operations')

synthesizer = api.model('Synthesizer', {
    'name': fields.String(required=True, description='The synthesizer name'),
    'path': fields.String(required=True, description='The synthesizer path'),
})

synthesizers_cache = {}
syn_models_dirt = "synthesizer/saved_models"
synthesizers = list(Path(syn_models_dirt).glob("**/*.pt"))
print("Loaded synthesizer models: " + str(len(synthesizers)))

@api.route('/')
class SynthesizerList(Resource):
    @api.doc('list_synthesizers')
    @api.marshal_list_with(synthesizer)
    def get(self):
        '''List all synthesizers'''
        return list({"name": e.name, "path": str(e)} for e in synthesizers)