Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -40,7 +40,7 @@ def process_document(contents: str, filename: str) -> str:
|
|
40 |
def generate_outline(text: str, instructions: str) -> str:
|
41 |
prompt = f"""
|
42 |
Analyze the following Project Work Statement (PWS) and create an outline
|
43 |
-
focusing on
|
44 |
requirements in each section. Pay special attention to requirements indicated
|
45 |
by words like "shall", "will", "must", and similar imperative language.
|
46 |
|
@@ -77,6 +77,49 @@ def generate_pink_team_document(outline: str, instructions: str) -> str:
|
|
77 |
response = model.generate_content(prompt)
|
78 |
return response.text
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
# Layout
|
81 |
app.layout = dbc.Container([
|
82 |
html.H1("MicroHealth PWS Analysis and Response Generator", className="my-4"),
|
@@ -117,6 +160,69 @@ app.layout = dbc.Container([
|
|
117 |
dbc.Button("Download Pink Team Document", id="download-pink", className="mt-3"),
|
118 |
dcc.Download(id="download-pink-doc")
|
119 |
]),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
], id="tabs", active_tab="shred"),
|
121 |
])
|
122 |
|
@@ -147,6 +253,71 @@ def update_pink_output(n_clicks, shred_output, instructions):
|
|
147 |
pink_doc = generate_pink_team_document(shred_output, instructions or "")
|
148 |
return dcc.Markdown(pink_doc)
|
149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
@app.callback(
|
151 |
Output("download-shred-doc", "data"),
|
152 |
Input("download-shred", "n_clicks"),
|
@@ -169,6 +340,39 @@ def download_pink(n_clicks, pink_output):
|
|
169 |
return dash.no_update
|
170 |
return dict(content=pink_output, filename="pink_team_document.md")
|
171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
if __name__ == '__main__':
|
173 |
print("Starting the Dash application...")
|
174 |
app.run(debug=True, host='0.0.0.0', port=7860)
|
|
|
40 |
def generate_outline(text: str, instructions: str) -> str:
|
41 |
prompt = f"""
|
42 |
Analyze the following Project Work Statement (PWS) and create an outline
|
43 |
+
focusing on sections L&M. Extract the main headers, subheaders, and specific
|
44 |
requirements in each section. Pay special attention to requirements indicated
|
45 |
by words like "shall", "will", "must", and similar imperative language.
|
46 |
|
|
|
77 |
response = model.generate_content(prompt)
|
78 |
return response.text
|
79 |
|
80 |
+
def evaluate_compliance(document: str, requirements: str) -> str:
|
81 |
+
prompt = f"""
|
82 |
+
Evaluate the following document against the requirements from sections L&M of the PWS:
|
83 |
+
|
84 |
+
Document:
|
85 |
+
{document}
|
86 |
+
|
87 |
+
Requirements:
|
88 |
+
{requirements}
|
89 |
+
|
90 |
+
Provide a compliance report by section number, highlighting:
|
91 |
+
1. Areas that need improvement
|
92 |
+
2. Suggestions on how MicroHealth can better respond to the requirements
|
93 |
+
3. Best industry practices that should be applied
|
94 |
+
4. Measurable outcomes that should be included
|
95 |
+
|
96 |
+
Format the report clearly by section number.
|
97 |
+
"""
|
98 |
+
response = model.generate_content(prompt)
|
99 |
+
return response.text
|
100 |
+
|
101 |
+
def generate_red_document(document: str, compliance_report: str) -> str:
|
102 |
+
prompt = f"""
|
103 |
+
Based on the following document and compliance report:
|
104 |
+
|
105 |
+
Original Document:
|
106 |
+
{document}
|
107 |
+
|
108 |
+
Compliance Report:
|
109 |
+
{compliance_report}
|
110 |
+
|
111 |
+
Generate a revised "Red Team" document that addresses all issues found in the compliance report.
|
112 |
+
Ensure that the new document:
|
113 |
+
1. Responds to all requirements with sufficient detail
|
114 |
+
2. Explains how MicroHealth will implement solutions
|
115 |
+
3. Incorporates best industry practices
|
116 |
+
4. Includes measurable outcomes for each requirement
|
117 |
+
|
118 |
+
Provide the revised document in a clear, structured format.
|
119 |
+
"""
|
120 |
+
response = model.generate_content(prompt)
|
121 |
+
return response.text
|
122 |
+
|
123 |
# Layout
|
124 |
app.layout = dbc.Container([
|
125 |
html.H1("MicroHealth PWS Analysis and Response Generator", className="my-4"),
|
|
|
160 |
dbc.Button("Download Pink Team Document", id="download-pink", className="mt-3"),
|
161 |
dcc.Download(id="download-pink-doc")
|
162 |
]),
|
163 |
+
dbc.Tab(label="P.Review", tab_id="p-review", children=[
|
164 |
+
dcc.Upload(
|
165 |
+
id='upload-p-review',
|
166 |
+
children=html.Div(['Drag and Drop or ', html.A('Select Files')]),
|
167 |
+
style={
|
168 |
+
'width': '100%',
|
169 |
+
'height': '60px',
|
170 |
+
'lineHeight': '60px',
|
171 |
+
'borderWidth': '1px',
|
172 |
+
'borderStyle': 'dashed',
|
173 |
+
'borderRadius': '5px',
|
174 |
+
'textAlign': 'center',
|
175 |
+
'margin': '10px'
|
176 |
+
},
|
177 |
+
multiple=False
|
178 |
+
),
|
179 |
+
dbc.Button("Evaluate Compliance", id="evaluate-p-review", className="mt-3"),
|
180 |
+
dbc.Spinner(html.Div(id='p-review-output')),
|
181 |
+
dbc.Button("Download P.Review Report", id="download-p-review", className="mt-3"),
|
182 |
+
dcc.Download(id="download-p-review-doc")
|
183 |
+
]),
|
184 |
+
dbc.Tab(label="Red", tab_id="red", children=[
|
185 |
+
dcc.Upload(
|
186 |
+
id='upload-red',
|
187 |
+
children=html.Div(['Drag and Drop or ', html.A('Select Files')]),
|
188 |
+
style={
|
189 |
+
'width': '100%',
|
190 |
+
'height': '60px',
|
191 |
+
'lineHeight': '60px',
|
192 |
+
'borderWidth': '1px',
|
193 |
+
'borderStyle': 'dashed',
|
194 |
+
'borderRadius': '5px',
|
195 |
+
'textAlign': 'center',
|
196 |
+
'margin': '10px'
|
197 |
+
},
|
198 |
+
multiple=False
|
199 |
+
),
|
200 |
+
dbc.Button("Generate Red Team Document", id="generate-red", className="mt-3"),
|
201 |
+
dbc.Spinner(html.Div(id='red-output')),
|
202 |
+
dbc.Button("Download Red Team Document", id="download-red", className="mt-3"),
|
203 |
+
dcc.Download(id="download-red-doc")
|
204 |
+
]),
|
205 |
+
dbc.Tab(label="R.Review", tab_id="r-review", children=[
|
206 |
+
dcc.Upload(
|
207 |
+
id='upload-r-review',
|
208 |
+
children=html.Div(['Drag and Drop or ', html.A('Select Files')]),
|
209 |
+
style={
|
210 |
+
'width': '100%',
|
211 |
+
'height': '60px',
|
212 |
+
'lineHeight': '60px',
|
213 |
+
'borderWidth': '1px',
|
214 |
+
'borderStyle': 'dashed',
|
215 |
+
'borderRadius': '5px',
|
216 |
+
'textAlign': 'center',
|
217 |
+
'margin': '10px'
|
218 |
+
},
|
219 |
+
multiple=False
|
220 |
+
),
|
221 |
+
dbc.Button("Evaluate Compliance", id="evaluate-r-review", className="mt-3"),
|
222 |
+
dbc.Spinner(html.Div(id='r-review-output')),
|
223 |
+
dbc.Button("Download R.Review Report", id="download-r-review", className="mt-3"),
|
224 |
+
dcc.Download(id="download-r-review-doc")
|
225 |
+
]),
|
226 |
], id="tabs", active_tab="shred"),
|
227 |
])
|
228 |
|
|
|
253 |
pink_doc = generate_pink_team_document(shred_output, instructions or "")
|
254 |
return dcc.Markdown(pink_doc)
|
255 |
|
256 |
+
@app.callback(
|
257 |
+
Output('p-review-output', 'children'),
|
258 |
+
Input('evaluate-p-review', 'n_clicks'),
|
259 |
+
State('upload-p-review', 'contents'),
|
260 |
+
State('upload-p-review', 'filename'),
|
261 |
+
State('pink-output', 'children'),
|
262 |
+
State('shred-output', 'children')
|
263 |
+
)
|
264 |
+
def update_p_review_output(n_clicks, contents, filename, pink_doc, requirements):
|
265 |
+
if n_clicks is None:
|
266 |
+
return "Click 'Evaluate Compliance' to begin."
|
267 |
+
|
268 |
+
if contents:
|
269 |
+
document = process_document(contents, filename)
|
270 |
+
elif pink_doc:
|
271 |
+
document = pink_doc
|
272 |
+
else:
|
273 |
+
return "Please upload a document or generate a Pink Team document first."
|
274 |
+
|
275 |
+
compliance_report = evaluate_compliance(document, requirements)
|
276 |
+
return dcc.Markdown(compliance_report)
|
277 |
+
|
278 |
+
@app.callback(
|
279 |
+
Output('red-output', 'children'),
|
280 |
+
Input('generate-red', 'n_clicks'),
|
281 |
+
State('upload-red', 'contents'),
|
282 |
+
State('upload-red', 'filename'),
|
283 |
+
State('p-review-output', 'children')
|
284 |
+
)
|
285 |
+
def update_red_output(n_clicks, contents, filename, p_review_output):
|
286 |
+
if n_clicks is None:
|
287 |
+
return "Click 'Generate Red Team Document' to begin."
|
288 |
+
|
289 |
+
if contents:
|
290 |
+
document = process_document(contents, filename)
|
291 |
+
elif p_review_output:
|
292 |
+
document = p_review_output
|
293 |
+
else:
|
294 |
+
return "Please upload a document or complete the P.Review first."
|
295 |
+
|
296 |
+
red_doc = generate_red_document(document, p_review_output)
|
297 |
+
return dcc.Markdown(red_doc)
|
298 |
+
|
299 |
+
@app.callback(
|
300 |
+
Output('r-review-output', 'children'),
|
301 |
+
Input('evaluate-r-review', 'n_clicks'),
|
302 |
+
State('upload-r-review', 'contents'),
|
303 |
+
State('upload-r-review', 'filename'),
|
304 |
+
State('red-output', 'children'),
|
305 |
+
State('shred-output', 'children')
|
306 |
+
)
|
307 |
+
def update_r_review_output(n_clicks, contents, filename, red_doc, requirements):
|
308 |
+
if n_clicks is None:
|
309 |
+
return "Click 'Evaluate Compliance' to begin."
|
310 |
+
|
311 |
+
if contents:
|
312 |
+
document = process_document(contents, filename)
|
313 |
+
elif red_doc:
|
314 |
+
document = red_doc
|
315 |
+
else:
|
316 |
+
return "Please upload a document or generate a Red Team document first."
|
317 |
+
|
318 |
+
compliance_report = evaluate_compliance(document, requirements)
|
319 |
+
return dcc.Markdown(compliance_report)
|
320 |
+
|
321 |
@app.callback(
|
322 |
Output("download-shred-doc", "data"),
|
323 |
Input("download-shred", "n_clicks"),
|
|
|
340 |
return dash.no_update
|
341 |
return dict(content=pink_output, filename="pink_team_document.md")
|
342 |
|
343 |
+
@app.callback(
|
344 |
+
Output("download-p-review-doc", "data"),
|
345 |
+
Input("download-p-review", "n_clicks"),
|
346 |
+
State('p-review-output', 'children'),
|
347 |
+
prevent_initial_call=True,
|
348 |
+
)
|
349 |
+
def download_p_review(n_clicks, p_review_output):
|
350 |
+
if p_review_output is None:
|
351 |
+
return dash.no_update
|
352 |
+
return dict(content=p_review_output, filename="p_review_report.md")
|
353 |
+
|
354 |
+
@app.callback(
|
355 |
+
Output("download-red-doc", "data"),
|
356 |
+
Input("download-red", "n_clicks"),
|
357 |
+
State('red-output', 'children'),
|
358 |
+
prevent_initial_call=True,
|
359 |
+
)
|
360 |
+
def download_red(n_clicks, red_output):
|
361 |
+
if red_output is None:
|
362 |
+
return dash.no_update
|
363 |
+
return dict(content=red_output, filename="red_team_document.md")
|
364 |
+
|
365 |
+
@app.callback(
|
366 |
+
Output("download-r-review-doc", "data"),
|
367 |
+
Input("download-r-review", "n_clicks"),
|
368 |
+
State('r-review-output', 'children'),
|
369 |
+
prevent_initial_call=True,
|
370 |
+
)
|
371 |
+
def download_r_review(n_clicks, r_review_output):
|
372 |
+
if r_review_output is None:
|
373 |
+
return dash.no_update
|
374 |
+
return dict(content=r_review_output, filename="r_review_report.md")
|
375 |
+
|
376 |
if __name__ == '__main__':
|
377 |
print("Starting the Dash application...")
|
378 |
app.run(debug=True, host='0.0.0.0', port=7860)
|