Spaces:
Build error
more error handling
Browse filesdef ask_llm_chunk(chunk, questions):
chunk = chunk.astype(str)
try:
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)
# Check for token limit
if inputs["input_ids"].shape[1] > 512:
st.warning("Token limit exceeded for chunk")
return ["Token limit exceeded for chunk"] * len(questions)
outputs = model(**inputs)
predicted_answer_coordinates, predicted_aggregation_indices = tokenizer.convert_logits_to_predictions(
inputs,
outputs.logits.detach(),
outputs.logits_aggregation.detach()
)
st.write(f"Testing DataFrame iloc: {chunk.iloc[0, 8]}") # Debugging line
answers = []
for coordinates in predicted_answer_coordinates:
if len(coordinates) == 1:
try:
st.write(f"Trying to access row {coordinates[0][0]}, col {coordinates[0][1]}") # Debugging line
answers.append(chunk.iloc[coordinates[0]].values)
except Exception as e:
st.write(f"An error occurred: {e}")
else:
cell_values = []
for coordinate in coordinates:
try:
cell_values.append(chunk.iloc[coordinate].values)
except Exception as e:
st.write(f"An error occurred: {e}")
answers.append(", ".join(cell_values))
return answers
11 unmodified lines1213141516171819202122232425262728293031323334353637383940414243444546474849505152535411 unmodified lineschunk = chunk.astype(str)try:inputs = tokenizer(table=chunk, queries=questions, padding="max_length", truncation=True, return_tensors="pt")st.write(f"Token shape: {inputs['input_ids'].shape[1]}") # Debugging line# Check for token limitif inputs["input_ids"].shape[1] > 512:st.warning("Token limit exceeded for chunk")return ["Token limit exceeded for chunk"] * len(questions)outputs = model(**inputs)predicted_answer_coordinates, predicted_aggregation_indices = tokenizer.convert_logits_to_predictions(inputs,outputs.logits.detach(),outputs.logits_aggregation.detach())answers = []for coordinates in predicted_answer_coordinates:st.write(f"Type of coordinates[0]: {type(coordinates[0])}") # Debugging linest.write(f"Value of coordinates[0]: {coordinates[0]}") # Debugging linest.write(f"DataFrame shape: {chunk.shape}") # Debugging lineif len(coordinates) == 1:row, col = coordinates[0]st.write(f"Trying to access row {row}, col {col}") # Debugging lineanswers.append(chunk.iloc[row, col])else:cell_values = []for coordinate in coordinates:row, col = coordinatest.write(f"Trying to access row {row}, col {col}") # Debugging linecell_values.append(chunk.iloc[row, col])answers.append(", ".join(map(str, cell_values)))return answersexcept Exception as e:st.write(f"An error occurred: {e}")return ["Error occurred while tokenizing"] * len(questions)11 unmodified lines1213141516171819202122232425262728293031323334353637383940414243444546474849505152535411 unmodified lineschunk = chunk.astype(str)try: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)# Check for token limitif inputs["input_ids"].shape[1] > 512:st.warning("Token limit exceeded for chunk")return ["Token limit exceeded for chunk"] * len(questions)outputs = model(**inputs)predicted_answer_coordinates, predicted_aggregation_indices = tokenizer.convert_logits_to_predictions(inputs,outputs.logits.detach(),outputs.logits_aggregation.detach())st.write(f"Testing DataFrame iloc: {chunk.iloc[0, 8]}") # Debugging lineanswers = []for coordinates in predicted_answer_coordinates:if len(coordinates) == 1:try:st.write(f"Trying to access row {coordinates[0][0]}, col {coordinates[0][1]}") # Debugging lineanswers.append(chunk.iloc[coordinates[0]].values)except Exception as e:st.write(f"An error occurred: {e}")else:cell_values = []for coordinate in coordinates:try:cell_values.append(chunk.iloc[coordinate].values)except Exception as e:st.write(f"An error occurred: {e}")answers.append(", ".join(cell_values))return answers