jskinner215's picture
Update app.py
99b5e21
raw
history blame contribute delete
No virus
2.17 kB
import sys
sys.path.append('.')
from copy import deepcopy
from langchain.callbacks import StreamlitCallbackHandler
import streamlit as st
import logging
import ui_utils
import weaviate_utils
import tapas_utils
from weaviate_utils import *
from tapas_utils import *
from ui_utils import *
# Initialize Weaviate client
client = initialize_weaviate_client()
# Initialize TAPAS
tokenizer, model = initialize_tapas()
# Global list to store debugging information
DEBUG_LOGS = []
class StreamlitCallbackHandler(logging.Handler):
def emit(self, record):
log_entry = self.format(record)
st.write(log_entry)
def log_debug_info(message):
if st.session_state.debug:
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
# Check if StreamlitCallbackHandler is already added to avoid duplicate logs
if not any(isinstance(handler, StreamlitCallbackHandler) for handler in logger.handlers):
handler = StreamlitCallbackHandler()
logger.addHandler(handler)
logger.debug(message)
# UI components
ui_utils.display_initial_buttons()
selected_class = ui_utils.display_class_dropdown(client)
ui_utils.handle_new_class_selection(client, selected_class)
ui_utils.csv_upload_and_ingestion(client, selected_class)
ui_utils.display_query_input(client, selected_class, tokenizer, model) # Updated this line
# Initialize session state attributes
if "debug" not in st.session_state:
st.session_state.debug = False
st.title("TAPAS Table Question Answering with Weaviate")
# Display debugging information
if st.checkbox("Show Debugging Information"):
st.write("Debugging Logs:")
for log in DEBUG_LOGS:
st.write(log)
# Add Ctrl+Enter functionality for submitting the questions
st.markdown("""
<script>
document.addEventListener("DOMContentLoaded", function(event) {
document.addEventListener("keydown", function(event) {
if (event.ctrlKey && event.key === "Enter") {
document.querySelector(".stButton button").click();
}
});
});
</script>
""", unsafe_allow_html=True)