Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,758 Bytes
52b4ed7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
"""Logging configuration and custom handlers"""
import logging
import threading
from transformers import logging as hf_logging
# Set logging to INFO level for cleaner output
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
# Custom logger handler to capture agentic thoughts
class ThoughtCaptureHandler(logging.Handler):
"""Custom handler to capture internal thoughts from MedSwin and supervisor"""
def __init__(self):
super().__init__()
self.thoughts = []
self.lock = threading.Lock()
def emit(self, record):
"""Capture log messages that contain agentic thoughts"""
try:
msg = self.format(record)
# Only capture messages from GEMINI SUPERVISOR or MEDSWIN
if "[GEMINI SUPERVISOR]" in msg or "[MEDSWIN]" in msg or "[MAC]" in msg:
# Remove timestamp and logger name for cleaner display
parts = msg.split(" - ", 3)
if len(parts) >= 4:
clean_msg = parts[-1]
else:
clean_msg = msg
with self.lock:
self.thoughts.append(clean_msg)
except Exception:
pass
def get_thoughts(self):
"""Get all captured thoughts as a formatted string"""
with self.lock:
return "\n".join(self.thoughts)
def clear(self):
"""Clear captured thoughts"""
with self.lock:
self.thoughts = []
# Set MCP client logging to WARNING to reduce noise
mcp_client_logger = logging.getLogger("mcp.client")
mcp_client_logger.setLevel(logging.WARNING)
hf_logging.set_verbosity_error()
|