AjaykumarPilla commited on
Commit
5b665a7
·
verified ·
1 Parent(s): cbf8115

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -11,6 +11,8 @@ from datetime import datetime
11
  from reportlab.lib.pagesizes import letter
12
  from reportlab.pdfgen import canvas
13
  from reportlab.lib.utils import simpleSplit
 
 
14
  from io import BytesIO
15
  import matplotlib.pyplot as plt
16
  import seaborn as sns
@@ -106,7 +108,17 @@ def generate_pdf_report(phase, weather, absentee_pct, delay_log, prediction, ris
106
  try:
107
  buffer = BytesIO()
108
  c = canvas.Canvas(buffer, pagesize=letter)
109
- c.setFont("Helvetica", 12)
 
 
 
 
 
 
 
 
 
 
110
 
111
  c.drawString(100, 750, "Project Delay Prediction Report")
112
  c.drawString(100, 730, f"Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
@@ -119,20 +131,20 @@ def generate_pdf_report(phase, weather, absentee_pct, delay_log, prediction, ris
119
  f"Weather: {weather}",
120
  f"Absentee Percentage: {absentee_pct}%",
121
  f"Previous Delay Log: {delay_log}",
122
- f"Predicted Delay: {prediction}%{' 🚩' if prediction >= 75 else ''}",
123
  f"Risk Level: {risk}",
124
  "AI Insight:"
125
  ]
126
 
127
  # Wrap and draw each line properly
128
  for line in details:
129
- lines = simpleSplit(line, 'Helvetica', 12, max_width)
130
  for wrapped_line in lines:
131
  c.drawString(100, y_position, wrapped_line)
132
  y_position -= 16
133
 
134
  # Wrap and draw insight (which may be long)
135
- insight_lines = simpleSplit(insight, 'Helvetica', 12, max_width)
136
  for wrapped_line in insight_lines:
137
  c.drawString(100, y_position, wrapped_line)
138
  y_position -= 16
 
11
  from reportlab.lib.pagesizes import letter
12
  from reportlab.pdfgen import canvas
13
  from reportlab.lib.utils import simpleSplit
14
+ from reportlab.pdfbase import pdfmetrics
15
+ from reportlab.pdfbase.ttfonts import TTFont
16
  from io import BytesIO
17
  import matplotlib.pyplot as plt
18
  import seaborn as sns
 
108
  try:
109
  buffer = BytesIO()
110
  c = canvas.Canvas(buffer, pagesize=letter)
111
+
112
+ # Register DejaVuSans font to support Unicode emojis
113
+ try:
114
+ # Assuming DejaVuSans.ttf is available in the project directory
115
+ pdfmetrics.registerFont(TTFont('DejaVuSans', 'DejaVuSans.ttf'))
116
+ c.setFont("DejaVuSans", 12)
117
+ flag_indicator = " 🚩" if prediction >= 75 else ""
118
+ except Exception as e:
119
+ print(f"Failed to load DejaVuSans font: {e}. Falling back to Helvetica with text flag.")
120
+ c.setFont("Helvetica", 12)
121
+ flag_indicator = " [FLAG]" if prediction >= 75 else ""
122
 
123
  c.drawString(100, 750, "Project Delay Prediction Report")
124
  c.drawString(100, 730, f"Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
 
131
  f"Weather: {weather}",
132
  f"Absentee Percentage: {absentee_pct}%",
133
  f"Previous Delay Log: {delay_log}",
134
+ f"Predicted Delay: {prediction}%{flag_indicator}",
135
  f"Risk Level: {risk}",
136
  "AI Insight:"
137
  ]
138
 
139
  # Wrap and draw each line properly
140
  for line in details:
141
+ lines = simpleSplit(line, 'DejaVuSans' if 'DejaVuSans' in pdfmetrics.getRegisteredFontNames() else 'Helvetica', 12, max_width)
142
  for wrapped_line in lines:
143
  c.drawString(100, y_position, wrapped_line)
144
  y_position -= 16
145
 
146
  # Wrap and draw insight (which may be long)
147
+ insight_lines = simpleSplit(insight, 'DejaVuSans' if 'DejaVuSans' in pdfmetrics.getRegisteredFontNames() else 'Helvetica', 12, max_width)
148
  for wrapped_line in insight_lines:
149
  c.drawString(100, y_position, wrapped_line)
150
  y_position -= 16