Spaces:
Build error

jskinner215 commited on
Commit
c1ca766
·
1 Parent(s): 7cd6a5a

more error handling

Browse files

def 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

1 file changed +33 -33
app.py+33-33