emeses commited on
Commit
d15bfd4
·
1 Parent(s): 5df5853

Update space

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -63,10 +63,13 @@ def extract_table(url):
63
  <td>{row['Topic']}</td>
64
  <td>
65
  <button onclick='
66
- const indexInput = document.getElementById("prepare-index");
67
- indexInput.value = "{i}";
68
- indexInput.dispatchEvent(new Event("change"));
69
- document.getElementById("prepare-trigger").click();
 
 
 
70
  '>
71
  Prepare
72
  </button>
@@ -94,29 +97,26 @@ def generate_response(history, system_message):
94
 
95
  def prepare_topic_message(index):
96
  try:
97
- # Debug print
98
- print(f"Received index: '{index}'")
99
 
100
- # Ensure index is not empty and is a valid integer
101
- if not index or index.strip() == '':
102
- print("Empty index received")
 
 
103
  return ""
104
-
105
- index = int(index)
106
- if 0 <= index < len(data):
107
- topic = data[index]["Topic"]
108
- date = data[index]["Date"]
109
  message = f"Please prepare a 10-minute reading guide for the topic '{topic}' scheduled for {date}"
110
  print(f"Generated message: {message}") # Debug print
111
  return message
112
  else:
113
- print(f"Index {index} out of range")
114
  return ""
115
- except ValueError as e:
116
- print(f"Error converting index: {e}")
117
- return ""
118
  except Exception as e:
119
- print(f"Unexpected error in prepare_topic_message: {e}")
120
  return ""
121
 
122
  def clear_chat():
 
63
  <td>{row['Topic']}</td>
64
  <td>
65
  <button onclick='
66
+ (function() {{
67
+ const indexInput = document.getElementById("prepare-index");
68
+ indexInput.value = {i};
69
+ const event = new Event("input", {{ bubbles: true }});
70
+ indexInput.dispatchEvent(event);
71
+ document.getElementById("prepare-trigger").click();
72
+ }})();
73
  '>
74
  Prepare
75
  </button>
 
97
 
98
  def prepare_topic_message(index):
99
  try:
100
+ print(f"Received index: '{index}'") # Debug print
 
101
 
102
+ # Convert index to integer, handling both string and numeric inputs
103
+ try:
104
+ idx = int(float(index))
105
+ except (ValueError, TypeError):
106
+ print(f"Invalid index value: {index}")
107
  return ""
108
+
109
+ if 0 <= idx < len(data):
110
+ topic = data[idx]["Topic"]
111
+ date = data[idx]["Date"]
 
112
  message = f"Please prepare a 10-minute reading guide for the topic '{topic}' scheduled for {date}"
113
  print(f"Generated message: {message}") # Debug print
114
  return message
115
  else:
116
+ print(f"Index {idx} out of range")
117
  return ""
 
 
 
118
  except Exception as e:
119
+ print(f"Error in prepare_topic_message: {e}")
120
  return ""
121
 
122
  def clear_chat():