Neom99 commited on
Commit
4a36a64
·
verified ·
1 Parent(s): e7905be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -27
app.py CHANGED
@@ -277,6 +277,7 @@ def generate_summary_html_by_category(df):
277
  Generates HTML summary blocks for each unique category in the DataFrame,
278
  following the user's desired executive summary format.
279
  Splits multi-line text into bullet points.
 
280
  """
281
  if df.empty or 'Category' not in df.columns:
282
  return "<p style='color:orange;'>No categories found or data is empty for detailed summarization. This could be due to issues with the AI's output parsing or content generation.</p>"
@@ -290,7 +291,11 @@ def generate_summary_html_by_category(df):
290
  df[col] = 'N/A'
291
  if col == 'Count': df[col] = 0
292
 
293
- for category, category_df in df.groupby('Category'):
 
 
 
 
294
  total_count = category_df['Count'].sum()
295
 
296
  # --- Issue Description (Summary) ---
@@ -339,24 +344,34 @@ def generate_summary_html_by_category(df):
339
  resolution_steps = f"<ul style='margin-top: 5px; margin-bottom: 5px;'>{''.join(resolution_steps_list)}</ul>" if resolution_steps_list else "<p>No specific steps identified.</p>"
340
 
341
 
342
- # --- Future Prediction & Proactive Measures ---
343
- prediction_and_proactive_list = []
344
  for pred_text in category_df['Future Prediction'].astype(str).drop_duplicates().tolist():
345
- # Use regex to split based on potential bullet patterns or just newlines
346
  lines = re.split(r'\s*[\*\-]\s*|\s*\n\s*', pred_text)
347
  for line in lines:
348
  line = line.strip()
349
  if line and line.lower() != 'n/a':
350
- prediction_and_proactive_list.append(f"<li><strong style='color: #8D6E63;'>Future Prediction:</strong> {line}</li>")
 
 
351
  for proactive_text in category_df['Proactive Measures'].astype(str).drop_duplicates().tolist():
352
- # Use regex to split based on potential bullet patterns or just newlines
353
  lines = re.split(r'\s*[\*\-]\s*|\s*\n\s*', proactive_text)
354
  for line in lines:
355
  line = line.strip()
356
  if line and line.lower() != 'n/a':
357
- prediction_and_proactive_list.append(f"<li><strong style='color: #8D6E63;'>Proactive Measures:</strong> {line}</li>")
 
 
 
 
 
358
 
359
- prediction_and_proactive = f"<ul style='margin-top: 5px; margin-bottom: 5px;'>{''.join(prediction_and_proactive_list)}</ul>" if prediction_and_proactive_list else "<p>No future prediction or proactive measures identified.</p>"
 
 
 
 
 
360
 
361
 
362
  summary_html += f"""
@@ -376,7 +391,7 @@ def generate_summary_html_by_category(df):
376
  {resolution_steps}
377
 
378
  <p style="font-weight: bold; color: #555; margin-bottom: 5px;">Future Prediction & Proactive Measures:</p>
379
- {prediction_and_proactive}
380
  </div>
