Update app.py
Browse files
app.py
CHANGED
|
@@ -188,32 +188,40 @@ 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 |
-
|
| 199 |
-
|
| 200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
-
|
|
|
|
| 203 |
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
|
|
|
|
|
|
| 217 |
)
|
| 218 |
def update_matrix_via_chat(n_clicks, chat_input):
|
| 219 |
global current_matrix
|
|
|
|
| 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_with_gpt(matrix_type, file_contents):
|
| 192 |
+
prompt = f"Generate a {matrix_type} based on the following project artifacts:\n\n"
|
| 193 |
+
prompt += "\n\n".join(file_contents)
|
| 194 |
+
prompt += f"\n\nCreate a {matrix_type} in a format that can be represented as a pandas DataFrame. Use '|' to separate columns. Do not include any separator lines, headers, or formatting characters. Start directly with the column names separated by '|'."
|
| 195 |
+
|
| 196 |
+
response = openai.ChatCompletion.create(
|
| 197 |
+
model="gpt-3.5-turbo",
|
| 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 |
+
# Use the first row as headers, and the rest as data
|
| 221 |
+
headers = data[0]
|
| 222 |
+
data = data[1:]
|
| 223 |
+
|
| 224 |
+
return pd.DataFrame(data, columns=headers)
|
| 225 |
)
|
| 226 |
def update_matrix_via_chat(n_clicks, chat_input):
|
| 227 |
global current_matrix
|