Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,6 @@ from dash.exceptions import PreventUpdate
|
|
| 11 |
import PyPDF2
|
| 12 |
import docx
|
| 13 |
import chardet
|
| 14 |
-
import json
|
| 15 |
|
| 16 |
# Initialize the Dash app
|
| 17 |
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
|
@@ -45,6 +44,10 @@ matrix_types = {
|
|
| 45 |
"SWOT Matrix": "Create a matrix analyzing Strengths, Weaknesses, Opportunities, and Threats."
|
| 46 |
}
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
app.layout = dbc.Container([
|
| 49 |
dbc.Row([
|
| 50 |
dbc.Col([
|
|
@@ -67,7 +70,10 @@ app.layout = dbc.Container([
|
|
| 67 |
},
|
| 68 |
multiple=True
|
| 69 |
),
|
| 70 |
-
html.Div(
|
|
|
|
|
|
|
|
|
|
| 71 |
html.Hr(),
|
| 72 |
html.Div([
|
| 73 |
dbc.Button(
|
|
@@ -80,7 +86,7 @@ app.layout = dbc.Container([
|
|
| 80 |
])
|
| 81 |
], width=3),
|
| 82 |
dbc.Col([
|
| 83 |
-
html.Div(style={"height": "20px"}), #
|
| 84 |
dcc.Loading(
|
| 85 |
id="loading-indicator",
|
| 86 |
type="dot",
|
|
@@ -90,7 +96,7 @@ app.layout = dbc.Container([
|
|
| 90 |
dbc.Button("Download Matrix", id="btn-download", color="success", className="mt-3"),
|
| 91 |
dcc.Download(id="download-matrix"),
|
| 92 |
html.Hr(),
|
| 93 |
-
html.Div(style={"height": "20px"}), #
|
| 94 |
dcc.Loading(
|
| 95 |
id="chat-loading",
|
| 96 |
type="dot",
|
|
@@ -138,15 +144,17 @@ def update_output(list_of_contents, list_of_names, existing_files):
|
|
| 138 |
for i, (content, name) in enumerate(zip(list_of_contents, list_of_names)):
|
| 139 |
file_content = parse_file_content(content, name)
|
| 140 |
uploaded_files[name] = file_content
|
| 141 |
-
new_files.append(
|
| 142 |
-
|
|
|
|
| 143 |
html.Span(name)
|
| 144 |
-
]
|
| 145 |
if existing_files is None:
|
| 146 |
existing_files = []
|
| 147 |
-
return existing_files + new_files
|
| 148 |
-
return existing_files
|
| 149 |
|
|
|
|
| 150 |
@app.callback(
|
| 151 |
Output('file-list', 'children', allow_duplicate=True),
|
| 152 |
Input({'type': 'remove-file', 'index': dash.ALL}, 'n_clicks'),
|
|
@@ -160,11 +168,10 @@ def remove_file(n_clicks, existing_files):
|
|
| 160 |
raise PreventUpdate
|
| 161 |
|
| 162 |
triggered_id = ctx.triggered[0]['prop_id']
|
| 163 |
-
|
| 164 |
-
removed_file = triggered_id.split('"index":')[1].split('}')[0].strip('"')
|
| 165 |
|
| 166 |
uploaded_files.pop(removed_file, None)
|
| 167 |
-
return [file for file in existing_files if file['props']['children'][1]['
|
| 168 |
|
| 169 |
def generate_matrix_with_gpt(matrix_type, file_contents):
|
| 170 |
prompt = f"""Generate a {matrix_type} based on the following project artifacts:
|
|
|
|
| 11 |
import PyPDF2
|
| 12 |
import docx
|
| 13 |
import chardet
|
|
|
|
| 14 |
|
| 15 |
# Initialize the Dash app
|
| 16 |
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
|
|
|
| 44 |
"SWOT Matrix": "Create a matrix analyzing Strengths, Weaknesses, Opportunities, and Threats."
|
| 45 |
}
|
| 46 |
|
| 47 |
+
import dash
|
| 48 |
+
from dash import dcc, html
|
| 49 |
+
import dash_bootstrap_components as dbc
|
| 50 |
+
|
| 51 |
app.layout = dbc.Container([
|
| 52 |
dbc.Row([
|
| 53 |
dbc.Col([
|
|
|
|
| 70 |
},
|
| 71 |
multiple=True
|
| 72 |
),
|
| 73 |
+
html.Div([
|
| 74 |
+
html.H5("Uploaded Files"),
|
| 75 |
+
dbc.ListGroup(id='file-list')
|
| 76 |
+
], className="mt-3"),
|
| 77 |
html.Hr(),
|
| 78 |
html.Div([
|
| 79 |
dbc.Button(
|
|
|
|
| 86 |
])
|
| 87 |
], width=3),
|
| 88 |
dbc.Col([
|
| 89 |
+
html.Div(style={"height": "20px"}), # Small gap
|
| 90 |
dcc.Loading(
|
| 91 |
id="loading-indicator",
|
| 92 |
type="dot",
|
|
|
|
| 96 |
dbc.Button("Download Matrix", id="btn-download", color="success", className="mt-3"),
|
| 97 |
dcc.Download(id="download-matrix"),
|
| 98 |
html.Hr(),
|
| 99 |
+
html.Div(style={"height": "20px"}), # Small gap
|
| 100 |
dcc.Loading(
|
| 101 |
id="chat-loading",
|
| 102 |
type="dot",
|
|
|
|
| 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([
|
| 148 |
+
dbc.Button("×", id={'type': 'remove-file', 'index': name},
|
| 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(
|
| 159 |
Output('file-list', 'children', allow_duplicate=True),
|
| 160 |
Input({'type': 'remove-file', 'index': dash.ALL}, 'n_clicks'),
|
|
|
|
| 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):
|
| 177 |
prompt = f"""Generate a {matrix_type} based on the following project artifacts:
|