Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -76,6 +76,7 @@ def generate_pink_team_document(outline: str, instructions: str) -> str:
|
|
| 76 |
4. Provide measurable outcomes for the customer.
|
| 77 |
5. Limit the use of bullet points and write predominantly in paragraph format.
|
| 78 |
6. Ensure a logical flow of steps taken by MicroHealth for each requirement.
|
|
|
|
| 79 |
|
| 80 |
Generate a comprehensive response that showcases MicroHealth's expertise and approach.
|
| 81 |
"""
|
|
@@ -122,10 +123,7 @@ def generate_red_document(document: str, compliance_report: str) -> str:
|
|
| 122 |
4. Provide measurable outcomes for the customer.
|
| 123 |
5. Limit the use of bullet points and write predominantly in paragraph format.
|
| 124 |
6. Ensure a logical flow of steps taken by MicroHealth for each requirement.
|
| 125 |
-
|
| 126 |
-
Provide the revised document in a clear, structured format using paragraphs.
|
| 127 |
-
Limit the use of bullet points and write predominantly in paragraph format.
|
| 128 |
-
Ensure a logical flow of steps taken by MicroHealth for each requirement.
|
| 129 |
"""
|
| 130 |
response = model.generate_content(prompt)
|
| 131 |
return response.text
|
|
@@ -158,22 +156,25 @@ def generate_loe(document: str, is_file: bool = False) -> Tuple[str, pd.DataFram
|
|
| 158 |
Ensure the table is properly formatted with | as column separators and a header row.
|
| 159 |
"""
|
| 160 |
response = model.generate_content(prompt)
|
|
|
|
| 161 |
|
| 162 |
# Extract the table from the response
|
| 163 |
-
table_start =
|
| 164 |
-
table_end =
|
| 165 |
-
table_text =
|
| 166 |
|
| 167 |
# Convert the table to a pandas DataFrame
|
| 168 |
try:
|
|
|
|
|
|
|
| 169 |
df = pd.read_csv(StringIO(table_text), sep='|', skipinitialspace=True).dropna(axis=1, how='all')
|
| 170 |
df.columns = df.columns.str.strip()
|
| 171 |
except pd.errors.EmptyDataError:
|
| 172 |
# If no table is found or it's empty, create a default DataFrame
|
| 173 |
df = pd.DataFrame(columns=['Task Summary', 'Labor Categories', 'Hours per Labor Category', 'Total Hours'])
|
| 174 |
-
|
| 175 |
|
| 176 |
-
return
|
| 177 |
|
| 178 |
# Layout
|
| 179 |
app.layout = dbc.Container([
|
|
@@ -400,23 +401,26 @@ def update_loe_output(n_clicks, upload_contents, shred_output):
|
|
| 400 |
if n_clicks is None:
|
| 401 |
return "Click 'Generate LOE' to begin."
|
| 402 |
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
|
|
|
|
|
|
|
|
|
| 420 |
|
| 421 |
@app.callback(
|
| 422 |
Output('red-output', 'children'),
|
|
|
|
| 76 |
4. Provide measurable outcomes for the customer.
|
| 77 |
5. Limit the use of bullet points and write predominantly in paragraph format.
|
| 78 |
6. Ensure a logical flow of steps taken by MicroHealth for each requirement.
|
| 79 |
+
7. Where applicable, describe the labor category or labor categories that perform the task as part of the process
|
| 80 |
|
| 81 |
Generate a comprehensive response that showcases MicroHealth's expertise and approach.
|
| 82 |
"""
|
|
|
|
| 123 |
4. Provide measurable outcomes for the customer.
|
| 124 |
5. Limit the use of bullet points and write predominantly in paragraph format.
|
| 125 |
6. Ensure a logical flow of steps taken by MicroHealth for each requirement.
|
| 126 |
+
7. Where applicable, describe the labor category or labor categories that perform the task as part of the process
|
|
|
|
|
|
|
|
|
|
| 127 |
"""
|
| 128 |
response = model.generate_content(prompt)
|
| 129 |
return response.text
|
|
|
|
| 156 |
Ensure the table is properly formatted with | as column separators and a header row.
|
| 157 |
"""
|
| 158 |
response = model.generate_content(prompt)
|
| 159 |
+
response_text = response.text
|
| 160 |
|
| 161 |
# Extract the table from the response
|
| 162 |
+
table_start = response_text.find("| Task Summary |")
|
| 163 |
+
table_end = response_text.find("\n\n", table_start)
|
| 164 |
+
table_text = response_text[table_start:table_end]
|
| 165 |
|
| 166 |
# Convert the table to a pandas DataFrame
|
| 167 |
try:
|
| 168 |
+
if not table_text.strip():
|
| 169 |
+
raise pd.errors.EmptyDataError("No table found in the response")
|
| 170 |
df = pd.read_csv(StringIO(table_text), sep='|', skipinitialspace=True).dropna(axis=1, how='all')
|
| 171 |
df.columns = df.columns.str.strip()
|
| 172 |
except pd.errors.EmptyDataError:
|
| 173 |
# If no table is found or it's empty, create a default DataFrame
|
| 174 |
df = pd.DataFrame(columns=['Task Summary', 'Labor Categories', 'Hours per Labor Category', 'Total Hours'])
|
| 175 |
+
response_text += "\n\nNote: No detailed LOE table could be generated from the AI response."
|
| 176 |
|
| 177 |
+
return response_text, df
|
| 178 |
|
| 179 |
# Layout
|
| 180 |
app.layout = dbc.Container([
|
|
|
|
| 401 |
if n_clicks is None:
|
| 402 |
return "Click 'Generate LOE' to begin."
|
| 403 |
|
| 404 |
+
try:
|
| 405 |
+
if upload_contents:
|
| 406 |
+
loe_text, loe_df = generate_loe(upload_contents, is_file=True)
|
| 407 |
+
elif shred_output:
|
| 408 |
+
loe_text, loe_df = generate_loe(shred_output)
|
| 409 |
+
else:
|
| 410 |
+
return "Please upload a document or complete the Shred tab first."
|
| 411 |
+
|
| 412 |
+
return [
|
| 413 |
+
dcc.Markdown(loe_text),
|
| 414 |
+
dash_table.DataTable(
|
| 415 |
+
data=loe_df.to_dict('records'),
|
| 416 |
+
columns=[{'name': i, 'id': i} for i in loe_df.columns],
|
| 417 |
+
style_table={'overflowX': 'auto'},
|
| 418 |
+
style_cell={'textAlign': 'left', 'padding': '5px'},
|
| 419 |
+
style_header={'backgroundColor': 'rgb(230, 230, 230)', 'fontWeight': 'bold'}
|
| 420 |
+
)
|
| 421 |
+
]
|
| 422 |
+
except Exception as e:
|
| 423 |
+
return f"An error occurred: {str(e)}"
|
| 424 |
|
| 425 |
@app.callback(
|
| 426 |
Output('red-output', 'children'),
|