File size: 880 Bytes
2257645
4f52ef2
2257645
 
 
 
ae065d3
 
16dfba3
 
 
 
2257645
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import logging #### todo add transformer logs
import streamlit as st
# Configure the logging settings for transformers
transformers_logger = logging.getLogger("transformers.file_utils")
transformers_logger.setLevel(logging.INFO)  # Set the desired logging level

log_enabled = False

def log_response(response):
    if log_enabled:
        with st.chat_message("ai"):
            st.markdown("Agent Response\n {}".format(response))
    print(response)

# Custom logging handler to append log messages to the chat
class ChatHandler(logging.Handler):
    def __init__(self):
        super().__init__()

    def emit(self, record):
        log_message = self.format(record)
        with st.chat_message("ai"):
            st.markdown(f"Log: {log_message}")

# Add the custom handler to the transformers_logger
chat_handler = ChatHandler()
transformers_logger.addHandler(chat_handler)