381
  """
382
  return summary_html
@@ -1016,9 +1031,11 @@ def generate_docx_report(selected_timezone):
1016
  doc.add_heading("Aggregated Issue Summaries", level=2)
1017
  doc.add_paragraph("")
1018
 
1019
- # Ensure required columns are present (handled in generate_summary_html_by_category)
1020
-
1021
- for category, category_df in df.groupby('Category'):
 
 
1022
  total_count = category_df['Count'].sum()
1023
 
1024
  cat_heading = doc.add_heading(f"{category} ({total_count})", level=3)
@@ -1084,32 +1101,39 @@ def generate_docx_report(selected_timezone):
1084
  doc.add_paragraph("• No specific steps identified.", style='List Bullet')
1085
  doc.add_paragraph("")
1086
 
1087
- doc.add_paragraph("Future Prediction & Proactive Measures:").runs[0].bold = True
1088
- prediction_and_proactive_items = []
1089
-
1090
  for pred_text in category_df['Future Prediction'].astype(str).drop_duplicates().tolist():
1091
- # Use regex to split based on potential bullet patterns or just newlines
1092
  lines = re.split(r'\s*[\*\-]\s*|\s*\n\s*', pred_text)
1093
  for line in lines:
1094
  line = line.strip()
1095
  if line and line.lower() != 'n/a':
1096
- prediction_and_proactive_items.append(f"Future Prediction: {line}")
1097
-
 
 
 
 
 
 
 
 
 
1098
  for proactive_text in category_df['Proactive Measures'].astype(str).drop_duplicates().tolist():
1099
- # Use regex to split based on potential bullet patterns or just newlines
1100
  lines = re.split(r'\s*[\*\-]\s*|\s*\n\s*', proactive_text)
1101
  for line in lines:
1102
  line = line.strip()
1103
  if line and line.lower() != 'n/a':
1104
- prediction_and_proactive_items.append(f"Proactive Measures: {line}")
1105
-
1106
- if prediction_and_proactive_items:
1107
- for item in prediction_and_proactive_items:
1108
  doc.add_paragraph(f"• {item}", style='List Bullet')
1109
  else:
1110
- doc.add_paragraph("• No future prediction or proactive measures identified.", style='List Bullet')
1111
  doc.add_paragraph("")
1112
 
 
1113
  doc.add_heading("Disclaimer", level=2)
1114
  doc.add_paragraph(
1115
  "*Note: AI-generated insights, especially 'Root Cause', 'Future Prediction', and 'Proactive Measures', are inferred based on the provided ticket descriptions. "
@@ -1194,9 +1218,10 @@ with gr.Blocks(theme=gr.themes.Soft(), css="""
1194
  * Bullet points of AI-inferred underlying reasons for the issues.
1195
  * **Resolution Steps:**
1196
  * Bullet points of strategic steps to resolve issues.
1197
- * **Future Prediction & Proactive Measures:**
1198
- * Combined predictions if issues aren't fixed.
1199
- * Preventive steps.
 
1200
  """
1201
  )
1202
 
 
277
  Generates HTML summary blocks for each unique category in the DataFrame,
278
  following the user's desired executive summary format.
279
  Splits multi-line text into bullet points.
280
+ Categories are sorted from max to min count.
281
  """
282
  if df.empty or 'Category' not in df.columns:
283
  return "<p style='color:orange;'>No categories found or data is empty for detailed summarization. This could be due to issues with the AI's output parsing or content generation.</p>"
 
291
  df[col] = 'N/A'
292
  if col == 'Count': df[col] = 0
293
 
294
+ # Group by category, sum the counts, and then sort by count in descending order
295
+ category_counts = df.groupby('Category')['Count'].sum().sort_values(ascending=False)
296
+
297
+ for category in category_counts.index: # Iterate through categories in sorted order (max to min count)
298
+ category_df = df[df['Category'] == category] # Get the DataFrame for the current category
299
  total_count = category_df['Count'].sum()
300
 
301
  # --- Issue Description (Summary) ---
 
344
  resolution_steps = f"<ul style='margin-top: 5px; margin-bottom: 5px;'>{''.join(resolution_steps_list)}</ul>" if resolution_steps_list else "<p>No specific steps identified.</p>"
345
 
346
 
347
+ # --- Future Prediction & Proactive Measures (Revised) ---
348
+ future_prediction_html_list = []
349
  for pred_text in category_df['Future Prediction'].astype(str).drop_duplicates().tolist():
 
350
  lines = re.split(r'\s*[\*\-]\s*|\s*\n\s*', pred_text)
351
  for line in lines:
352
  line = line.strip()
353
  if line and line.lower() != 'n/a':
354
+ future_prediction_html_list.append(f"<li>{line}</li>")
355
+
356
+ proactive_measures_html_list = []
357
  for proactive_text in category_df['Proactive Measures'].astype(str).drop_duplicates().tolist():
 
358
  lines = re.split(r'\s*[\*\-]\s*|\s*\n\s*', proactive_text)
359
  for line in lines:
360
  line = line.strip()
361
  if line and line.lower() != 'n/a':
362
+ proactive_measures_html_list.append(f"<li>{line}</li>")
363
+
364
+ prediction_and_proactive_html = ""
365
+ if future_prediction_html_list:
366
+ prediction_and_proactive_html += "<p style='font-weight: bold; color: #6A1B9A; margin-top: 10px; margin-bottom: 5px;'>Future Prediction:</p>"
367
+ prediction_and_proactive_html += f"<ul style='margin-top: 5px; margin-bottom: 5px;'>{''.join(future_prediction_html_list)}</ul>"
368
 
