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
|
@@ -12,43 +12,43 @@ def ask_llm_chunk(chunk, questions):
|
|
| 12 |
chunk = chunk.astype(str)
|
| 13 |
try:
|
| 14 |
inputs = tokenizer(table=chunk, queries=questions, padding="max_length", truncation=True, return_tensors="pt")
|
| 15 |
-
st.write(f"Token shape: {inputs['input_ids'].shape[1]}") # Debugging line
|
| 16 |
-
|
| 17 |
-
# Check for token limit
|
| 18 |
-
if inputs["input_ids"].shape[1] > 512:
|
| 19 |
-
st.warning("Token limit exceeded for chunk")
|
| 20 |
-
return ["Token limit exceeded for chunk"] * len(questions)
|
| 21 |
-
|
| 22 |
-
outputs = model(**inputs)
|
| 23 |
-
predicted_answer_coordinates, predicted_aggregation_indices = tokenizer.convert_logits_to_predictions(
|
| 24 |
-
inputs,
|
| 25 |
-
outputs.logits.detach(),
|
| 26 |
-
outputs.logits_aggregation.detach()
|
| 27 |
-
)
|
| 28 |
-
|
| 29 |
-
answers = []
|
| 30 |
-
for coordinates in predicted_answer_coordinates:
|
| 31 |
-
st.write(f"Type of coordinates[0]: {type(coordinates[0])}") # Debugging line
|
| 32 |
-
st.write(f"Value of coordinates[0]: {coordinates[0]}") # Debugging line
|
| 33 |
-
|
| 34 |
-
st.write(f"DataFrame shape: {chunk.shape}") # Debugging line
|
| 35 |
-
|
| 36 |
-
if len(coordinates) == 1:
|
| 37 |
-
row, col = coordinates[0]
|
| 38 |
-
st.write(f"Trying to access row {row}, col {col}") # Debugging line
|
| 39 |
-
answers.append(chunk.iloc[row, col])
|
| 40 |
-
else:
|
| 41 |
-
cell_values = []
|
| 42 |
-
for coordinate in coordinates:
|
| 43 |
-
row, col = coordinate
|
| 44 |
-
st.write(f"Trying to access row {row}, col {col}") # Debugging line
|
| 45 |
-
cell_values.append(chunk.iloc[row, col])
|
| 46 |
-
answers.append(", ".join(map(str, cell_values)))
|
| 47 |
-
return answers
|
| 48 |
except Exception as e:
|
| 49 |
st.write(f"An error occurred: {e}")
|
| 50 |
return ["Error occurred while tokenizing"] * len(questions)
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
|
|
|
|
| 12 |
chunk = chunk.astype(str)
|
| 13 |
try:
|
| 14 |
inputs = tokenizer(table=chunk, queries=questions, padding="max_length", truncation=True, return_tensors="pt")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
except Exception as e:
|
| 16 |
st.write(f"An error occurred: {e}")
|
| 17 |
return ["Error occurred while tokenizing"] * len(questions)
|
| 18 |
|
| 19 |
+
# Check for token limit
|
| 20 |
+
if inputs["input_ids"].shape[1] > 512:
|
| 21 |
+
st.warning("Token limit exceeded for chunk")
|
| 22 |
+
return ["Token limit exceeded for chunk"] * len(questions)
|
| 23 |
+
|
| 24 |
+
outputs = model(**inputs)
|
| 25 |
+
predicted_answer_coordinates, predicted_aggregation_indices = tokenizer.convert_logits_to_predictions(
|
| 26 |
+
inputs,
|
| 27 |
+
outputs.logits.detach(),
|
| 28 |
+
outputs.logits_aggregation.detach()
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
st.write(f"Testing DataFrame iloc: {chunk.iloc[0, 8]}") # Debugging line
|
| 32 |
+
|
| 33 |
+
answers = []
|
| 34 |
+
for coordinates in predicted_answer_coordinates:
|
| 35 |
+
if len(coordinates) == 1:
|
| 36 |
+
try:
|
| 37 |
+
st.write(f"Trying to access row {coordinates[0][0]}, col {coordinates[0][1]}") # Debugging line
|
| 38 |
+
answers.append(chunk.iloc[coordinates[0]].values)
|
| 39 |
+
except Exception as e:
|
| 40 |
+
st.write(f"An error occurred: {e}")
|
| 41 |
+
else:
|
| 42 |
+
cell_values = []
|
| 43 |
+
for coordinate in coordinates:
|
| 44 |
+
try:
|
| 45 |
+
cell_values.append(chunk.iloc[coordinate].values)
|
| 46 |
+
except Exception as e:
|
| 47 |
+
st.write(f"An error occurred: {e}")
|
| 48 |
+
answers.append(", ".join(cell_values))
|
| 49 |
+
return answers
|
| 50 |
+
|
| 51 |
+
|
| 52 |
|
| 53 |
|
| 54 |
|