Spaces:
Build error
Had an error about incorrect type (str) so adding error handling to debug
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")
st.write(f"Token shape: {inputs['input_ids'].shape[1]}") # Debugging line
# 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()
)
answers = []
for coordinates in predicted_answer_coordinates:
st.write(f"Type of coordinates[0]: {type(coordinates[0])}") # Debugging line
st.write(f"Value of coordinates[0]: {coordinates[0]}") # Debugging line
if len(coordinates) == 1:
answers.append(chunk.iloc[coordinates[0]].values)
else:
cell_values = []
for coordinate in coordinates:
cell_values.append(chunk.iloc[coordinate].values)
answers.append(", ".join(cell_values))
return answers
except Exception as e:
st.write(f"An error occurred: {e}")
return ["Error occurred while tokenizing"] * len(questions)
11 unmodified lines1213141516171819202122232425262728293031323334353637383940414211 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())answers = []for coordinates in predicted_answer_coordinates:if len(coordinates) == 1:answers.append(chunk.iloc[coordinates[0]].values)else:cell_values = []for coordinate in coordinates:cell_values.append(chunk.iloc[coordinate].values)answers.append(", ".join(cell_values))return answersMAX_ROWS_PER_CHUNK = 20011 unmodified lines12131415161718192021222324252627282930313233343536373839404142434445464711 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 lineif len(coordinates) == 1:answers.append(chunk.iloc[coordinates[0]].values)else:cell_values = []for coordinate in coordinates:cell_values.append(chunk.iloc[coordinate].values)answers.append(", ".join(cell_values))return answersexcept Exception as e:st.write(f"An error occurred: {e}")return ["Error occurred while tokenizing"] * len(questions)MAX_ROWS_PER_CHUNK = 200