bluenevus commited on
Commit
edd7603
·
verified ·
1 Parent(s): a0d2fac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -14,6 +14,7 @@ import chardet
14
 
15
  # Initialize the Dash app
16
  app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
 
17
 
18
  # Get OpenAI API key from Hugging Face Spaces environment variable
19
  openai.api_key = os.environ.get('OPENAI_API_KEY')
@@ -141,7 +142,7 @@ def update_output(list_of_contents, list_of_names, existing_files):
141
  global uploaded_files
142
  if list_of_contents is not None:
143
  new_files = []
144
- for i, (content, name) in enumerate(zip(list_of_contents, list_of_names)):
145
  file_content = parse_file_content(content, name)
146
  uploaded_files[name] = file_content
147
  new_files.append(dbc.ListGroupItem([
@@ -149,10 +150,9 @@ def update_output(list_of_contents, list_of_names, existing_files):
149
  color="danger", size="sm", className="me-2"),
150
  html.Span(name)
151
  ]))
152
- if existing_files is None:
153
- existing_files = []
154
- return dbc.ListGroup(existing_files + new_files)
155
- return dbc.ListGroup(existing_files) if existing_files else []
156
 
157
  # Update the remove file callback
158
  @app.callback(
@@ -168,9 +168,14 @@ def remove_file(n_clicks, existing_files):
168
  raise PreventUpdate
169
 
170
  triggered_id = ctx.triggered[0]['prop_id']
 
 
171
  removed_file = triggered_id.split('"index":')[1].split('"')[1]
 
172
 
173
  uploaded_files.pop(removed_file, None)
 
 
174
  return [file for file in existing_files if file['props']['children'][1]['children'] != removed_file]
175
 
176
  def generate_matrix_with_gpt(matrix_type, file_contents):
@@ -222,6 +227,7 @@ Now, generate the {matrix_type}:
222
  prevent_initial_call=True
223
  )
224
  def generate_matrix(*args):
 
225
  global current_matrix, matrix_type
226
  ctx = dash.callback_context
227
  if not ctx.triggered:
 
14
 
15
  # Initialize the Dash app
16
  app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
17
+ uploaded_files = {}
18
 
19
  # Get OpenAI API key from Hugging Face Spaces environment variable
20
  openai.api_key = os.environ.get('OPENAI_API_KEY')
 
142
  global uploaded_files
143
  if list_of_contents is not None:
144
  new_files = []
145
+ for content, name in zip(list_of_contents, list_of_names):
146
  file_content = parse_file_content(content, name)
147
  uploaded_files[name] = file_content
148
  new_files.append(dbc.ListGroupItem([
 
150
  color="danger", size="sm", className="me-2"),
151
  html.Span(name)
152
  ]))
153
+ existing_files = existing_files or []
154
+ return existing_files + new_files
155
+ return existing_files or []
 
156
 
157
  # Update the remove file callback
158
  @app.callback(
 
168
  raise PreventUpdate
169
 
170
  triggered_id = ctx.triggered[0]['prop_id']
171
+ print(f"Triggered ID: {triggered_id}")
172
+
173
  removed_file = triggered_id.split('"index":')[1].split('"')[1]
174
+ print(f"Attempting to remove file: {removed_file}")
175
 
176
  uploaded_files.pop(removed_file, None)
177
+ print(f"Remaining files: {uploaded_files}")
178
+
179
  return [file for file in existing_files if file['props']['children'][1]['children'] != removed_file]
180
 
181
  def generate_matrix_with_gpt(matrix_type, file_contents):
 
227
  prevent_initial_call=True
228
  )
229
  def generate_matrix(*args):
230
+ print(f"Current uploaded files: {uploaded_files}")
231
  global current_matrix, matrix_type
232
  ctx = dash.callback_context
233
  if not ctx.triggered: