Update app.py
Browse files
app.py
CHANGED
|
@@ -124,32 +124,6 @@ def parse_file_content(contents, filename):
|
|
| 124 |
print(f"Error processing file {filename}: {str(e)}")
|
| 125 |
return "Error processing file"
|
| 126 |
|
| 127 |
-
@app.callback(
|
| 128 |
-
Output('file-list', 'children', allow_duplicate=True),
|
| 129 |
-
Input({'type': 'remove-file', 'index': dash.ALL}, 'n_clicks'),
|
| 130 |
-
State('file-list', 'children'),
|
| 131 |
-
prevent_initial_call=True
|
| 132 |
-
)
|
| 133 |
-
def remove_file(n_clicks, existing_files):
|
| 134 |
-
global uploaded_files
|
| 135 |
-
ctx = dash.callback_context
|
| 136 |
-
if not ctx.triggered:
|
| 137 |
-
raise PreventUpdate
|
| 138 |
-
|
| 139 |
-
button_id = ctx.triggered[0]['prop_id'].split('.')[0]
|
| 140 |
-
removed_file = button_id.split('"index":"')[1].split('"')[0]
|
| 141 |
-
|
| 142 |
-
if removed_file in uploaded_files:
|
| 143 |
-
del uploaded_files[removed_file]
|
| 144 |
-
|
| 145 |
-
updated_files = [
|
| 146 |
-
file for file in existing_files
|
| 147 |
-
if file['props']['children'][1]['props']['children'] != removed_file
|
| 148 |
-
]
|
| 149 |
-
|
| 150 |
-
return updated_files
|
| 151 |
-
|
| 152 |
-
# Modify the update_output function to include the correct button structure
|
| 153 |
@app.callback(
|
| 154 |
Output('file-list', 'children'),
|
| 155 |
Input('upload-files', 'contents'),
|
|
@@ -164,8 +138,7 @@ def update_output(list_of_contents, list_of_names, existing_files):
|
|
| 164 |
file_content = parse_file_content(content, name)
|
| 165 |
uploaded_files[name] = file_content
|
| 166 |
new_files.append(html.Div([
|
| 167 |
-
html.Button('×', id={'type': 'remove-file', 'index': name},
|
| 168 |
-
style={'marginRight': '5px', 'fontSize': '10px', 'border': 'none', 'background': 'none', 'cursor': 'pointer'}),
|
| 169 |
html.Span(name)
|
| 170 |
]))
|
| 171 |
if existing_files is None:
|
|
@@ -173,6 +146,21 @@ def update_output(list_of_contents, list_of_names, existing_files):
|
|
| 173 |
return existing_files + new_files
|
| 174 |
return existing_files
|
| 175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
def generate_matrix_with_gpt(matrix_type, file_contents):
|
| 177 |
prompt = f"""Generate a {matrix_type} based on the following project artifacts:
|
| 178 |
{' '.join(file_contents)}
|
|
|
|
| 124 |
print(f"Error processing file {filename}: {str(e)}")
|
| 125 |
return "Error processing file"
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
@app.callback(
|
| 128 |
Output('file-list', 'children'),
|
| 129 |
Input('upload-files', 'contents'),
|
|
|
|
| 138 |
file_content = parse_file_content(content, name)
|
| 139 |
uploaded_files[name] = file_content
|
| 140 |
new_files.append(html.Div([
|
| 141 |
+
html.Button('×', id={'type': 'remove-file', 'index': name}, style={'marginRight': '5px', 'fontSize': '10px'}),
|
|
|
|
| 142 |
html.Span(name)
|
| 143 |
]))
|
| 144 |
if existing_files is None:
|
|
|
|
| 146 |
return existing_files + new_files
|
| 147 |
return existing_files
|
| 148 |
|
| 149 |
+
@app.callback(
|
| 150 |
+
Output('file-list', 'children', allow_duplicate=True),
|
| 151 |
+
Input({'type': 'remove-file', 'index': dash.ALL}, 'n_clicks'),
|
| 152 |
+
State('file-list', 'children'),
|
| 153 |
+
prevent_initial_call=True
|
| 154 |
+
)
|
| 155 |
+
def remove_file(n_clicks, existing_files):
|
| 156 |
+
global uploaded_files
|
| 157 |
+
ctx = dash.callback_context
|
| 158 |
+
if not ctx.triggered:
|
| 159 |
+
raise PreventUpdate
|
| 160 |
+
removed_file = ctx.triggered[0]['prop_id'].split(',')[0].split(':')[-1].strip('}')
|
| 161 |
+
uploaded_files.pop(removed_file, None)
|
| 162 |
+
return [file for file in existing_files if file['props']['children'][1]['props']['children'] != removed_file]
|
| 163 |
+
|
| 164 |
def generate_matrix_with_gpt(matrix_type, file_contents):
|
| 165 |
prompt = f"""Generate a {matrix_type} based on the following project artifacts:
|
| 166 |
{' '.join(file_contents)}
|