Update app.py
Browse files
app.py
CHANGED
|
@@ -156,7 +156,7 @@ def remove_file(n_clicks, existing_files):
|
|
| 156 |
def generate_matrix_with_gpt(matrix_type, file_contents):
|
| 157 |
prompt = f"Generate a {matrix_type} based on the following project artifacts:\n\n"
|
| 158 |
prompt += "\n\n".join(file_contents)
|
| 159 |
-
prompt += f"\n\nCreate a {matrix_type} in a format that can be represented as a pandas DataFrame."
|
| 160 |
|
| 161 |
response = openai.ChatCompletion.create(
|
| 162 |
model="gpt-3.5-turbo",
|
|
@@ -167,11 +167,19 @@ def generate_matrix_with_gpt(matrix_type, file_contents):
|
|
| 167 |
)
|
| 168 |
|
| 169 |
matrix_text = response.choices[0].message.content
|
| 170 |
-
|
| 171 |
-
#
|
| 172 |
-
lines = matrix_text.strip().split('\n')
|
| 173 |
-
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
return pd.DataFrame(data, columns=headers)
|
| 176 |
|
| 177 |
@app.callback(
|
|
|
|
| 156 |
def generate_matrix_with_gpt(matrix_type, file_contents):
|
| 157 |
prompt = f"Generate a {matrix_type} based on the following project artifacts:\n\n"
|
| 158 |
prompt += "\n\n".join(file_contents)
|
| 159 |
+
prompt += f"\n\nCreate a {matrix_type} in a format that can be represented as a pandas DataFrame. Use '|' to separate columns and ensure each row has the same number of columns."
|
| 160 |
|
| 161 |
response = openai.ChatCompletion.create(
|
| 162 |
model="gpt-3.5-turbo",
|
|
|
|
| 167 |
)
|
| 168 |
|
| 169 |
matrix_text = response.choices[0].message.content
|
| 170 |
+
|
| 171 |
+
# More robust parsing of the matrix text
|
| 172 |
+
lines = [line.strip() for line in matrix_text.strip().split('\n') if line.strip()]
|
| 173 |
+
data = [line.split('|') for line in lines]
|
| 174 |
+
|
| 175 |
+
# Ensure all rows have the same number of columns
|
| 176 |
+
max_columns = max(len(row) for row in data)
|
| 177 |
+
data = [row + [''] * (max_columns - len(row)) for row in data]
|
| 178 |
+
|
| 179 |
+
# Use the first row as headers, and the rest as data
|
| 180 |
+
headers = data[0]
|
| 181 |
+
data = data[1:]
|
| 182 |
+
|
| 183 |
return pd.DataFrame(data, columns=headers)
|
| 184 |
|
| 185 |
@app.callback(
|