Update app.py
Browse files
app.py
CHANGED
@@ -188,40 +188,25 @@ def generate_matrix_with_gpt(matrix_type, file_contents):
|
|
188 |
[Input(f'btn-{matrix_type.lower().replace(" ", "-")}', 'n_clicks') for matrix_type in matrix_types.keys()],
|
189 |
prevent_initial_call=True
|
190 |
)
|
191 |
-
def
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
messages=[
|
199 |
-
{"role": "system", "content": "You are a helpful assistant that generates project management matrices without any formatting or separator lines."},
|
200 |
-
{"role": "user", "content": prompt}
|
201 |
-
]
|
202 |
-
)
|
203 |
-
|
204 |
-
matrix_text = response.choices[0].message.content
|
205 |
-
print("Raw matrix text from GPT:", matrix_text) # For debugging
|
206 |
-
|
207 |
-
# Filter out any lines that don't contain the '|' character
|
208 |
-
lines = [line.strip() for line in matrix_text.strip().split('\n') if '|' in line]
|
209 |
-
|
210 |
-
# More robust parsing of the matrix text
|
211 |
-
data = [line.split('|') for line in lines]
|
212 |
-
|
213 |
-
# Strip whitespace from each cell
|
214 |
-
data = [[cell.strip() for cell in row] for row in data]
|
215 |
-
|
216 |
-
# Ensure all rows have the same number of columns
|
217 |
-
max_columns = max(len(row) for row in data)
|
218 |
-
data = [row + [''] * (max_columns - len(row)) for row in data]
|
219 |
|
220 |
-
|
221 |
-
|
222 |
-
|
|
|
223 |
|
224 |
-
|
|
|
|
|
|
|
|
|
|
|
225 |
|
226 |
@app.callback(
|
227 |
Output('chat-output', 'children'),
|
|
|
188 |
[Input(f'btn-{matrix_type.lower().replace(" ", "-")}', 'n_clicks') for matrix_type in matrix_types.keys()],
|
189 |
prevent_initial_call=True
|
190 |
)
|
191 |
+
def generate_matrix(*args):
|
192 |
+
global current_matrix, matrix_type
|
193 |
+
ctx = dash.callback_context
|
194 |
+
if not ctx.triggered:
|
195 |
+
raise PreventUpdate
|
196 |
+
button_id = ctx.triggered[0]['prop_id'].split('.')[0]
|
197 |
+
matrix_type = button_id.replace('btn-', '').replace('-', ' ').title()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
|
199 |
+
if not uploaded_files:
|
200 |
+
return html.Div("Please upload project artifacts before generating a matrix."), ""
|
201 |
+
|
202 |
+
file_contents = list(uploaded_files.values())
|
203 |
|
204 |
+
try:
|
205 |
+
current_matrix = generate_matrix_with_gpt(matrix_type, file_contents)
|
206 |
+
return dbc.Table.from_dataframe(current_matrix, striped=True, bordered=True, hover=True), f"{matrix_type} generated"
|
207 |
+
except Exception as e:
|
208 |
+
print(f"Error generating matrix: {str(e)}")
|
209 |
+
return html.Div(f"Error generating matrix: {str(e)}"), "Error"
|
210 |
|
211 |
@app.callback(
|
212 |
Output('chat-output', 'children'),
|