Update app.py
Browse files
app.py
CHANGED
@@ -24,6 +24,26 @@ import plotly.express as px
|
|
24 |
import pydeck as pdk
|
25 |
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
import time
|
28 |
from transformers import load_tool, Agent
|
29 |
import torch
|
@@ -292,6 +312,36 @@ with tabs[3]:
|
|
292 |
- Ensure proper configuration, such as setting the Hugging Face token as an environment variable.
|
293 |
|
294 |
''')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
|
296 |
# Chat code (user input, agent responses, etc.)
|
297 |
if "messages" not in st.session_state:
|
|
|
24 |
import pydeck as pdk
|
25 |
|
26 |
|
27 |
+
import logging
|
28 |
+
import streamlit as st
|
29 |
+
from transformers import load_tool, Agent
|
30 |
+
|
31 |
+
# Configure the logging settings for transformers
|
32 |
+
transformers_logger = logging.getLogger("transformers.file_utils")
|
33 |
+
transformers_logger.setLevel(logging.INFO) # Set the desired logging level
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
import time
|
48 |
from transformers import load_tool, Agent
|
49 |
import torch
|
|
|
312 |
- Ensure proper configuration, such as setting the Hugging Face token as an environment variable.
|
313 |
|
314 |
''')
|
315 |
+
|
316 |
+
|
317 |
+
# Display logs in the frontend
|
318 |
+
logs_expander = st.expander("Logs")
|
319 |
+
with logs_expander:
|
320 |
+
log_output = st.empty()
|
321 |
+
|
322 |
+
# Custom logging handler to append log messages to the chat
|
323 |
+
class ChatHandler(logging.Handler):
|
324 |
+
def __init__(self):
|
325 |
+
super().__init__()
|
326 |
+
|
327 |
+
def emit(self, record):
|
328 |
+
log_message = self.format(record)
|
329 |
+
with st.chat_message("ai"):
|
330 |
+
st.markdown(f"Log: {log_message}")
|
331 |
+
|
332 |
+
# Add the custom handler to the transformers_logger
|
333 |
+
chat_handler = ChatHandler()
|
334 |
+
transformers_logger.addHandler(chat_handler)
|
335 |
+
|
336 |
+
# Function to update logs in the frontend
|
337 |
+
def update_logs():
|
338 |
+
log_output.code("") # Clear previous logs
|
339 |
+
# Do nothing here since logs are appended to the chat
|
340 |
+
|
341 |
+
# Update logs when the button is clicked
|
342 |
+
if st.button("Update Logs"):
|
343 |
+
update_logs()
|
344 |
+
|
345 |
|
346 |
# Chat code (user input, agent responses, etc.)
|
347 |
if "messages" not in st.session_state:
|