Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -45,19 +45,12 @@ def process_document(contents: str, filename: str) -> str:
|
|
45 |
except Exception as e:
|
46 |
return f"Error processing document: {str(e)}"
|
47 |
|
48 |
-
def generate_loe(document: str, is_file: bool = False
|
49 |
-
if is_file:
|
50 |
-
document_text = process_document(document, filename)
|
51 |
-
if document_text.startswith("Unsupported file format") or document_text.startswith("Error processing document"):
|
52 |
-
return document_text, pd.DataFrame()
|
53 |
-
else:
|
54 |
-
document_text = document
|
55 |
-
|
56 |
prompt = f"""
|
57 |
Analyze the following document and provide a Level of Effort (LOE) breakdown:
|
58 |
|
59 |
Document:
|
60 |
-
{
|
61 |
|
62 |
For each section header in the document:
|
63 |
1. Identify the tasks to be completed
|
@@ -93,6 +86,19 @@ def generate_loe(document: str, is_file: bool = False, filename: str = "") -> Tu
|
|
93 |
response_text += "\n\nNote: No detailed LOE table could be generated from the AI response."
|
94 |
|
95 |
return response_text, df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
def generate_outline(text: str, instructions: str) -> str:
|
98 |
prompt = f"""
|
@@ -129,6 +135,9 @@ def generate_pink_team_document(outline: str, instructions: str) -> str:
|
|
129 |
5. Limit the use of bullet points and write predominantly in paragraph format.
|
130 |
6. Ensure a logical flow of steps taken by MicroHealth for each requirement.
|
131 |
7. Where applicable, describe the labor category or labor categories that perform the task as part of the process
|
|
|
|
|
|
|
132 |
|
133 |
Generate a comprehensive response that showcases MicroHealth's expertise and approach.
|
134 |
"""
|
@@ -178,7 +187,10 @@ def generate_red_document(document: str, compliance_report: str, instructions: s
|
|
178 |
5. Limit the use of bullet points and write predominantly in paragraph format.
|
179 |
6. Ensure a logical flow of steps taken by MicroHealth for each requirement.
|
180 |
7. Where applicable, describe the labor category or labor categories that perform the task as part of the process
|
181 |
-
8.
|
|
|
|
|
|
|
182 |
"""
|
183 |
response = model.generate_content(prompt)
|
184 |
return response.text
|
@@ -690,15 +702,15 @@ def update_loe_output(n_clicks, upload_contents, upload_filename, shred_output):
|
|
690 |
try:
|
691 |
if triggered_id in ['generate-loe', 'upload-loe']:
|
692 |
if upload_contents:
|
693 |
-
|
|
|
|
|
|
|
694 |
elif shred_output:
|
695 |
loe_text, loe_df = generate_loe(shred_output)
|
696 |
else:
|
697 |
return "Please upload a document or complete the Shred tab first."
|
698 |
|
699 |
-
if isinstance(loe_text, str) and loe_text.startswith(("Unsupported file format", "Error processing document")):
|
700 |
-
return loe_text
|
701 |
-
|
702 |
return [
|
703 |
dcc.Markdown(loe_text),
|
704 |
dash_table.DataTable(
|
|
|
45 |
except Exception as e:
|
46 |
return f"Error processing document: {str(e)}"
|
47 |
|
48 |
+
def generate_loe(document: str, is_file: bool = False) -> Tuple[str, pd.DataFrame]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
prompt = f"""
|
50 |
Analyze the following document and provide a Level of Effort (LOE) breakdown:
|
51 |
|
52 |
Document:
|
53 |
+
{document}
|
54 |
|
55 |
For each section header in the document:
|
56 |
1. Identify the tasks to be completed
|
|
|
86 |
response_text += "\n\nNote: No detailed LOE table could be generated from the AI response."
|
87 |
|
88 |
return response_text, df
|
89 |
+
|
90 |
+
# Convert the table to a pandas DataFrame
|
91 |
+
try:
|
92 |
+
if not table_text.strip():
|
93 |
+
raise pd.errors.EmptyDataError("No table found in the response")
|
94 |
+
df = pd.read_csv(StringIO(table_text), sep='|', skipinitialspace=True).dropna(axis=1, how='all')
|
95 |
+
df.columns = df.columns.str.strip()
|
96 |
+
except pd.errors.EmptyDataError:
|
97 |
+
# If no table is found or it's empty, create a default DataFrame
|
98 |
+
df = pd.DataFrame(columns=['Task Summary', 'Labor Categories', 'Hours per Labor Category', 'Total Hours'])
|
99 |
+
response_text += "\n\nNote: No detailed LOE table could be generated from the AI response."
|
100 |
+
|
101 |
+
return response_text, df
|
102 |
|
103 |
def generate_outline(text: str, instructions: str) -> str:
|
104 |
prompt = f"""
|
|
|
135 |
5. Limit the use of bullet points and write predominantly in paragraph format.
|
136 |
6. Ensure a logical flow of steps taken by MicroHealth for each requirement.
|
137 |
7. Where applicable, describe the labor category or labor categories that perform the task as part of the process
|
138 |
+
8. Analyze the given requirement for MicroHealth and describe the proposed solution, incorporating relevant industry best practices.
|
139 |
+
9. Then, provide a detailed explanation of the implementation process, including a step-by-step workflow and any necessary procedures.
|
140 |
+
10. Conclude by briefly outlining the benefits and measurable outcomes of this approach, citing relevant research to support your claims.
|
141 |
|
142 |
Generate a comprehensive response that showcases MicroHealth's expertise and approach.
|
143 |
"""
|
|
|
187 |
5. Limit the use of bullet points and write predominantly in paragraph format.
|
188 |
6. Ensure a logical flow of steps taken by MicroHealth for each requirement.
|
189 |
7. Where applicable, describe the labor category or labor categories that perform the task as part of the process
|
190 |
+
8. Analyze the given requirement for MicroHealth and describe the proposed solution, incorporating relevant industry best practices.
|
191 |
+
9. Then, provide a detailed explanation of the implementation process, including a step-by-step workflow and any necessary procedures.
|
192 |
+
10. Conclude by briefly outlining the benefits and measurable outcomes of this approach, citing relevant research to support your claims.
|
193 |
+
|
194 |
"""
|
195 |
response = model.generate_content(prompt)
|
196 |
return response.text
|
|
|
702 |
try:
|
703 |
if triggered_id in ['generate-loe', 'upload-loe']:
|
704 |
if upload_contents:
|
705 |
+
document = process_document(upload_contents, upload_filename)
|
706 |
+
if document.startswith("Unsupported file format") or document.startswith("Error processing document"):
|
707 |
+
return document
|
708 |
+
loe_text, loe_df = generate_loe(document)
|
709 |
elif shred_output:
|
710 |
loe_text, loe_df = generate_loe(shred_output)
|
711 |
else:
|
712 |
return "Please upload a document or complete the Shred tab first."
|
713 |
|
|
|
|
|
|
|
714 |
return [
|
715 |
dcc.Markdown(loe_text),
|
716 |
dash_table.DataTable(
|