Update app.py
Browse files
app.py
CHANGED
|
@@ -19,7 +19,7 @@ from weasyprint import HTML, CSS
|
|
| 19 |
# --- End WeasyPrint import ---
|
| 20 |
|
| 21 |
from docx import Document as DocxDocument
|
| 22 |
-
from docx.shared import Inches, Pt
|
| 23 |
from docx.enum.text import WD_ALIGN_PARAGRAPH, WD_PARAGRAPH_ALIGNMENT
|
| 24 |
|
| 25 |
# --- Python Environment Diagnostics ---
|
|
@@ -1061,9 +1061,9 @@ def generate_docx_report(selected_timezone):
|
|
| 1061 |
issue_descriptions_list.append(line)
|
| 1062 |
if issue_descriptions_list:
|
| 1063 |
for item in issue_descriptions_list:
|
| 1064 |
-
doc.add_paragraph(
|
| 1065 |
else:
|
| 1066 |
-
doc.add_paragraph("
|
| 1067 |
doc.add_paragraph("")
|
| 1068 |
|
| 1069 |
# Sub-Categories
|
|
@@ -1073,10 +1073,10 @@ def generate_docx_report(selected_timezone):
|
|
| 1073 |
sub_cat_counts = category_df.groupby('Sub-Category')['Count'].sum().sort_values(ascending=False)
|
| 1074 |
for sub_cat, count in sub_cat_counts.items():
|
| 1075 |
if str(sub_cat).strip() and str(sub_cat).strip().lower() != 'n/a':
|
| 1076 |
-
doc.add_paragraph(f"
|
| 1077 |
sub_cat_found = True
|
| 1078 |
if not sub_cat_found:
|
| 1079 |
-
doc.add_paragraph("
|
| 1080 |
doc.add_paragraph("")
|
| 1081 |
|
| 1082 |
# Root Cause
|
|
@@ -1090,9 +1090,9 @@ def generate_docx_report(selected_timezone):
|
|
| 1090 |
root_causes_list.append(line)
|
| 1091 |
if root_causes_list:
|
| 1092 |
for item in root_causes_list:
|
| 1093 |
-
doc.add_paragraph(
|
| 1094 |
else:
|
| 1095 |
-
doc.add_paragraph("
|
| 1096 |
doc.add_paragraph("")
|
| 1097 |
|
| 1098 |
# Resolution Steps
|
|
@@ -1106,9 +1106,9 @@ def generate_docx_report(selected_timezone):
|
|
| 1106 |
resolution_steps_list.append(line)
|
| 1107 |
if resolution_steps_list:
|
| 1108 |
for item in resolution_steps_list:
|
| 1109 |
-
doc.add_paragraph(
|
| 1110 |
else:
|
| 1111 |
-
doc.add_paragraph("
|
| 1112 |
doc.add_paragraph("")
|
| 1113 |
|
| 1114 |
# Insights & Recommendations section
|
|
@@ -1125,9 +1125,9 @@ def generate_docx_report(selected_timezone):
|
|
| 1125 |
future_prediction_items.append(line)
|
| 1126 |
if future_prediction_items:
|
| 1127 |
for item in future_prediction_items:
|
| 1128 |
-
doc.add_paragraph(
|
| 1129 |
else:
|
| 1130 |
-
doc.add_paragraph("
|
| 1131 |
doc.add_paragraph("")
|
| 1132 |
|
| 1133 |
# Proactive Measures
|
|
@@ -1141,9 +1141,9 @@ def generate_docx_report(selected_timezone):
|
|
| 1141 |
proactive_measures_items.append(line)
|
| 1142 |
if proactive_measures_items:
|
| 1143 |
for item in proactive_measures_items:
|
| 1144 |
-
doc.add_paragraph(
|
| 1145 |
else:
|
| 1146 |
-
doc.add_paragraph("
|
| 1147 |
doc.add_paragraph("")
|
| 1148 |
|
| 1149 |
|
|
@@ -1196,11 +1196,19 @@ with gr.Blocks(theme=gr.themes.Soft(), css="""
|
|
| 1196 |
}
|
| 1197 |
h3 {
|
| 1198 |
color: #1A5276; /* Darker Blue-Green */
|
| 1199 |
-
margin-top:
|
| 1200 |
-
margin-bottom:
|
| 1201 |
font-size: 1.3em;
|
| 1202 |
font-weight: 600;
|
| 1203 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1204 |
|
| 1205 |
/* Paragraphs and list items */
|
| 1206 |
p {
|
|
@@ -1308,6 +1316,14 @@ with gr.Blocks(theme=gr.themes.Soft(), css="""
|
|
| 1308 |
overflow-y: auto; /* Enable scrolling for long logs */
|
| 1309 |
height: 120px; /* Fixed height for log box */
|
| 1310 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1311 |
""") as demo:
|
| 1312 |
gr.HTML("""
|
| 1313 |
<h1 align="center">Advanced AI Customer Ticket Analyst</h1>
|
|
@@ -1321,12 +1337,12 @@ with gr.Blocks(theme=gr.themes.Soft(), css="""
|
|
| 1321 |
|
| 1322 |
---
|
| 1323 |
|
| 1324 |
-
####
|
| 1325 |
AI-generated insights, including inferred root causes, future predictions, and proactive measures, are based on the provided ticket data. These analyses are intended for guidance and require human expert validation for critical business decisions.
|
| 1326 |
|
| 1327 |
---
|
| 1328 |
|
| 1329 |
-
####
|
| 1330 |
* **Supported Formats:** `.xlsx` (Excel), `.xls` (Legacy Excel), and `.csv` (Comma Separated Values).
|
| 1331 |
* **Data Structure:** Files must contain tabular data with clear headers in the first row. Each row represents an individual customer ticket.
|
| 1332 |
* **Minimum Columns:** A minimum of two columns are recommended: one for a unique `Ticket ID` (or `ID`) and one for the `Issue` (or `Description`).
|
|
@@ -1342,7 +1358,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css="""
|
|
| 1342 |
|
| 1343 |
---
|
| 1344 |
|
| 1345 |
-
####
|
| 1346 |
The AI will generate a clear, data-driven report based solely on your uploaded file. The visual output will feature:
|
| 1347 |
* **Category Name (Total Count for Category)**
|
| 1348 |
* **Summary:** Key issue descriptions and common themes.
|
|
|
|
| 19 |
# --- End WeasyPrint import ---
|
| 20 |
|
| 21 |
from docx import Document as DocxDocument
|
| 22 |
+
from docx.shared import Inches, Pt, RGBColor
|
| 23 |
from docx.enum.text import WD_ALIGN_PARAGRAPH, WD_PARAGRAPH_ALIGNMENT
|
| 24 |
|
| 25 |
# --- Python Environment Diagnostics ---
|
|
|
|
| 1061 |
issue_descriptions_list.append(line)
|
| 1062 |
if issue_descriptions_list:
|
| 1063 |
for item in issue_descriptions_list:
|
| 1064 |
+
doc.add_paragraph(item, style='List Bullet') # FIX: Removed "• "
|
| 1065 |
else:
|
| 1066 |
+
doc.add_paragraph("No specific summary available.", style='List Bullet') # FIX: Removed "• "
|
| 1067 |
doc.add_paragraph("")
|
| 1068 |
|
| 1069 |
# Sub-Categories
|
|
|
|
| 1073 |
sub_cat_counts = category_df.groupby('Sub-Category')['Count'].sum().sort_values(ascending=False)
|
| 1074 |
for sub_cat, count in sub_cat_counts.items():
|
| 1075 |
if str(sub_cat).strip() and str(sub_cat).strip().lower() != 'n/a':
|
| 1076 |
+
doc.add_paragraph(f"{sub_cat} (Count: {count})", style='List Bullet') # FIX: Removed "• "
|
| 1077 |
sub_cat_found = True
|
| 1078 |
if not sub_cat_found:
|
| 1079 |
+
doc.add_paragraph("No sub-categories identified.", style='List Bullet') # FIX: Removed "• "
|
| 1080 |
doc.add_paragraph("")
|
| 1081 |
|
| 1082 |
# Root Cause
|
|
|
|
| 1090 |
root_causes_list.append(line)
|
| 1091 |
if root_causes_list:
|
| 1092 |
for item in root_causes_list:
|
| 1093 |
+
doc.add_paragraph(item, style='List Bullet') # FIX: Removed "• "
|
| 1094 |
else:
|
| 1095 |
+
doc.add_paragraph("Undetermined.", style='List Bullet') # FIX: Removed "• "
|
| 1096 |
doc.add_paragraph("")
|
| 1097 |
|
| 1098 |
# Resolution Steps
|
|
|
|
| 1106 |
resolution_steps_list.append(line)
|
| 1107 |
if resolution_steps_list:
|
| 1108 |
for item in resolution_steps_list:
|
| 1109 |
+
doc.add_paragraph(item, style='List Bullet') # FIX: Removed "• "
|
| 1110 |
else:
|
| 1111 |
+
doc.add_paragraph("No specific steps identified.", style='List Bullet') # FIX: Removed "• "
|
| 1112 |
doc.add_paragraph("")
|
| 1113 |
|
| 1114 |
# Insights & Recommendations section
|
|
|
|
| 1125 |
future_prediction_items.append(line)
|
| 1126 |
if future_prediction_items:
|
| 1127 |
for item in future_prediction_items:
|
| 1128 |
+
doc.add_paragraph(item, style='List Bullet') # FIX: Removed "• "
|
| 1129 |
else:
|
| 1130 |
+
doc.add_paragraph("No future predictions identified.", style='List Bullet') # FIX: Removed "• "
|
| 1131 |
doc.add_paragraph("")
|
| 1132 |
|
| 1133 |
# Proactive Measures
|
|
|
|
| 1141 |
proactive_measures_items.append(line)
|
| 1142 |
if proactive_measures_items:
|
| 1143 |
for item in proactive_measures_items:
|
| 1144 |
+
doc.add_paragraph(item, style='List Bullet') # FIX: Removed "• "
|
| 1145 |
else:
|
| 1146 |
+
doc.add_paragraph("No proactive measures identified.", style='List Bullet') # FIX: Removed "• "
|
| 1147 |
doc.add_paragraph("")
|
| 1148 |
|
| 1149 |
|
|
|
|
| 1196 |
}
|
| 1197 |
h3 {
|
| 1198 |
color: #1A5276; /* Darker Blue-Green */
|
| 1199 |
+
margin-top: 15px; /* Reduced space */
|
| 1200 |
+
margin-bottom: 8px; /* Reduced space */
|
| 1201 |
font-size: 1.3em;
|
| 1202 |
font-weight: 600;
|
| 1203 |
}
|
| 1204 |
+
h4 { /* Added h4 styling */
|
| 1205 |
+
color: #3F51B5; /* Medium Indigo */
|
| 1206 |
+
margin-top: 12px; /* Reduced space */
|
| 1207 |
+
margin-bottom: 6px; /* Reduced space */
|
| 1208 |
+
font-size: 1.1em;
|
| 1209 |
+
font-weight: 600;
|
| 1210 |
+
}
|
| 1211 |
+
|
| 1212 |
|
| 1213 |
/* Paragraphs and list items */
|
| 1214 |
p {
|
|
|
|
| 1316 |
overflow-y: auto; /* Enable scrolling for long logs */
|
| 1317 |
height: 120px; /* Fixed height for log box */
|
| 1318 |
}
|
| 1319 |
+
/* Specific hr styling for Markdown content separators */
|
| 1320 |
+
.gradio-container hr { /* Target hr within the gradio container, particularly for Markdown */
|
| 1321 |
+
margin-top: 15px; /* Reduced space */
|
| 1322 |
+
margin-bottom: 15px; /* Reduced space */
|
| 1323 |
+
border: 0;
|
| 1324 |
+
height: 1px;
|
| 1325 |
+
background-color: #E0E0E0;
|
| 1326 |
+
}
|
| 1327 |
""") as demo:
|
| 1328 |
gr.HTML("""
|
| 1329 |
<h1 align="center">Advanced AI Customer Ticket Analyst</h1>
|
|
|
|
| 1337 |
|
| 1338 |
---
|
| 1339 |
|
| 1340 |
+
#### Important Note on AI Inferences:
|
| 1341 |
AI-generated insights, including inferred root causes, future predictions, and proactive measures, are based on the provided ticket data. These analyses are intended for guidance and require human expert validation for critical business decisions.
|
| 1342 |
|
| 1343 |
---
|
| 1344 |
|
| 1345 |
+
#### Input File Requirements:
|
| 1346 |
* **Supported Formats:** `.xlsx` (Excel), `.xls` (Legacy Excel), and `.csv` (Comma Separated Values).
|
| 1347 |
* **Data Structure:** Files must contain tabular data with clear headers in the first row. Each row represents an individual customer ticket.
|
| 1348 |
* **Minimum Columns:** A minimum of two columns are recommended: one for a unique `Ticket ID` (or `ID`) and one for the `Issue` (or `Description`).
|
|
|
|
| 1358 |
|
| 1359 |
---
|
| 1360 |
|
| 1361 |
+
#### Output Structure:
|
| 1362 |
The AI will generate a clear, data-driven report based solely on your uploaded file. The visual output will feature:
|
| 1363 |
* **Category Name (Total Count for Category)**
|
| 1364 |
* **Summary:** Key issue descriptions and common themes.
|