Spaces:
Build error
Build error
Commit ·
3b3c852
1
Parent(s): f790556
added debugging features
Browse files123453 unmodified lines91011121314151617181920213 unmodified lines2526272829303132333435363738394041424344454652 unmodified lines991001011021031041051065 unmodified lines1121131141151161171181191201211221239 unmodified lines1331341351091101111361131371381391401411421433 unmodified lines14714814915015115215352 unmodified lines20620720820921021121221321421 unmodified lines236237238239240241242243244245246247from copy import deepcopyfrom langchain.callbacks import StreamlitCallbackHandlerimport streamlit as stimport pandas as pdfrom io import StringIO3 unmodified linesfrom weaviate.embedded import EmbeddedOptionsfrom weaviate import Clientfrom weaviate.util import generate_uuid5import logging
class StreamlitCallbackHandler(logging.Handler): def emit(self, record): log_entry = self.format(record) st.write(log_entry) # Initialize TAPAS model and tokenizertokenizer = AutoTokenizer.from_pretrained("google/tapas-large-finetuned-wtq")model = AutoModelForTableQuestionAnswering.from_pretrained("google/tapas-large-finetuned-wtq")3 unmodified lines embedded_options=EmbeddedOptions())
# Global list to store debugging informationDEBUG_LOGS = []
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)
# Function to check if a class already exists in Weaviatedef class_exists(class_name): try:52 unmodified lines } client.data_object.create(obj)
# Log data ingestion log_debug_info(f"Data ingested into Weaviate for class: {class_name}")
def query_weaviate(question): # This is a basic example; adapt the query based on the question5 unmodified lines try: inputs = tokenizer(table=chunk, queries=questions, padding="max_length", truncation=True, return_tensors="pt") except Exception as e: log_debug_info(f"Tokenization error: {e}") st.write(f"An error occurred: {e}") return ["Error occurred while tokenizing"] * len(questions)
if inputs["input_ids"].shape[1] > 512: log_debug_info("Token limit exceeded for chunk") st.warning("Token limit exceeded for chunk") return ["Token limit exceeded for chunk"] * len(questions)
9 unmodified lines if len(coordinates) == 1: row, col = coordinates[0] try: st.write(f"DataFrame shape: {chunk.shape}") # Debugging line st.write(f"DataFrame columns: {chunk.columns}") # Debugging line st.write(f"Trying to access row {row}, col {col}") # Debugging line value = chunk.iloc[row, col] st.write(f"Value accessed: {value}") # Debugging line log_debug_info(f"Accessed value for row {row}, col {col}: {value}") answers.append(value) except Exception as e: log_debug_info(f"Error accessing value for row {row}, col {col}: {e}") st.write(f"An error occurred: {e}") else: cell_values = []3 unmodified lines value = chunk.iloc[row, col] cell_values.append(value) except Exception as e: log_debug_info(f"Error accessing value for row {row}, col {col}: {e}") st.write(f"An error occurred: {e}") answers.append(", ".join(map(str, cell_values)))
52 unmodified linesif csv_file is not None: data = csv_file.read().decode("utf-8") dataframe = pd.read_csv(StringIO(data))
# Log CSV upload information log_debug_info(f"CSV uploaded with shape: {dataframe.shape}") # Display the uploaded CSV data st.write("Uploaded CSV Data:")21 unmodified lines st.write(f"Question: {q}") st.write(f"Answer: {a}")
# Display debugging informationif st.checkbox("Show Debugging Information"): st.write("Debugging Logs:") for log in DEBUG_LOGS: st.write(log) # Add Ctrl+Enter functionality for submitting the questionsst.markdown(""" <script>app.py+39-4