drewThomasson commited on
Commit
df68428
β€’
1 Parent(s): c566bad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -80
app.py CHANGED
@@ -22,74 +22,13 @@ nltk.download('punkt_tab')
22
 
23
  #nltk.download('punkt') # Make sure to download the necessary models
24
 
 
 
 
25
  import wave
26
  import time
27
  from piper import PiperVoice
28
 
29
- import gradio as gr
30
- from gradio_log import Log
31
- import logging
32
- from pathlib import Path
33
- import threading
34
-
35
- log_file = "log_file.txt"
36
-
37
- def setup_logging(log_file="log_file.txt"):
38
- """
39
- Set up root-level logging to capture all logs from the app, including third-party libraries.
40
- """
41
- # Define a custom formatter
42
- class CustomFormatter(logging.Formatter):
43
- green = "\x1b[32;20m"
44
- blue = "\x1b[34;20m"
45
- yellow = "\x1b[33;20m"
46
- red = "\x1b[31;20m"
47
- bold_red = "\x1b[31;1m"
48
- reset = "\x1b[0m"
49
- format = "%(asctime)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)"
50
-
51
- FORMATS = {
52
- logging.DEBUG: blue + format + reset,
53
- logging.INFO: green + format + reset,
54
- logging.WARNING: yellow + format + reset,
55
- logging.ERROR: red + format + reset,
56
- logging.CRITICAL: bold_red + format + reset,
57
- }
58
-
59
- def format(self, record):
60
- log_fmt = self.FORMATS.get(record.levelno)
61
- formatter = logging.Formatter(log_fmt)
62
- return formatter.format(record)
63
-
64
- # Ensure the log file exists
65
- Path(log_file).touch()
66
-
67
- # Set up the root logger to log everything
68
- root_logger = logging.getLogger()
69
- root_logger.setLevel(logging.DEBUG) # Set to DEBUG to capture all logs
70
-
71
- # Create a file handler to write to the log file
72
- file_handler = logging.FileHandler(log_file)
73
- file_handler.setLevel(logging.DEBUG)
74
- file_handler.setFormatter(CustomFormatter())
75
-
76
- # Create a console handler to log to the terminal (optional)
77
- console_handler = logging.StreamHandler()
78
- console_handler.setLevel(logging.DEBUG)
79
- console_handler.setFormatter(CustomFormatter())
80
-
81
- # Remove any existing handlers to prevent duplicate logs
82
- root_logger.handlers = []
83
-
84
- # Add both handlers
85
- root_logger.addHandler(file_handler)
86
- root_logger.addHandler(console_handler)
87
-
88
- logging.info("Logging system initialized.")
89
-
90
- return root_logger
91
-
92
-
93
  def load_piper_tts(folder_name):
94
  model_file = os.path.join(folder_name, f"{folder_name}.onnx")
95
  config_file = os.path.join(folder_name, f"{folder_name}.json")
@@ -680,21 +619,6 @@ with open("voices.json", "r") as f:
680
  # Base URL for downloading model files
681
  BASE_URL = "https://huggingface.co/rhasspy/piper-voices/resolve/main/"
682
 
683
- logger = setup_logging()
684
-
685
- # Function to continuously log messages in a separate thread
686
- def continuous_logging():
687
- while True:
688
- logger.info("Background log entry.")
689
- logger.warning("Background warning entry.")
690
- time.sleep(3) # Log something every 3 seconds
691
-
692
- # Start the logging in a separate thread
693
- log_thread = threading.Thread(target=continuous_logging, daemon=True)
694
- log_thread.start()
695
-
696
-
697
-
698
  # Function to download selected voice files if missing
699
  def download_voice(voice_key):
700
  voice_info = voices_data[voice_key]
@@ -811,6 +735,5 @@ with gr.Blocks(theme=theme) as demo:
811
 
812
  voice_selector.change(get_voice_details, voice_selector, voice_details)
813
  download_voice_btn.click(download_voice, voice_selector, None)
814
- Log(log_file, dark=True, xterm_font_size=12)
815
 
816
  demo.launch(share=True)
 
22
 
23
  #nltk.download('punkt') # Make sure to download the necessary models
24
 
25
+
26
+
27
+ import os
28
  import wave
29
  import time
30
  from piper import PiperVoice
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  def load_piper_tts(folder_name):
33
  model_file = os.path.join(folder_name, f"{folder_name}.onnx")
34
  config_file = os.path.join(folder_name, f"{folder_name}.json")
 
619
  # Base URL for downloading model files
620
  BASE_URL = "https://huggingface.co/rhasspy/piper-voices/resolve/main/"
621
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
622
  # Function to download selected voice files if missing
623
  def download_voice(voice_key):
624
  voice_info = voices_data[voice_key]
 
735
 
736
  voice_selector.change(get_voice_details, voice_selector, voice_details)
737
  download_voice_btn.click(download_voice, voice_selector, None)
 
738
 
739
  demo.launch(share=True)