LPX55
commited on
Commit
·
68f9986
1
Parent(s):
80c3f0c
refactor: extract Gradio logging setup into a separate module
Browse files- app.py +3 -15
- utils/logging_setup.py +18 -0
app.py
CHANGED
@@ -36,22 +36,10 @@ logging.basicConfig(level=logging.INFO)
|
|
36 |
logger = logging.getLogger(__name__)
|
37 |
os.environ['HF_HUB_CACHE'] = './models'
|
38 |
|
39 |
-
# --- Gradio Log Handler ---
|
40 |
-
class GradioLogHandler(logging.Handler):
|
41 |
-
def __init__(self, log_queue):
|
42 |
-
super().__init__()
|
43 |
-
self.log_queue = log_queue
|
44 |
-
self.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
|
45 |
-
|
46 |
-
def emit(self, record):
|
47 |
-
self.log_queue.append(self.format(record))
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
# Set root logger level to DEBUG to capture all messages from agents
|
53 |
-
logging.getLogger().setLevel(logging.INFO)
|
54 |
-
logging.getLogger().addHandler(gradio_handler)
|
55 |
# --- End Gradio Log Handler ---
|
56 |
|
57 |
LOCAL_LOG_DIR = "./hf_inference_logs"
|
|
|
36 |
logger = logging.getLogger(__name__)
|
37 |
os.environ['HF_HUB_CACHE'] = './models'
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
+
# --- Gradio Log Handler ---
|
41 |
+
from utils.logging_setup import setup_gradio_logging
|
42 |
+
log_queue, gradio_handler = setup_gradio_logging()
|
|
|
|
|
|
|
43 |
# --- End Gradio Log Handler ---
|
44 |
|
45 |
LOCAL_LOG_DIR = "./hf_inference_logs"
|
utils/logging_setup.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
+
import collections
|
3 |
+
|
4 |
+
class GradioLogHandler(logging.Handler):
|
5 |
+
def __init__(self, log_queue):
|
6 |
+
super().__init__()
|
7 |
+
self.log_queue = log_queue
|
8 |
+
self.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
|
9 |
+
|
10 |
+
def emit(self, record):
|
11 |
+
self.log_queue.append(self.format(record))
|
12 |
+
|
13 |
+
def setup_gradio_logging():
|
14 |
+
log_queue = collections.deque(maxlen=1000)
|
15 |
+
gradio_handler = GradioLogHandler(log_queue)
|
16 |
+
logging.getLogger().setLevel(logging.INFO)
|
17 |
+
logging.getLogger().addHandler(gradio_handler)
|
18 |
+
return log_queue, gradio_handler
|