Spaces:
Build error
Build error
Commit ·
3b3c852
1
Parent(s): f790556
added debugging features
Browse files12343 unmodified lines8910111213143 unmodified lines18192021222352 unmodified lines7677787980815 unmodified lines878889909192939495969 unmodified lines1061071081091101111121131141151161171183 unmodified lines12212312412512612752 unmodified lines18018118218318418521 unmodified lines207208209210211212from copy import deepcopyimport streamlit as stimport pandas as pdfrom io import StringIO3 unmodified linesfrom weaviate.embedded import EmbeddedOptionsfrom weaviate import Clientfrom weaviate.util import generate_uuid5# Initialize TAPAS model and tokenizertokenizer = AutoTokenizer.from_pretrained("google/tapas-large-finetuned-wtq")model = AutoModelForTableQuestionAnswering.from_pretrained("google/tapas-large-finetuned-wtq")3 unmodified linesembedded_options=EmbeddedOptions())# Function to check if a class already exists in Weaviatedef class_exists(class_name):try:52 unmodified lines}client.data_object.create(obj)def query_weaviate(question):# This is a basic example; adapt the query based on the question5 unmodified linestry:inputs = tokenizer(table=chunk, queries=questions, padding="max_length", truncation=True, return_tensors="pt")except Exception as e:st.write(f"An error occurred: {e}")return ["Error occurred while tokenizing"] * len(questions)if inputs["input_ids"].shape[1] > 512:st.warning("Token limit exceeded for chunk")return ["Token limit exceeded for chunk"] * len(questions)9 unmodified linesif len(coordinates) == 1:row, col = coordinates[0]try:st.write(f"DataFrame shape: {chunk.shape}") # Debugging linest.write(f"DataFrame columns: {chunk.columns}") # Debugging linest.write(f"Trying to access row {row}, col {col}") # Debugging linevalue = chunk.iloc[row, col]st.write(f"Value accessed: {value}") # Debugging lineanswers.append(value)except Exception as e:st.write(f"An error occurred: {e}")else:cell_values = []3 unmodified linesvalue = chunk.iloc[row, col]cell_values.append(value)except Exception as 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))# Display the uploaded CSV datast.write("Uploaded CSV Data:")21 unmodified linesst.write(f"Question: {q}")st.write(f"Answer: {a}")# Add Ctrl+Enter functionality for submitting the questionsst.markdown("""<script>123453 unmodified lines91011121314151617181920213 unmodified lines2526272829303132333435363738394041424344454652 unmodified lines991001011021031041051065 unmodified lines1121131141151161171181191201211221239 unmodified lines1331341351361371381391401411421433 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 loggingclass 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 linesembedded_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 logsif 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 ingestionlog_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 linestry: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 linesif len(coordinates) == 1:row, col = coordinates[0]try:value = chunk.iloc[row, col]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 linesvalue = 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 informationlog_debug_info(f"CSV uploaded with shape: {dataframe.shape}")# Display the uploaded CSV datast.write("Uploaded CSV Data:")21 unmodified linesst.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