369
+ if proactive_measures_html_list:
370
+ prediction_and_proactive_html += "<p style='font-weight: bold; color: #6A1B9A; margin-top: 10px; margin-bottom: 5px;'>Proactive Measures:</p>"
371
+ prediction_and_proactive_html += f"<ul style='margin-top: 5px; margin-bottom: 5px;'>{''.join(proactive_measures_html_list)}</ul>"
372
+
373
+ if not prediction_and_proactive_html:
374
+ prediction_and_proactive_html = "<p>No future prediction or proactive measures identified.</p>"
375
 
376
 
377
  summary_html += f"""
 
391
  {resolution_steps}
392
 
393
  <p style="font-weight: bold; color: #555; margin-bottom: 5px;">Future Prediction & Proactive Measures:</p>
394
+ {prediction_and_proactive_html}
395
  </div>
396
  """
397
  return summary_html
 
1031
  doc.add_heading("Aggregated Issue Summaries", level=2)
1032
  doc.add_paragraph("")
1033
 
1034
+ # Group by category, sum the counts, and then sort by count in descending order
1035
+ category_counts = df.groupby('Category')['Count'].sum().sort_values(ascending=False)
1036
+
1037
+ for category in category_counts.index: # Iterate through categories in sorted order
1038
+ category_df = df[df['Category'] == category] # Get the DataFrame for the current category
1039
  total_count = category_df['Count'].sum()
1040
 
1041
  cat_heading = doc.add_heading(f"{category} ({total_count})", level=3)
 
1101
  doc.add_paragraph("• No specific steps identified.", style='List Bullet')
1102
  doc.add_paragraph("")
1103
 
1104
+ # --- Future Prediction (Revised for DOCX) ---
1105
+ doc.add_paragraph("Future Prediction:").runs[0].bold = True
1106
+ future_prediction_items = []
1107
  for pred_text in category_df['Future Prediction'].astype(str).drop_duplicates().tolist():
 
1108
  lines = re.split(r'\s*[\*\-]\s*|\s*\n\s*', pred_text)
1109
  for line in lines:
1110
  line = line.strip()
1111
  if line and line.lower() != 'n/a':
1112
+ future_prediction_items.append(line)
1113
+ if future_prediction_items:
1114
+ for item in future_prediction_items:
1115
+ doc.add_paragraph(f"• {item}", style='List Bullet')
1116
+ else:
1117
+ doc.add_paragraph("• No future predictions identified.", style='List Bullet')
1118
+ doc.add_paragraph("")
1119
+
1120
+ # --- Proactive Measures (Revised for DOCX) ---
1121
+ doc.add_paragraph("Proactive Measures:").runs[0].bold = True
1122
+ proactive_measures_items = []
1123
  for proactive_text in category_df['Proactive Measures'].astype(str).drop_duplicates().tolist():
 
1124
  lines = re.split(r'\s*[\*\-]\s*|\s*\n\s*', proactive_text)
1125
  for line in lines:
1126
  line = line.strip()
1127
  if line and line.lower() != 'n/a':
1128
+ proactive_measures_items.append(line)
1129
+ if proactive_measures_items:
1130
+ for item in proactive_measures_items:
 
1131
  doc.add_paragraph(f"• {item}", style='List Bullet')
1132
  else:
1133
+ doc.add_paragraph("• No proactive measures identified.", style='List Bullet')
1134
  doc.add_paragraph("")
1135
 
1136
+
1137
  doc.add_heading("Disclaimer", level=2)
1138
  doc.add_paragraph(
1139
  "*Note: AI-generated insights, especially 'Root Cause', 'Future Prediction', and 'Proactive Measures', are inferred based on the provided ticket descriptions. "
 
1218
  * Bullet points of AI-inferred underlying reasons for the issues.
1219
  * **Resolution Steps:**
1220
  * Bullet points of strategic steps to resolve issues.
1221
+ * **Future Prediction:**
1222
+ * Bullet points of predictions if issues aren't fixed.
1223
+ * **Proactive Measures:**
1224
+ * Bullet points of preventive steps.
1225
  """
1226
  )
1227