Add error logging

This commit is contained in:
BenAAndrew
2021-03-22 19:34:45 +00:00
parent 0a50841acd
commit 81dcf2bd91
4 changed files with 30 additions and 7 deletions

View File

@@ -14,7 +14,7 @@
<p class="error">
<b>Type</b>: {{ error.type }}<br>
<b>Text</b>: {{ error.text }}<br>
<b>Full</b>: {{ error.full }}
<b>Full</b>: {{ error.stacktrace }}
</p>
<a href="/" class="back">Go To Homepage</a>
</div>

View File

@@ -2,12 +2,16 @@ import logging
from threading import Thread
import os
from datetime import datetime
import requests
from main import socketio
from dataset.clip_generator import clip_generator, extend_dataset
from dataset.forced_alignment.align import align
LOGGING_URL = "https://voice-cloning-app-logging.herokuapp.com/"
class SocketIOHandler(logging.Handler):
def emit(self, record):
text = record.getMessage()
@@ -40,15 +44,24 @@ def extend_existing_dataset(text_path, audio_path, forced_alignment_path, output
extend_dataset(audio_path, forced_alignment_path, output_path, label_path, prefix, logging=logging)
def send_error_log(error):
try:
response = requests.post(LOGGING_URL, data=error)
if response.status_code != 201:
print("error logging recieved invalid response")
except:
print("error logging failed")
def background_task(func, **kwargs):
exception = False
try:
socketio.sleep(5)
func(logging=logger, **kwargs)
except Exception as e:
socketio.emit(
"error", {"type": e.__class__.__name__, "text": str(e), "full": traceback.format_exc()}, namespace="/voice"
)
error = {"type": e.__class__.__name__, "text": str(e), "stacktrace": traceback.format_exc()}
send_error_log(error)
socketio.emit("error", error, namespace="/voice")
exception = True
print(e)

View File

@@ -10,7 +10,14 @@ import torch
sys.path.append("synthesis/waveglow/")
from main import app, paths
from application.utils import start_progress_thread, get_next_url, create_dataset, extend_existing_dataset, get_prefix
from application.utils import (
start_progress_thread,
get_next_url,
create_dataset,
extend_existing_dataset,
get_prefix,
send_error_log,
)
from dataset.analysis import get_total_audio_duration
from training.train import train
from training.checkpoint import get_latest_checkpoint
@@ -37,7 +44,8 @@ inflect_engine = inflect.engine()
@app.errorhandler(Exception)
def handle_bad_request(e):
error = {"type": e.__class__.__name__, "text": str(e), "full": traceback.format_exc()}
error = {"type": e.__class__.__name__, "text": str(e), "stacktrace": traceback.format_exc()}
send_error_log(error)
return render_template("error.html", error=error)
@@ -61,7 +69,7 @@ def get_page(endpoint):
if endpoint == "synthesis" and not model:
return redirect("/synthesis-setup")
return render_template(f"{endpoint}.html")
return ender_template(f"{endpoint}.html")
@app.route("/", methods=["POST"])

View File

@@ -4,12 +4,14 @@ import argparse
TARGET_SAMPLE_RATE = 22050
TARGET_BITRATE = "32k"
def compress_audio(input_path, output_path):
command = (
f"ffmpeg -i {input_path} -acodec libmp3lame -b:a {TARGET_BITRATE} -ac 1 -ar {TARGET_SAMPLE_RATE} {output_path}"
)
call(command.split(" "))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input_path", type=str, help="input audio path")