Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -26,6 +26,8 @@ current_document = None
|
|
26 |
document_type = None
|
27 |
shredded_document = None
|
28 |
pink_review_document = None
|
|
|
|
|
29 |
|
30 |
# Document types and their descriptions
|
31 |
document_types = {
|
@@ -34,7 +36,7 @@ document_types = {
|
|
34 |
"Pink Review": "Evaluate compliance of the Pink Team document against the requirements and output a spreadsheet of non compliant findings by pws number, the goal of that pws section, what made it non compliant and your recommendations for recovery",
|
35 |
"Red": "Produce a Red Team document based on the Pink Review by pws sections. Your goal is to be compliant and compelling by recovering all the findings in Pink Review",
|
36 |
"Red Review": "Evaluate compliance of the Red Team document against the requirements and output a spreadsheet of non compliant findings by pws number, the goal of that pws section, what made it non compliant and your recommendations for recovery",
|
37 |
-
"Gold": "Create a
|
38 |
"Gold Review": "Perform a final compliance review against the requirements and output a spreadsheet of non compliant findings by pws number, the goal of that pws section, what made it non compliant and your recommendations for recovery",
|
39 |
"Virtual Board": "Based on the requirements and in particular the evaulation criteria, you will evaluate the proposal as if you were a contracting office and provide section by section evaluation as unsatisfactory, satisfactory, good, very good, excellent and why in a spreadsheet",
|
40 |
"LOE": "Generate a Level of Effort (LOE) breakdown as a spreadsheet"
|
@@ -85,10 +87,10 @@ app.layout = dbc.Container([
|
|
85 |
dbc.Button("Download Document", id="btn-download", color="success", className="mt-3"),
|
86 |
dcc.Download(id="download-document"),
|
87 |
html.Hr(),
|
88 |
-
html.Div(id='
|
89 |
dcc.Upload(
|
90 |
-
id='upload-
|
91 |
-
children=html.Div(['Drag and Drop or ', html.A('Select
|
92 |
style={
|
93 |
'width': '100%',
|
94 |
'height': '60px',
|
@@ -101,7 +103,7 @@ app.layout = dbc.Container([
|
|
101 |
},
|
102 |
multiple=False
|
103 |
),
|
104 |
-
html.Div(id='
|
105 |
]),
|
106 |
dcc.Loading(
|
107 |
id="chat-loading",
|
@@ -186,7 +188,7 @@ Instructions:
|
|
186 |
4. Start the output immediately with the document content.
|
187 |
5. IMPORTANT: If the document type is Pink, Red, Gold and not review type, loe or board
|
188 |
then your goal is to be compliant and compelling based on the
|
189 |
-
|
190 |
MicroHealth, limit bullets, answer the
|
191 |
requirement with what MicroHealth will do
|
192 |
to satisfy the requirement, the technical
|
@@ -214,19 +216,19 @@ Now, generate the {document_type}:
|
|
214 |
Output('document-preview', 'children'),
|
215 |
Output('loading-output', 'children'),
|
216 |
Output('status-bar', 'children', allow_duplicate=True),
|
217 |
-
Output('
|
218 |
[Input(f'btn-{doc_type.lower().replace("_", "-")}', 'n_clicks') for doc_type in document_types.keys()],
|
219 |
-
State('
|
220 |
prevent_initial_call=True
|
221 |
)
|
222 |
def generate_document_preview(*args):
|
223 |
-
global current_document, document_type, shredded_document,
|
224 |
ctx = dash.callback_context
|
225 |
if not ctx.triggered:
|
226 |
raise dash.exceptions.PreventUpdate
|
227 |
button_id = ctx.triggered[0]['prop_id'].split('.')[0]
|
228 |
document_type = button_id.replace('btn-', '').replace('-', '_').title()
|
229 |
-
|
230 |
|
231 |
if not uploaded_files and document_type != "Shred":
|
232 |
return html.Div("Please upload and shred a document first."), "", "Please upload and shred a document first.", {'display': 'none'}
|
@@ -237,6 +239,7 @@ def generate_document_preview(*args):
|
|
237 |
file_contents = list(uploaded_files.values())
|
238 |
try:
|
239 |
shredded_document = generate_document(document_type, file_contents)
|
|
|
240 |
return dcc.Markdown(shredded_document), f"{document_type} generated", "Document shredded. You can now proceed with other operations.", {'display': 'none'}
|
241 |
except Exception as e:
|
242 |
print(f"Error generating document: {str(e)}")
|
@@ -245,22 +248,24 @@ def generate_document_preview(*args):
|
|
245 |
if shredded_document is None:
|
246 |
return html.Div("Please shred a document first."), "", "Please shred a document first.", {'display': 'none'}
|
247 |
|
248 |
-
if document_type
|
249 |
-
return html.Div("Please upload a
|
250 |
-
|
251 |
-
if document_type in ["Red", "Red Review"] and pink_review_document is None:
|
252 |
-
return html.Div("Please complete Pink Review first."), "", "Please complete Pink Review first.", {'display': 'none'}
|
253 |
|
254 |
try:
|
255 |
-
if document_type == "Pink
|
256 |
-
current_document = generate_document(document_type, [
|
257 |
-
elif document_type
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
else:
|
260 |
current_document = generate_document(document_type, [shredded_document])
|
261 |
|
262 |
-
|
263 |
-
pink_review_document = current_document
|
264 |
|
265 |
return dcc.Markdown(current_document), f"{document_type} generated", f"{document_type} document generated successfully.", {'display': 'none'}
|
266 |
except Exception as e:
|
@@ -268,11 +273,11 @@ def generate_document_preview(*args):
|
|
268 |
return html.Div(f"Error generating document: {str(e)}"), "Error", "An error occurred while generating the document.", {'display': 'none'}
|
269 |
|
270 |
@app.callback(
|
271 |
-
Output('
|
272 |
-
Input('upload-
|
273 |
-
State('upload-
|
274 |
)
|
275 |
-
def
|
276 |
if contents is not None:
|
277 |
return filename
|
278 |
return ""
|
@@ -314,14 +319,14 @@ def download_document(n_clicks):
|
|
314 |
if current_document is None:
|
315 |
raise dash.exceptions.PreventUpdate
|
316 |
|
317 |
-
if document_type
|
318 |
-
# Create a pandas DataFrame for
|
319 |
df = pd.read_csv(StringIO(current_document))
|
320 |
|
321 |
# Save the DataFrame to an Excel file
|
322 |
output = BytesIO()
|
323 |
with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
|
324 |
-
df.to_excel(writer, sheet_name=
|
325 |
|
326 |
return dcc.send_bytes(output.getvalue(), f"{document_type}.xlsx")
|
327 |
else:
|
|
|
26 |
document_type = None
|
27 |
shredded_document = None
|
28 |
pink_review_document = None
|
29 |
+
red_review_document = None
|
30 |
+
generated_documents = {}
|
31 |
|
32 |
# Document types and their descriptions
|
33 |
document_types = {
|
|
|
36 |
"Pink Review": "Evaluate compliance of the Pink Team document against the requirements and output a spreadsheet of non compliant findings by pws number, the goal of that pws section, what made it non compliant and your recommendations for recovery",
|
37 |
"Red": "Produce a Red Team document based on the Pink Review by pws sections. Your goal is to be compliant and compelling by recovering all the findings in Pink Review",
|
38 |
"Red Review": "Evaluate compliance of the Red Team document against the requirements and output a spreadsheet of non compliant findings by pws number, the goal of that pws section, what made it non compliant and your recommendations for recovery",
|
39 |
+
"Gold": "Create a Gold Team document based on the PWS response by pws sections. Your goal is to be compliant and compelling by recovering all the findings in Red Review",
|
40 |
"Gold Review": "Perform a final compliance review against the requirements and output a spreadsheet of non compliant findings by pws number, the goal of that pws section, what made it non compliant and your recommendations for recovery",
|
41 |
"Virtual Board": "Based on the requirements and in particular the evaulation criteria, you will evaluate the proposal as if you were a contracting office and provide section by section evaluation as unsatisfactory, satisfactory, good, very good, excellent and why in a spreadsheet",
|
42 |
"LOE": "Generate a Level of Effort (LOE) breakdown as a spreadsheet"
|
|
|
87 |
dbc.Button("Download Document", id="btn-download", color="success", className="mt-3"),
|
88 |
dcc.Download(id="download-document"),
|
89 |
html.Hr(),
|
90 |
+
html.Div(id='review-upload', style={'display': 'none'}, children=[
|
91 |
dcc.Upload(
|
92 |
+
id='upload-review',
|
93 |
+
children=html.Div(['Drag and Drop or ', html.A('Select Review File')]),
|
94 |
style={
|
95 |
'width': '100%',
|
96 |
'height': '60px',
|
|
|
103 |
},
|
104 |
multiple=False
|
105 |
),
|
106 |
+
html.Div(id='review-file-name')
|
107 |
]),
|
108 |
dcc.Loading(
|
109 |
id="chat-loading",
|
|
|
188 |
4. Start the output immediately with the document content.
|
189 |
5. IMPORTANT: If the document type is Pink, Red, Gold and not review type, loe or board
|
190 |
then your goal is to be compliant and compelling based on the
|
191 |
+
requirements, write in paragraph in active voice as
|
192 |
MicroHealth, limit bullets, answer the
|
193 |
requirement with what MicroHealth will do
|
194 |
to satisfy the requirement, the technical
|
|
|
216 |
Output('document-preview', 'children'),
|
217 |
Output('loading-output', 'children'),
|
218 |
Output('status-bar', 'children', allow_duplicate=True),
|
219 |
+
Output('review-upload', 'style'),
|
220 |
[Input(f'btn-{doc_type.lower().replace("_", "-")}', 'n_clicks') for doc_type in document_types.keys()],
|
221 |
+
State('review-file-name', 'children'),
|
222 |
prevent_initial_call=True
|
223 |
)
|
224 |
def generate_document_preview(*args):
|
225 |
+
global current_document, document_type, shredded_document, generated_documents
|
226 |
ctx = dash.callback_context
|
227 |
if not ctx.triggered:
|
228 |
raise dash.exceptions.PreventUpdate
|
229 |
button_id = ctx.triggered[0]['prop_id'].split('.')[0]
|
230 |
document_type = button_id.replace('btn-', '').replace('-', '_').title()
|
231 |
+
review_file = args[-1]
|
232 |
|
233 |
if not uploaded_files and document_type != "Shred":
|
234 |
return html.Div("Please upload and shred a document first."), "", "Please upload and shred a document first.", {'display': 'none'}
|
|
|
239 |
file_contents = list(uploaded_files.values())
|
240 |
try:
|
241 |
shredded_document = generate_document(document_type, file_contents)
|
242 |
+
generated_documents['Shred'] = shredded_document
|
243 |
return dcc.Markdown(shredded_document), f"{document_type} generated", "Document shredded. You can now proceed with other operations.", {'display': 'none'}
|
244 |
except Exception as e:
|
245 |
print(f"Error generating document: {str(e)}")
|
|
|
248 |
if shredded_document is None:
|
249 |
return html.Div("Please shred a document first."), "", "Please shred a document first.", {'display': 'none'}
|
250 |
|
251 |
+
if document_type in ["Pink Review", "Red Review", "Gold Review"]:
|
252 |
+
return html.Div(f"Please upload a {document_type.split()[0]} Team document or use the generated one."), "", f"Please upload a {document_type.split()[0]} Team document or use the generated one.", {'display': 'block'}
|
|
|
|
|
|
|
253 |
|
254 |
try:
|
255 |
+
if document_type == "Pink":
|
256 |
+
current_document = generate_document(document_type, [shredded_document])
|
257 |
+
elif document_type == "Red":
|
258 |
+
if 'Pink Review' not in generated_documents:
|
259 |
+
return html.Div("Please complete Pink Review first."), "", "Please complete Pink Review first.", {'display': 'none'}
|
260 |
+
current_document = generate_document(document_type, [generated_documents['Pink Review'], shredded_document])
|
261 |
+
elif document_type == "Gold":
|
262 |
+
if 'Red Review' not in generated_documents:
|
263 |
+
return html.Div("Please complete Red Review first."), "", "Please complete Red Review first.", {'display': 'none'}
|
264 |
+
current_document = generate_document(document_type, [generated_documents['Red Review'], shredded_document])
|
265 |
else:
|
266 |
current_document = generate_document(document_type, [shredded_document])
|
267 |
|
268 |
+
generated_documents[document_type] = current_document
|
|
|
269 |
|
270 |
return dcc.Markdown(current_document), f"{document_type} generated", f"{document_type} document generated successfully.", {'display': 'none'}
|
271 |
except Exception as e:
|
|
|
273 |
return html.Div(f"Error generating document: {str(e)}"), "Error", "An error occurred while generating the document.", {'display': 'none'}
|
274 |
|
275 |
@app.callback(
|
276 |
+
Output('review-file-name', 'children'),
|
277 |
+
Input('upload-review', 'contents'),
|
278 |
+
State('upload-review', 'filename')
|
279 |
)
|
280 |
+
def update_review_filename(contents, filename):
|
281 |
if contents is not None:
|
282 |
return filename
|
283 |
return ""
|
|
|
319 |
if current_document is None:
|
320 |
raise dash.exceptions.PreventUpdate
|
321 |
|
322 |
+
if document_type in ["LOE", "Pink Review", "Red Review", "Gold Review", "Virtual Board"]:
|
323 |
+
# Create a pandas DataFrame for spreadsheet-type documents
|
324 |
df = pd.read_csv(StringIO(current_document))
|
325 |
|
326 |
# Save the DataFrame to an Excel file
|
327 |
output = BytesIO()
|
328 |
with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
|
329 |
+
df.to_excel(writer, sheet_name=document_type, index=False)
|
330 |
|
331 |
return dcc.send_bytes(output.getvalue(), f"{document_type}.xlsx")
|
332 |
else:
|