Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -369,4 +369,143 @@ def update_loe_output(n_clicks, shred_output):
|
|
369 |
return "Click 'Generate LOE' to begin."
|
370 |
|
371 |
if shred_output is None:
|
372 |
-
return "Please complete the
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
return "Click 'Generate LOE' to begin."
|
370 |
|
371 |
if shred_output is None:
|
372 |
+
return "Please complete the Shred tab first."
|
373 |
+
|
374 |
+
loe_text, loe_df = generate_loe(shred_output)
|
375 |
+
|
376 |
+
return [
|
377 |
+
dcc.Markdown(loe_text),
|
378 |
+
dash_table.DataTable(
|
379 |
+
data=loe_df.to_dict('records'),
|
380 |
+
columns=[{'name': i, 'id': i} for i in loe_df.columns],
|
381 |
+
style_table={'overflowX': 'auto'},
|
382 |
+
style_cell={'textAlign': 'left', 'padding': '5px'},
|
383 |
+
style_header={'backgroundColor': 'rgb(230, 230, 230)', 'fontWeight': 'bold'}
|
384 |
+
)
|
385 |
+
]
|
386 |
+
|
387 |
+
@app.callback(
|
388 |
+
Output('red-output', 'children'),
|
389 |
+
Input('generate-red', 'n_clicks'),
|
390 |
+
State('upload-red', 'contents'),
|
391 |
+
State('upload-red', 'filename'),
|
392 |
+
State('p-review-output', 'children')
|
393 |
+
)
|
394 |
+
def update_red_output(n_clicks, contents, filename, p_review_output):
|
395 |
+
if n_clicks is None:
|
396 |
+
return "Click 'Generate Red Team Document' to begin."
|
397 |
+
|
398 |
+
if contents:
|
399 |
+
document = process_document(contents, filename)
|
400 |
+
elif p_review_output:
|
401 |
+
document = p_review_output
|
402 |
+
else:
|
403 |
+
return "Please upload a document or complete the P.Review first."
|
404 |
+
|
405 |
+
red_doc = generate_red_document(document, p_review_output)
|
406 |
+
return dcc.Markdown(red_doc)
|
407 |
+
|
408 |
+
@app.callback(
|
409 |
+
Output('r-review-output', 'children'),
|
410 |
+
Input('evaluate-r-review', 'n_clicks'),
|
411 |
+
State('upload-r-review', 'contents'),
|
412 |
+
State('upload-r-review', 'filename'),
|
413 |
+
State('red-output', 'children'),
|
414 |
+
State('shred-output', 'children')
|
415 |
+
)
|
416 |
+
def update_r_review_output(n_clicks, contents, filename, red_doc, requirements):
|
417 |
+
if n_clicks is None:
|
418 |
+
return "Click 'Evaluate Compliance' to begin."
|
419 |
+
|
420 |
+
if contents:
|
421 |
+
document = process_document(contents, filename)
|
422 |
+
elif red_doc:
|
423 |
+
document = red_doc
|
424 |
+
else:
|
425 |
+
return "Please upload a document or generate a Red Team document first."
|
426 |
+
|
427 |
+
compliance_report = evaluate_compliance(document, requirements)
|
428 |
+
return dcc.Markdown(compliance_report)
|
429 |
+
|
430 |
+
@app.callback(
|
431 |
+
Output("download-shred-doc", "data"),
|
432 |
+
Input("download-shred", "n_clicks"),
|
433 |
+
State('shred-output', 'children'),
|
434 |
+
prevent_initial_call=True,
|
435 |
+
)
|
436 |
+
def download_shred(n_clicks, shred_output):
|
437 |
+
if shred_output is None:
|
438 |
+
return dash.no_update
|
439 |
+
return dict(content=shred_output, filename="shred_outline.md")
|
440 |
+
|
441 |
+
@app.callback(
|
442 |
+
Output("download-pink-doc", "data"),
|
443 |
+
Input("download-pink", "n_clicks"),
|
444 |
+
State('pink-output', 'children'),
|
445 |
+
prevent_initial_call=True,
|
446 |
+
)
|
447 |
+
def download_pink(n_clicks, pink_output):
|
448 |
+
if pink_output is None:
|
449 |
+
return dash.no_update
|
450 |
+
return dict(content=pink_output, filename="pink_team_document.md")
|
451 |
+
|
452 |
+
@app.callback(
|
453 |
+
Output("download-p-review-doc", "data"),
|
454 |
+
Input("download-p-review", "n_clicks"),
|
455 |
+
State('p-review-output', 'children'),
|
456 |
+
prevent_initial_call=True,
|
457 |
+
)
|
458 |
+
def download_p_review(n_clicks, p_review_output):
|
459 |
+
if p_review_output is None:
|
460 |
+
return dash.no_update
|
461 |
+
return dict(content=p_review_output, filename="p_review_report.md")
|
462 |
+
|
463 |
+
@app.callback(
|
464 |
+
Output("download-red-doc", "data"),
|
465 |
+
Input("download-red", "n_clicks"),
|
466 |
+
State('red-output', 'children'),
|
467 |
+
prevent_initial_call=True,
|
468 |
+
)
|
469 |
+
def download_red(n_clicks, red_output):
|
470 |
+
if red_output is None:
|
471 |
+
return dash.no_update
|
472 |
+
return dict(content=red_output, filename="red_team_document.md")
|
473 |
+
|
474 |
+
@app.callback(
|
475 |
+
Output("download-r-review-doc", "data"),
|
476 |
+
Input("download-r-review", "n_clicks"),
|
477 |
+
State('r-review-output', 'children'),
|
478 |
+
prevent_initial_call=True,
|
479 |
+
)
|
480 |
+
def download_r_review(n_clicks, r_review_output):
|
481 |
+
if r_review_output is None:
|
482 |
+
return dash.no_update
|
483 |
+
return dict(content=r_review_output, filename="r_review_report.md")
|
484 |
+
|
485 |
+
@app.callback(
|
486 |
+
Output("download-g-review-doc", "data"),
|
487 |
+
Input("download-g-review", "n_clicks"),
|
488 |
+
State('g-review-output', 'children'),
|
489 |
+
prevent_initial_call=True,
|
490 |
+
)
|
491 |
+
def download_g_review(n_clicks, g_review_output):
|
492 |
+
if g_review_output is None:
|
493 |
+
return dash.no_update
|
494 |
+
return dict(content=g_review_output, filename="g_review_report.md")
|
495 |
+
|
496 |
+
@app.callback(
|
497 |
+
Output("download-loe-doc", "data"),
|
498 |
+
Input("download-loe", "n_clicks"),
|
499 |
+
State('loe-output', 'children'),
|
500 |
+
prevent_initial_call=True,
|
501 |
+
)
|
502 |
+
def download_loe(n_clicks, loe_output):
|
503 |
+
if loe_output is None:
|
504 |
+
return dash.no_update
|
505 |
+
loe_text = loe_output[0]['props']['children']
|
506 |
+
return dict(content=loe_text, filename="loe_report.md")
|
507 |
+
|
508 |
+
if __name__ == '__main__':
|
509 |
+
print("Starting the Dash application...")
|
510 |
+
app.run(debug=True, host='0.0.0.0', port=7860)
|
511 |
+
print("Dash application has finished running.")
|