Merge branch 'error_log' into for_webui
This commit is contained in:
@@ -11,6 +11,7 @@ from models.translation.translation_languages import translation_lang
|
||||
from models.translation.translation_utils import ctranslate2_weights
|
||||
from models.transcription.transcription_languages import transcription_lang
|
||||
from models.transcription.transcription_whisper import _MODELS as whisper_models
|
||||
from utils import errorLogging
|
||||
|
||||
json_serializable_vars = {}
|
||||
def json_serializable(var_name):
|
||||
@@ -1082,9 +1083,7 @@ class Config:
|
||||
try:
|
||||
setattr(self, key, value)
|
||||
except Exception:
|
||||
import traceback
|
||||
with open('error.log', 'a') as f:
|
||||
traceback.print_exc(file=f)
|
||||
errorLogging()
|
||||
|
||||
with open(self.PATH_CONFIG, 'w', encoding="utf-8") as fp:
|
||||
for var_name, var_func in json_serializable_vars.items():
|
||||
|
||||
@@ -5,7 +5,7 @@ import comtypes
|
||||
from pyaudiowpatch import PyAudio, paWASAPI
|
||||
from pycaw.callbacks import MMNotificationClient
|
||||
from pycaw.utils import AudioUtilities
|
||||
from utils import printLog
|
||||
from utils import errorLogging
|
||||
|
||||
class Client(MMNotificationClient):
|
||||
def __init__(self):
|
||||
@@ -187,12 +187,12 @@ class DeviceManager:
|
||||
sleep(2)
|
||||
self.noticeUpdateDevices()
|
||||
self.runProcessAfterUpdateDevices()
|
||||
except Exception as e:
|
||||
printLog("Device Monitoring: ", e)
|
||||
except Exception:
|
||||
errorLogging()
|
||||
finally:
|
||||
pass
|
||||
except Exception as e:
|
||||
printLog("Device Monitoring End Exception: ", e)
|
||||
except Exception:
|
||||
errorLogging()
|
||||
|
||||
def startMonitoring(self):
|
||||
self.monitoring_flag = True
|
||||
|
||||
@@ -30,6 +30,7 @@ from models.transcription.transcription_whisper import checkWhisperWeight, downl
|
||||
from models.overlay.overlay import Overlay
|
||||
from models.overlay.overlay_image import OverlayImage
|
||||
from models.watchdog.watchdog import Watchdog
|
||||
from utils import errorLogging
|
||||
|
||||
class threadFnc(Thread):
|
||||
def __init__(self, fnc, end_fnc=None, daemon=True, *args, **kwargs):
|
||||
@@ -329,9 +330,7 @@ class Model:
|
||||
if new_version > current_version:
|
||||
update_flag = True
|
||||
except Exception:
|
||||
import traceback
|
||||
with open('error.log', 'a') as f:
|
||||
traceback.print_exc(file=f)
|
||||
errorLogging()
|
||||
return update_flag
|
||||
|
||||
@staticmethod
|
||||
@@ -350,9 +349,7 @@ class Model:
|
||||
file.write(chunk)
|
||||
break
|
||||
except Exception:
|
||||
import traceback
|
||||
with open('error.log', 'a') as f:
|
||||
traceback.print_exc(file=f)
|
||||
errorLogging()
|
||||
# run updater
|
||||
Popen(program_name, cwd=current_directory)
|
||||
|
||||
@@ -372,9 +369,7 @@ class Model:
|
||||
file.write(chunk)
|
||||
break
|
||||
except Exception:
|
||||
import traceback
|
||||
with open('error.log', 'a') as f:
|
||||
traceback.print_exc(file=f)
|
||||
errorLogging()
|
||||
# run updater
|
||||
Popen([program_name, "--cuda"], cwd=current_directory)
|
||||
|
||||
@@ -445,7 +440,7 @@ class Model:
|
||||
message = self.mic_transcriber.getTranscript()
|
||||
fnc(message)
|
||||
except Exception:
|
||||
pass
|
||||
errorLogging()
|
||||
|
||||
def endMicTranscript():
|
||||
while not self.mic_audio_queue.empty():
|
||||
@@ -541,7 +536,7 @@ class Model:
|
||||
try:
|
||||
self.check_mic_energy_fnc(energy)
|
||||
except Exception:
|
||||
pass
|
||||
errorLogging()
|
||||
sleep(0.01)
|
||||
|
||||
mic_energy_queue = Queue()
|
||||
@@ -609,7 +604,7 @@ class Model:
|
||||
message = self.speaker_transcriber.getTranscript()
|
||||
fnc(message)
|
||||
except Exception:
|
||||
pass
|
||||
errorLogging()
|
||||
|
||||
def endSpeakerTranscript():
|
||||
speaker_audio_queue.queue.clear()
|
||||
@@ -663,7 +658,7 @@ class Model:
|
||||
try:
|
||||
self.check_speaker_energy_fnc(energy)
|
||||
except Exception:
|
||||
pass
|
||||
errorLogging()
|
||||
sleep(0.01)
|
||||
|
||||
speaker_energy_queue = Queue()
|
||||
|
||||
@@ -7,6 +7,7 @@ from tinyoscquery.queryservice import OSCQueryService
|
||||
from tinyoscquery.query import OSCQueryBrowser, OSCQueryClient
|
||||
from tinyoscquery.utility import get_open_udp_port, get_open_tcp_port
|
||||
from tinyoscquery.shared.node import OSCAccess
|
||||
from utils import errorLogging
|
||||
|
||||
class OSCHandler:
|
||||
def __init__(self, ip_address="127.0.0.1", port=9000) -> None:
|
||||
@@ -55,7 +56,7 @@ class OSCHandler:
|
||||
browser.browser.cancel()
|
||||
|
||||
except Exception:
|
||||
pass
|
||||
errorLogging()
|
||||
return value
|
||||
|
||||
def getOSCParameterMuteSelf(self) -> bool:
|
||||
@@ -77,6 +78,7 @@ class OSCHandler:
|
||||
self.osc_query_service.advertise_endpoint(filter, access=OSCAccess.READWRITE_VALUE)
|
||||
break
|
||||
except Exception:
|
||||
errorLogging()
|
||||
sleep(1)
|
||||
|
||||
def oscServerServe(self) -> None:
|
||||
|
||||
@@ -10,11 +10,7 @@ try:
|
||||
from . import overlay_utils as utils
|
||||
except ImportError:
|
||||
import overlay_utils as utils
|
||||
try:
|
||||
from utils import printLog
|
||||
except ImportError:
|
||||
def printLog(*args):
|
||||
print(*args)
|
||||
from utils import errorLogging
|
||||
|
||||
def mat34Id(array):
|
||||
arr = openvr.HmdMatrix34_t()
|
||||
@@ -114,8 +110,8 @@ class Overlay:
|
||||
self.updateFadeoutDuration(self.settings[size]["fadeout_duration"], size)
|
||||
self.init_process = False
|
||||
|
||||
except Exception as e:
|
||||
printLog("error:Could not initialise OpenVR", e)
|
||||
except Exception:
|
||||
errorLogging()
|
||||
|
||||
def updateImage(self, img, size):
|
||||
if self.initialized is True:
|
||||
@@ -125,8 +121,8 @@ class Overlay:
|
||||
|
||||
try:
|
||||
self.overlay.setOverlayRaw(self.handle[size], img, width, height, 4)
|
||||
except Exception as e:
|
||||
printLog("error:Could not update image", e)
|
||||
except Exception:
|
||||
errorLogging()
|
||||
self.initialized = False
|
||||
self.reStartOverlay()
|
||||
while self.initialized is False:
|
||||
@@ -217,8 +213,8 @@ class Overlay:
|
||||
if new_event.eventType == openvr.VREvent_Quit:
|
||||
return False
|
||||
return True
|
||||
except Exception as e:
|
||||
printLog("error:Could not check SteamVR running", e)
|
||||
except Exception:
|
||||
errorLogging()
|
||||
return False
|
||||
|
||||
def evaluateOpacityFade(self, size):
|
||||
@@ -344,9 +340,11 @@ if __name__ == "__main__":
|
||||
overlay.updateImage(img, "small")
|
||||
time.sleep(15)
|
||||
except openvr.error_code.OverlayError_InvalidParameter as e:
|
||||
errorLogging()
|
||||
logging.error(f"OverlayError_InvalidParameter: {e}")
|
||||
break
|
||||
except Exception as e:
|
||||
errorLogging()
|
||||
logging.error(f"Unexpected error: {e}")
|
||||
break
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ from os import path as os_path
|
||||
from datetime import datetime
|
||||
from typing import Tuple
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from utils import errorLogging
|
||||
|
||||
class OverlayImage:
|
||||
LANGUAGES = {
|
||||
@@ -56,6 +57,7 @@ class OverlayImage:
|
||||
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf")
|
||||
font = ImageFont.truetype(font_path, font_size)
|
||||
except Exception:
|
||||
errorLogging()
|
||||
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf")
|
||||
font = ImageFont.truetype(font_path, font_size)
|
||||
|
||||
@@ -133,6 +135,7 @@ class OverlayImage:
|
||||
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf")
|
||||
font = ImageFont.truetype(font_path, font_size)
|
||||
except Exception:
|
||||
errorLogging()
|
||||
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf")
|
||||
font = ImageFont.truetype(font_path, font_size)
|
||||
|
||||
@@ -167,6 +170,7 @@ class OverlayImage:
|
||||
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", "NotoSansJP-Regular.ttf")
|
||||
font = ImageFont.truetype(font_path, font_size)
|
||||
except Exception:
|
||||
errorLogging()
|
||||
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", "NotoSansJP-Regular.ttf")
|
||||
font = ImageFont.truetype(font_path, font_size)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ from io import BytesIO
|
||||
from threading import Event
|
||||
import wave
|
||||
from speech_recognition import Recognizer, AudioData, AudioFile
|
||||
from speech_recognition.exceptions import UnknownValueError
|
||||
from datetime import timedelta
|
||||
from pyaudiowpatch import get_sample_size, paInt16
|
||||
from .transcription_languages import transcription_lang
|
||||
@@ -11,6 +12,8 @@ from .transcription_whisper import getWhisperModel, checkWhisperWeight
|
||||
import torch
|
||||
import numpy as np
|
||||
from pydub import AudioSegment
|
||||
from utils import errorLogging
|
||||
|
||||
import warnings
|
||||
warnings.simplefilter('ignore', RuntimeWarning)
|
||||
|
||||
@@ -74,9 +77,10 @@ class AudioTranscriber:
|
||||
if s.avg_logprob < avg_logprob or s.no_speech_prob > no_speech_prob:
|
||||
continue
|
||||
text += s.text
|
||||
|
||||
except Exception:
|
||||
except UnknownValueError:
|
||||
pass
|
||||
except Exception:
|
||||
errorLogging()
|
||||
finally:
|
||||
pass
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ from typing import Callable
|
||||
import huggingface_hub
|
||||
from faster_whisper import WhisperModel
|
||||
import logging
|
||||
from utils import printLog
|
||||
|
||||
logger = logging.getLogger('faster_whisper')
|
||||
logger.setLevel(logging.CRITICAL)
|
||||
@@ -40,10 +39,8 @@ def downloadFile(url, path, func=None):
|
||||
if isinstance(func, Callable):
|
||||
total_chunk += len(chunk)
|
||||
func(total_chunk/file_size)
|
||||
printLog(f"Downloading Whisper Model: {total_chunk/file_size:.0%}")
|
||||
|
||||
except Exception as e:
|
||||
printLog("warning:downloadFile()", e)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def checkWhisperWeight(root, weight_type):
|
||||
path = os_path.join(root, "weights", "whisper", weight_type)
|
||||
|
||||
@@ -6,7 +6,7 @@ from .translation_utils import ctranslate2_weights
|
||||
|
||||
import ctranslate2
|
||||
import transformers
|
||||
from utils import printLog
|
||||
from utils import errorLogging
|
||||
|
||||
import warnings
|
||||
warnings.filterwarnings("ignore")
|
||||
@@ -25,6 +25,7 @@ class Translator():
|
||||
self.deepl_client = deepl_Translator(authkey)
|
||||
self.deepl_client.translate_text(" ", target_lang="EN-US")
|
||||
except Exception:
|
||||
errorLogging()
|
||||
self.deepl_client = None
|
||||
result = False
|
||||
return result
|
||||
@@ -47,8 +48,8 @@ class Translator():
|
||||
)
|
||||
try:
|
||||
self.ctranslate2_tokenizer = transformers.AutoTokenizer.from_pretrained(tokenizer, cache_dir=tokenizer_path)
|
||||
except Exception as e:
|
||||
printLog("error:changeCTranslate2Model()", e)
|
||||
except Exception:
|
||||
errorLogging()
|
||||
tokenizer_path = os_path.join("./weights", "ctranslate2", directory_name, "tokenizer")
|
||||
self.ctranslate2_tokenizer = transformers.AutoTokenizer.from_pretrained(tokenizer, cache_dir=tokenizer_path)
|
||||
self.is_loaded_ctranslate2_model = True
|
||||
@@ -67,7 +68,7 @@ class Translator():
|
||||
target = results[0].hypotheses[0][1:]
|
||||
result = self.ctranslate2_tokenizer.decode(self.ctranslate2_tokenizer.convert_tokens_to_ids(target))
|
||||
except Exception:
|
||||
pass
|
||||
errorLogging()
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
@@ -139,8 +140,6 @@ class Translator():
|
||||
target_language=target_language,
|
||||
)
|
||||
except Exception:
|
||||
import traceback
|
||||
with open('error.log', 'a') as f:
|
||||
traceback.print_exc(file=f)
|
||||
errorLogging()
|
||||
result = False
|
||||
return result
|
||||
@@ -5,7 +5,7 @@ from os import makedirs as os_makedirs
|
||||
from requests import get as requests_get
|
||||
from typing import Callable
|
||||
import hashlib
|
||||
from utils import printLog
|
||||
from utils import errorLogging
|
||||
|
||||
ctranslate2_weights = {
|
||||
"small": { # M2M-100 418M-parameter model
|
||||
@@ -79,12 +79,11 @@ def downloadCTranslate2Weight(root, weight_type="small", callback=None, end_call
|
||||
if isinstance(callback, Callable):
|
||||
total_chunk += len(chunk)
|
||||
callback(total_chunk/file_size)
|
||||
printLog(f"Downloading CTranslate Model: {total_chunk/file_size:.0%}")
|
||||
|
||||
with ZipFile(os_path.join(tmp_path, filename)) as zf:
|
||||
zf.extractall(path)
|
||||
except Exception as e:
|
||||
printLog("warning:downloadCTranslate2Weight()", e)
|
||||
except Exception:
|
||||
errorLogging()
|
||||
|
||||
if isinstance(end_callback, Callable):
|
||||
end_callback()
|
||||
@@ -1,6 +1,5 @@
|
||||
from typing import Callable
|
||||
import time
|
||||
from utils import printLog
|
||||
|
||||
class Watchdog:
|
||||
def __init__(self, timeout:int=60, interval:int=20):
|
||||
@@ -16,7 +15,6 @@ class Watchdog:
|
||||
|
||||
def start(self):
|
||||
if time.time() - self.last_feed_time > self.timeout:
|
||||
printLog("Watchdog timeout! Shutting down...")
|
||||
if isinstance(self.callback, Callable):
|
||||
self.callback()
|
||||
time.sleep(self.interval)
|
||||
@@ -4,6 +4,7 @@ import json
|
||||
import random
|
||||
from typing import Union
|
||||
from os import path as os_path, rename as os_rename
|
||||
import traceback
|
||||
from PIL.Image import open as Image_open
|
||||
|
||||
def getImageFile(file_name):
|
||||
@@ -94,3 +95,7 @@ def printResponse(status:int, endpoint:str, result:Any=None) -> None:
|
||||
|
||||
response = json.dumps(response)
|
||||
print(response, flush=True)
|
||||
|
||||
def errorLogging() -> None:
|
||||
with open('error.log', 'a') as f:
|
||||
traceback.print_exc(file=f)
|
||||
@@ -6,7 +6,7 @@ import re
|
||||
from device_manager import device_manager
|
||||
from config import config
|
||||
from model import model
|
||||
from utils import removeLog, printLog
|
||||
from utils import removeLog, printLog, errorLogging
|
||||
|
||||
class Controller:
|
||||
def __init__(self) -> None:
|
||||
@@ -706,6 +706,7 @@ class Controller:
|
||||
else:
|
||||
raise ValueError()
|
||||
except Exception:
|
||||
errorLogging()
|
||||
response = {
|
||||
"status":400,
|
||||
"result":{
|
||||
@@ -745,6 +746,7 @@ class Controller:
|
||||
else:
|
||||
raise ValueError()
|
||||
except Exception:
|
||||
errorLogging()
|
||||
response = {
|
||||
"status":400,
|
||||
"result":{
|
||||
@@ -769,6 +771,7 @@ class Controller:
|
||||
else:
|
||||
raise ValueError()
|
||||
except Exception:
|
||||
errorLogging()
|
||||
response = {
|
||||
"status":400,
|
||||
"result":{
|
||||
@@ -793,6 +796,7 @@ class Controller:
|
||||
else:
|
||||
raise ValueError()
|
||||
except Exception:
|
||||
errorLogging()
|
||||
response = {
|
||||
"status":400,
|
||||
"result":{
|
||||
@@ -879,6 +883,7 @@ class Controller:
|
||||
else:
|
||||
raise ValueError()
|
||||
except Exception:
|
||||
errorLogging()
|
||||
response = {
|
||||
"status":400,
|
||||
"result":{
|
||||
@@ -917,6 +922,7 @@ class Controller:
|
||||
else:
|
||||
raise ValueError()
|
||||
except Exception:
|
||||
errorLogging()
|
||||
response = {
|
||||
"status":400,
|
||||
"result":{
|
||||
@@ -941,6 +947,7 @@ class Controller:
|
||||
else:
|
||||
raise ValueError()
|
||||
except Exception:
|
||||
errorLogging()
|
||||
response = {
|
||||
"status":400,
|
||||
"result":{
|
||||
@@ -966,6 +973,7 @@ class Controller:
|
||||
else:
|
||||
raise ValueError()
|
||||
except Exception:
|
||||
errorLogging()
|
||||
response = {
|
||||
"status":400,
|
||||
"result":{
|
||||
@@ -1049,6 +1057,7 @@ class Controller:
|
||||
}
|
||||
}
|
||||
except Exception as e:
|
||||
errorLogging()
|
||||
response = {
|
||||
"status":400,
|
||||
"result":{
|
||||
|
||||
@@ -5,7 +5,7 @@ from typing import Any
|
||||
from threading import Thread
|
||||
from queue import Queue
|
||||
from webui_controller import Controller
|
||||
from utils import printLog, printResponse, encodeBase64
|
||||
from utils import printLog, printResponse, errorLogging, encodeBase64
|
||||
|
||||
controller = Controller()
|
||||
|
||||
@@ -334,6 +334,7 @@ class Main:
|
||||
status = response.get("status", None)
|
||||
result = response.get("result", None)
|
||||
except Exception as e:
|
||||
errorLogging()
|
||||
result = str(e)
|
||||
status = 500
|
||||
return result, status
|
||||
@@ -345,9 +346,7 @@ class Main:
|
||||
endpoint, data = self.queue.get()
|
||||
result, status = self.handleRequest(endpoint, data)
|
||||
except Exception as e:
|
||||
import traceback
|
||||
with open('error.log', 'a') as f:
|
||||
traceback.print_exc(file=f)
|
||||
errorLogging()
|
||||
result = str(e)
|
||||
status = 500
|
||||
|
||||
|
||||
Reference in New Issue
Block a user