Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -5,10 +5,11 @@ import threading
|
|
5 |
import time
|
6 |
from typing import List, Tuple
|
7 |
import re
|
8 |
-
import pandas as pd
|
|
|
9 |
import dash
|
10 |
import dash_bootstrap_components as dbc
|
11 |
-
from dash import html, dcc, Input, Output, State, ctx
|
12 |
import google.generativeai as genai
|
13 |
from docx import Document
|
14 |
from PyPDF2 import PdfReader
|
@@ -326,145 +327,20 @@ def update_pink_output(n_clicks, shred_output, instructions):
|
|
326 |
State('pink-output', 'children'),
|
327 |
State('shred-output', 'children')
|
328 |
)
|
329 |
-
|
330 |
-
@app.callback(
|
331 |
-
Output('g-review-output', 'children'),
|
332 |
-
Input('evaluate-g-review', 'n_clicks'),
|
333 |
-
State('upload-g-review', 'contents'),
|
334 |
-
State('upload-g-review', 'filename'),
|
335 |
-
State('shred-output', 'children')
|
336 |
-
)
|
337 |
-
def update_g_review_output(n_clicks, contents, filename, requirements):
|
338 |
-
if n_clicks is None:
|
339 |
-
return "Click 'Evaluate Compliance' to begin."
|
340 |
-
|
341 |
-
if contents is None:
|
342 |
-
return "Please upload a document first."
|
343 |
-
|
344 |
-
document = process_document(contents, filename)
|
345 |
-
compliance_report = evaluate_compliance(document, requirements)
|
346 |
-
return dcc.Markdown(compliance_report)
|
347 |
-
|
348 |
-
@app.callback(
|
349 |
-
Output('loe-output', 'children'),
|
350 |
-
Input('generate-loe', 'n_clicks'),
|
351 |
-
State('shred-output', 'children')
|
352 |
-
)
|
353 |
-
def update_loe_output(n_clicks, shred_output):
|
354 |
-
if n_clicks is None:
|
355 |
-
return "Click 'Generate LOE' to begin."
|
356 |
-
|
357 |
-
if shred_output is None:
|
358 |
-
return "Please complete the Shred tab first."
|
359 |
-
|
360 |
-
loe_text, loe_df = generate_loe(shred_output)
|
361 |
-
|
362 |
-
return [
|
363 |
-
dcc.Markdown(loe_text),
|
364 |
-
dash_table.DataTable(
|
365 |
-
data=loe_df.to_dict('records'),
|
366 |
-
columns=[{'name': i, 'id': i} for i in loe_df.columns],
|
367 |
-
style_table={'overflowX': 'auto'},
|
368 |
-
style_cell={'textAlign': 'left', 'padding': '5px'},
|
369 |
-
style_header={'backgroundColor': 'rgb(230, 230, 230)', 'fontWeight': 'bold'}
|
370 |
-
)
|
371 |
-
]
|
372 |
-
|
373 |
-
@app.callback(
|
374 |
-
[Output(f"tab-{tab}", "disabled") for tab in ["pink", "p-review", "red", "r-review", "g-review", "loe"]],
|
375 |
-
Input('shred-output', 'children')
|
376 |
-
)
|
377 |
-
def update_tab_status(shred_output):
|
378 |
-
return [shred_output is None] * 6
|
379 |
-
|
380 |
-
@app.callback(
|
381 |
-
Output('red-output', 'children'),
|
382 |
-
Input('generate-red', 'n_clicks'),
|
383 |
-
State('upload-red', 'contents'),
|
384 |
-
State('upload-red', 'filename'),
|
385 |
-
State('p-review-output', 'children')
|
386 |
-
)
|
387 |
-
def update_red_output(n_clicks, contents, filename, p_review_output):
|
388 |
-
if n_clicks is None:
|
389 |
-
return "Click 'Generate Red Team Document' to begin."
|
390 |
-
|
391 |
-
if contents:
|
392 |
-
document = process_document(contents, filename)
|
393 |
-
elif p_review_output:
|
394 |
-
document = p_review_output
|
395 |
-
else:
|
396 |
-
return "Please upload a document or complete the P.Review first."
|
397 |
-
|
398 |
-
red_doc = generate_red_document(document, p_review_output)
|
399 |
-
return dcc.Markdown(red_doc)
|
400 |
-
|
401 |
-
@app.callback(
|
402 |
-
Output('r-review-output', 'children'),
|
403 |
-
Input('evaluate-r-review', 'n_clicks'),
|
404 |
-
State('upload-r-review', 'contents'),
|
405 |
-
State('upload-r-review', 'filename'),
|
406 |
-
State('red-output', 'children'),
|
407 |
-
State('shred-output', 'children')
|
408 |
-
)
|
409 |
-
def update_r_review_output(n_clicks, contents, filename, red_doc, requirements):
|
410 |
if n_clicks is None:
|
411 |
return "Click 'Evaluate Compliance' to begin."
|
412 |
|
413 |
if contents:
|
414 |
document = process_document(contents, filename)
|
415 |
-
elif
|
416 |
-
document =
|
417 |
else:
|
418 |
-
return "Please upload a document or generate a
|
419 |
|
420 |
compliance_report = evaluate_compliance(document, requirements)
|
421 |
return dcc.Markdown(compliance_report)
|
422 |
|
423 |
-
@app.callback(
|
424 |
-
Output("download-shred-doc", "data"),
|
425 |
-
Input("download-shred", "n_clicks"),
|
426 |
-
State('shred-output', 'children'),
|
427 |
-
prevent_initial_call=True,
|
428 |
-
)
|
429 |
-
def download_shred(n_clicks, shred_output):
|
430 |
-
if shred_output is None:
|
431 |
-
return dash.no_update
|
432 |
-
return dict(content=shred_output, filename="shred_outline.md")
|
433 |
-
|
434 |
-
@app.callback(
|
435 |
-
Output("download-pink-doc", "data"),
|
436 |
-
Input("download-pink", "n_clicks"),
|
437 |
-
State('pink-output', 'children'),
|
438 |
-
prevent_initial_call=True,
|
439 |
-
)
|
440 |
-
def download_pink(n_clicks, pink_output):
|
441 |
-
if pink_output is None:
|
442 |
-
return dash.no_update
|
443 |
-
return dict(content=pink_output, filename="pink_team_document.md")
|
444 |
-
|
445 |
-
@app.callback(
|
446 |
-
Output("download-p-review-doc", "data"),
|
447 |
-
Input("download-p-review", "n_clicks"),
|
448 |
-
State('p-review-output', 'children'),
|
449 |
-
prevent_initial_call=True,
|
450 |
-
)
|
451 |
-
def download_p_review(n_clicks, p_review_output):
|
452 |
-
if p_review_output is None:
|
453 |
-
return dash.no_update
|
454 |
-
return dict(content=p_review_output, filename="p_review_report.md")
|
455 |
-
|
456 |
-
@app.callback(
|
457 |
-
Output("download-red-doc", "data"),
|
458 |
-
Input("download-red", "n_clicks"),
|
459 |
-
State('red-output', 'children'),
|
460 |
-
prevent_initial_call=True,
|
461 |
-
)
|
462 |
-
def download_red(n_clicks, red_output):
|
463 |
-
if red_output is None:
|
464 |
-
return dash.no_update
|
465 |
-
return dict(content=red_output, filename="red_team_document.md")
|
466 |
-
|
467 |
-
# Update the g-review callback
|
468 |
@app.callback(
|
469 |
Output('g-review-output', 'children'),
|
470 |
Input('evaluate-g-review', 'n_clicks'),
|
@@ -483,86 +359,14 @@ def update_g_review_output(n_clicks, contents, filename, requirements):
|
|
483 |
compliance_report = evaluate_compliance(document, requirements)
|
484 |
return dcc.Markdown(compliance_report)
|
485 |
|
486 |
-
# Update the tab disabling callback
|
487 |
@app.callback(
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
)
|
492 |
-
def
|
493 |
-
|
494 |
-
|
495 |
-
dbc.Tab(label="Pink", tab_id="pink"),
|
496 |
-
dbc.Tab(label="P.Review", tab_id="p-review"),
|
497 |
-
dbc.Tab(label="Red", tab_id="red"),
|
498 |
-
dbc.Tab(label="R.Review", tab_id="r-review"),
|
499 |
-
dbc.Tab(label="G.Review", tab_id="g-review"),
|
500 |
-
dbc.Tab(label="LOE", tab_id="loe")
|
501 |
-
]
|
502 |
|
503 |
if shred_output is None:
|
504 |
-
|
505 |
-
tab.disabled = True
|
506 |
-
else:
|
507 |
-
for tab in tabs[1:]:
|
508 |
-
tab.disabled = False
|
509 |
-
|
510 |
-
return ["shred"] + tabs
|
511 |
-
|
512 |
-
# Update the app layout
|
513 |
-
app.layout = dbc.Container([
|
514 |
-
html.H1("MicroHealth PWS Analysis and Response Generator", className="my-4"),
|
515 |
-
dbc.Tabs(id="tabs", active_tab="shred"),
|
516 |
-
html.Div(id='tab-content')
|
517 |
-
])
|
518 |
-
|
519 |
-
# Add a callback to update tab content
|
520 |
-
@app.callback(
|
521 |
-
Output('tab-content', 'children'),
|
522 |
-
Input('tabs', 'active_tab')
|
523 |
-
)
|
524 |
-
def render_tab_content(active_tab):
|
525 |
-
if active_tab == "shred":
|
526 |
-
return [
|
527 |
-
dbc.Textarea(
|
528 |
-
id='shred-instructions',
|
529 |
-
placeholder="Enter any additional instructions for shredding the document...",
|
530 |
-
style={'height': '100px', 'marginBottom': '10px'}
|
531 |
-
),
|
532 |
-
dcc.Upload(
|
533 |
-
id='upload-document',
|
534 |
-
children=html.Div(['Drag and Drop or ', html.A('Select Files')]),
|
535 |
-
style={
|
536 |
-
'width': '100%',
|
537 |
-
'height': '60px',
|
538 |
-
'lineHeight': '60px',
|
539 |
-
'borderWidth': '1px',
|
540 |
-
'borderStyle': 'dashed',
|
541 |
-
'borderRadius': '5px',
|
542 |
-
'textAlign': 'center',
|
543 |
-
'margin': '10px'
|
544 |
-
},
|
545 |
-
multiple=False
|
546 |
-
),
|
547 |
-
dbc.Spinner(html.Div(id='shred-output')),
|
548 |
-
dbc.Button("Download Outline", id="download-shred", className="mt-3"),
|
549 |
-
dcc.Download(id="download-shred-doc")
|
550 |
-
]
|
551 |
-
elif active_tab == "pink":
|
552 |
-
return [
|
553 |
-
dbc.Textarea(
|
554 |
-
id='pink-instructions',
|
555 |
-
placeholder="Enter any additional instructions for generating the Pink Team document...",
|
556 |
-
style={'height': '100px', 'marginBottom': '10px'}
|
557 |
-
),
|
558 |
-
dbc.Button("Generate Pink Team Document", id="generate-pink", className="mt-3"),
|
559 |
-
dbc.Spinner(html.Div(id='pink-output')),
|
560 |
-
dbc.Button("Download Pink Team Document", id="download-pink", className="mt-3"),
|
561 |
-
dcc.Download(id="download-pink-doc")
|
562 |
-
]
|
563 |
-
# Add similar content for other tabs...
|
564 |
-
|
565 |
-
if __name__ == '__main__':
|
566 |
-
print("Starting the Dash application...")
|
567 |
-
app.run(debug=True, host='0.0.0.0', port=7860)
|
568 |
-
print("Dash application has finished running.")
|
|
|
5 |
import time
|
6 |
from typing import List, Tuple
|
7 |
import re
|
8 |
+
import pandas as pd
|
9 |
+
|
10 |
import dash
|
11 |
import dash_bootstrap_components as dbc
|
12 |
+
from dash import html, dcc, Input, Output, State, ctx, dash_table
|
13 |
import google.generativeai as genai
|
14 |
from docx import Document
|
15 |
from PyPDF2 import PdfReader
|
|
|
327 |
State('pink-output', 'children'),
|
328 |
State('shred-output', 'children')
|
329 |
)
|
330 |
+
def update_p_review_output(n_clicks, contents, filename, pink_doc, requirements):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
331 |
if n_clicks is None:
|
332 |
return "Click 'Evaluate Compliance' to begin."
|
333 |
|
334 |
if contents:
|
335 |
document = process_document(contents, filename)
|
336 |
+
elif pink_doc:
|
337 |
+
document = pink_doc
|
338 |
else:
|
339 |
+
return "Please upload a document or generate a Pink Team document first."
|
340 |
|
341 |
compliance_report = evaluate_compliance(document, requirements)
|
342 |
return dcc.Markdown(compliance_report)
|
343 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
344 |
@app.callback(
|
345 |
Output('g-review-output', 'children'),
|
346 |
Input('evaluate-g-review', 'n_clicks'),
|
|
|
359 |
compliance_report = evaluate_compliance(document, requirements)
|
360 |
return dcc.Markdown(compliance_report)
|
361 |
|
|
|
362 |
@app.callback(
|
363 |
+
Output('loe-output', 'children'),
|
364 |
+
Input('generate-loe', 'n_clicks'),
|
365 |
+
State('shred-output', 'children')
|
366 |
)
|
367 |
+
def update_loe_output(n_clicks, shred_output):
|
368 |
+
if n_clicks is None:
|
369 |
+
return "Click 'Generate LOE' to begin."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
370 |
|
371 |
if shred_output is None:
|
372 |
+
return "Please complete the Sh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|