jskinner215 commited on
Commit
45ee012
·
1 Parent(s): 66f9f66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import streamlit as st
2
  import pandas as pd
3
  from io import StringIO
@@ -29,34 +31,36 @@ def ask_llm_chunk(chunk, questions):
29
 
30
  answers = []
31
  for coordinates in predicted_answer_coordinates:
32
- for coordinate in coordinates:
33
- row, col = coordinate
34
  try:
 
 
35
  st.write(f"Trying to access row {row}, col {col}") # Debugging line
36
  value = chunk.iloc[row, col]
37
  st.write(f"Value accessed: {value}") # Debugging line
38
- if isinstance(value, pd.Series):
39
- answers.append(value.values)
40
- else:
41
- answers.append(value.item() if hasattr(value, 'item') else value)
42
  except Exception as e:
43
  st.write(f"An error occurred: {e}")
44
- st.write(f"Type of error: {type(e)}")
45
- st.write(f"Arguments of error: {e.args}")
46
- answers.append(", ".join(map(str, [chunk.iloc[coordinate].values for coordinate in coordinates])))
 
 
 
 
 
 
 
47
 
48
  return answers
49
 
50
-
51
-
52
-
53
-
54
  MAX_ROWS_PER_CHUNK = 200
55
 
56
  def summarize_map_reduce(data, questions):
57
  dataframe = pd.read_csv(StringIO(data))
58
  num_chunks = len(dataframe) // MAX_ROWS_PER_CHUNK + 1
59
- dataframe_chunks = np.array_split(dataframe, num_chunks)
60
  all_answers = []
61
  for chunk in dataframe_chunks:
62
  chunk_answers = ask_llm_chunk(chunk, questions)
 
1
+ from copy import deepcopy
2
+
3
  import streamlit as st
4
  import pandas as pd
5
  from io import StringIO
 
31
 
32
  answers = []
33
  for coordinates in predicted_answer_coordinates:
34
+ if len(coordinates) == 1:
35
+ row, col = coordinates[0]
36
  try:
37
+ st.write(f"DataFrame shape: {chunk.shape}") # Debugging line
38
+ st.write(f"DataFrame columns: {chunk.columns}") # Debugging line
39
  st.write(f"Trying to access row {row}, col {col}") # Debugging line
40
  value = chunk.iloc[row, col]
41
  st.write(f"Value accessed: {value}") # Debugging line
42
+ answers.append(value)
 
 
 
43
  except Exception as e:
44
  st.write(f"An error occurred: {e}")
45
+ else:
46
+ cell_values = []
47
+ for coordinate in coordinates:
48
+ row, col = coordinate
49
+ try:
50
+ value = chunk.iloc[row, col]
51
+ cell_values.append(value)
52
+ except Exception as e:
53
+ st.write(f"An error occurred: {e}")
54
+ answers.append(", ".join(map(str, cell_values)))
55
 
56
  return answers
57
 
 
 
 
 
58
  MAX_ROWS_PER_CHUNK = 200
59
 
60
  def summarize_map_reduce(data, questions):
61
  dataframe = pd.read_csv(StringIO(data))
62
  num_chunks = len(dataframe) // MAX_ROWS_PER_CHUNK + 1
63
+ dataframe_chunks = [deepcopy(chunk) for chunk in np.array_split(dataframe, num_chunks)]
64
  all_answers = []
65
  for chunk in dataframe_chunks:
66
  chunk_answers = ask_llm_chunk(chunk, questions)