File size: 1,531 Bytes
cf24096
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from fpdf import FPDF
import datetime

class PDF(FPDF):
    def header(self):
        self.set_font('Arial', 'B', 12)
        self.cell(0, 10, 'InsightForge AI - AutoML Report', border=False, ln=True, align='C')
        self.ln(5)

    def footer(self):
        self.set_y(-15)
        self.set_font('Arial', 'I', 8)
        self.cell(0, 10, f'Page {self.page_no()}', align='C')

    def chapter_title(self, title):
        self.set_font('Arial', 'B', 12)
        self.set_fill_color(200, 220, 255)
        self.cell(0, 10, title, ln=True, fill=True)
        self.ln(4)

    def chapter_body(self, text):
        self.set_font('Arial', '', 11)
        self.multi_cell(0, 10, text)
        self.ln()

def generate_pdf(raw_df, model_results, best_model_name, problem_type):
    pdf = PDF()
    pdf.add_page()

    now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    pdf.set_font('Arial', '', 12)
    pdf.cell(0, 10, f"Generated on: {now}", ln=True)
    pdf.ln(5)

    pdf.chapter_title("πŸ“Š Dataset Preview")
    preview = raw_df.head().to_string(index=False)
    pdf.chapter_body(preview)

    pdf.chapter_title("🎯 Problem Type")
    pdf.chapter_body(f"This task was identified as a {problem_type.upper()} problem.")

    pdf.chapter_title("πŸ“ˆ Model Comparison")
    result_text = model_results.to_string(index=False)
    pdf.chapter_body(result_text)

    pdf.chapter_title("πŸ† Best Model")
    pdf.chapter_body(f"The best-performing model was: {best_model_name}")

    pdf.output("InsightForge_AI_Report.pdf")