meissa/meissa/main.py

91 lines
2.2 KiB
Python

# Meissa - A trainable and simple text to speech server
#
# Copyright (c) 2023 Sameer Rahmani <lxsameer@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
This module contains all the CLI subcommands and interfaces that Meissa
provides for user interaction
"""
import os
import sys
import yaml
import asyncio
from pathlib import Path
import click
from meissa import utils, server
DEFAULT_MODEL = (
"https://coqui.gateway.scarf.sh/english/coqui/v1.0.0-huge-vocab/model.tflite"
)
DEFAULT_SCORER = "https://coqui.gateway.scarf.sh/english/coqui/v1.0.0-huge-vocab/huge-vocabulary.scorer"
@click.group("CLI")
@click.pass_context
def cli(ctx):
pass
@cli.command(help="Seutp the environment")
@click.pass_context
def setup(ctx):
config = utils.config(ctx)
home = utils.home(ctx)
model = config.get("model", DEFAULT_MODEL)
scorer = config.get("scorer", DEFAULT_SCORER)
# TODO: Add support for multiple profiles
utils.info(f"Downloading the model: {model}")
utils.download(model, home, "model")
utils.info(f"Downloading the scorer: {scorer}")
utils.download(scorer, home, "scorer")
@cli.command(help="Starts the Meissa server")
@click.pass_context
def start(ctx):
asyncio.run(server.start(ctx))
def main():
"""
The main entry point for Faraday
"""
user_home = os.environ.get("HOME")
meissa_home = Path(user_home) / ".meissa"
meissa_home.mkdir(exist_ok=True)
config_path = meissa_home / "config.yml"
config = {}
if config_path.exists():
with open(config_path, "r") as stream:
config = yaml.safe_load(stream)
cli(
obj={
"home": meissa_home,
"config": config,
}
)
# pylint: skip-file