mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-13 16:53:24 +00:00
Merge pull request #7 from BoardWare-Genius/count_time
feat: logging_time decorator
This commit is contained in:
@ -34,6 +34,11 @@ python main.py
|
||||
## Configuration
|
||||
Create ".env.yaml" at the root of jarvis-models, and copy the following yaml configuration
|
||||
```yaml
|
||||
env:
|
||||
version: 0.0.1
|
||||
host: 0.0.0.0
|
||||
port: 8000
|
||||
|
||||
log:
|
||||
level: debug
|
||||
time_format: "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
@ -7,6 +7,8 @@ from fastapi.responses import JSONResponse
|
||||
from injector import inject
|
||||
from injector import singleton
|
||||
|
||||
from ..log.logging_time import logging_time
|
||||
|
||||
from ..configuration import MeloConf
|
||||
from .blackbox import Blackbox
|
||||
|
||||
@ -14,7 +16,7 @@ import soundfile
|
||||
from melo.api import TTS
|
||||
|
||||
import logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@singleton
|
||||
class MeloTTS(Blackbox):
|
||||
@ -25,8 +27,8 @@ class MeloTTS(Blackbox):
|
||||
language: str
|
||||
speaker: str
|
||||
|
||||
@inject
|
||||
def __init__(self, melo_config: MeloConf) -> None:
|
||||
@logging_time(logger=logger)
|
||||
def model_init(self, melo_config: MeloConf) -> None:
|
||||
self.speed = melo_config.speed
|
||||
self.device = melo_config.device
|
||||
self.language = melo_config.language
|
||||
@ -43,6 +45,10 @@ class MeloTTS(Blackbox):
|
||||
self.url = melo_config.url
|
||||
logging.info('#### Initializing MeloTTS Service in ' + self.device + ' mode...')
|
||||
|
||||
@inject
|
||||
def __init__(self, melo_config: MeloConf) -> None:
|
||||
self.model_init(melo_config)
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self.processing(*args, **kwargs)
|
||||
|
||||
@ -50,6 +56,7 @@ class MeloTTS(Blackbox):
|
||||
text = args[0]
|
||||
return isinstance(text, str)
|
||||
|
||||
@logging_time(logger=logger)
|
||||
def processing(self, *args, **kwargs) -> io.BytesIO | bytes:
|
||||
text = args[0]
|
||||
current_time = time.time()
|
||||
|
||||
@ -81,7 +81,7 @@ class LogConf():
|
||||
time_format = "%Y-%m-%d %H:%M:%S"
|
||||
filename: str | None
|
||||
@inject
|
||||
def __init__(self,config: Configuration) -> None:
|
||||
def __init__(self, config: Configuration) -> None:
|
||||
self.level = config.get("log.level")
|
||||
c = config.get("log.level", default=DEFAULT_LEVEL).upper()
|
||||
level=logging._nameToLevel.get(c)
|
||||
@ -95,7 +95,10 @@ class LogConf():
|
||||
@singleton
|
||||
class EnvConf():
|
||||
version: str
|
||||
|
||||
host: str
|
||||
port: str
|
||||
@inject
|
||||
def __init__(self) -> None:
|
||||
def __init__(self, config: Configuration) -> None:
|
||||
self.version = "0.0.1"
|
||||
self.host = config.get("env.host", default="0.0.0.0")
|
||||
self.port = config.get("env.port", default="8080")
|
||||
15
src/log/logging_time.py
Normal file
15
src/log/logging_time.py
Normal file
@ -0,0 +1,15 @@
|
||||
import time
|
||||
import logging
|
||||
|
||||
def logging_time(logger: logging.Logger=None):
|
||||
if logger is None:
|
||||
logger = logging.getLogger("unknown_logger")
|
||||
def dec(cb):
|
||||
def inner(self, *args, **kwargs):
|
||||
start = time.time()
|
||||
result = cb(self, *args, **kwargs)
|
||||
end = time.time()
|
||||
logger.info(self.__class__.__name__+"."+cb.__name__ + " Time taken: " + str(end - start) + " seconds")
|
||||
return result
|
||||
return inner
|
||||
return dec
|
||||
@ -10,10 +10,7 @@ from scipy.io.wavfile import read
|
||||
import torch
|
||||
|
||||
MATPLOTLIB_FLAG = False
|
||||
|
||||
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
|
||||
logger = logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def load_checkpoint(checkpoint_path, model, optimizer=None):
|
||||
assert os.path.isfile(checkpoint_path)
|
||||
|
||||
Reference in New Issue
Block a user