File size: 4,027 Bytes
bee9bbb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"""Source-grounded presentation for the Deep Learning Specialization prototype."""

from __future__ import annotations

from pathlib import Path
from typing import Any

from jinja2 import Environment, FileSystemLoader, select_autoescape


TEMPLATE_ROOT = Path(__file__).resolve().parent / "templates"
_TEMPLATES = Environment(
    loader=FileSystemLoader(TEMPLATE_ROOT),
    autoescape=select_autoescape(("html", "xml")),
)

_COURSE_PRESENTATION = {
    "neural-networks-deep-learning": {
        "number": 1,
        "asset": "course-neural-networks.png",
        "duration": "4 weeks",
    },
    "improving-deep-neural-networks": {
        "number": 2,
        "asset": "course-improving-networks.png",
        "duration": "3 weeks",
    },
    "structuring-machine-learning-projects": {
        "number": 3,
        "asset": "course-structuring-projects.png",
        "duration": "2 weeks",
    },
    "convolutional-neural-networks": {
        "number": 4,
        "asset": "course-convolutional.png",
        "duration": "4 weeks",
    },
    "sequence-models": {
        "number": 5,
        "asset": "course-sequence-models.png",
        "duration": "4 weeks",
    },
}


def render_specialization_body(
    *,
    components: list[dict[str, Any]],
    authenticated: bool,
    specialization: dict[str, Any] | None = None,
) -> str:
    """Render the observed English page while keeping all actions clone-local.

    For programs whose component records were not individually observed, the
    program's own ``syllabus`` (observed course titles) synthesizes the course
    list so the series section is never empty.
    """

    specialization = specialization or {}
    courses = []
    for component in components:
        presentation = _COURSE_PRESENTATION.get(str(component["id"]))
        if presentation is None:
            number = int(component.get("component_number", len(courses) + 1))
            presentation = {
                "number": number,
                "asset": "course-neural-networks.png",
                "duration": "4 weeks",
            }
        courses.append({**component, **presentation})
    courses.sort(key=lambda course: int(course["number"]))
    program_id = str(specialization.get("id", "deep-learning-specialization"))
    is_deep_learning = program_id == "deep-learning-specialization"
    instructor_names = (
        ["Andrew Ng", "Younes Bensouda Mourri", "Kian Katanforoosh"]
        if is_deep_learning
        else [f"{str(specialization.get('provider', 'Program'))} instructor team"]
    )
    return _TEMPLATES.get_template("pages/specialization.html").render(
        authenticated=authenticated,
        courses=courses,
        program={
            "id": program_id,
            "title": str(specialization.get("title", "Deep Learning Specialization")),
            "provider": str(specialization.get("provider", "DeepLearning.AI")),
            "subject": str(specialization.get("subject", "Data Science")),
            "subtitle": (
                "Become a Machine Learning expert."
                if is_deep_learning
                else f"Build job-ready skills in {str(specialization.get('subject', 'this field'))}."
            ),
            "lead": (
                "Master the fundamentals of deep learning and break into AI. Recently updated with cutting-edge techniques!"
                if is_deep_learning
                else "Learn from industry experts and build a strong foundation with hands-on projects and real-world applications."
            ),
            "instructors": instructor_names,
            "top_instructor": is_deep_learning,
            "course_count": len(courses),
            "reviews": "147,228" if is_deep_learning else "deterministic local learner summary",
            "level": "Intermediate" if is_deep_learning else "Beginner",
            "duration": "3 months at 10 hours a week" if is_deep_learning else "Flexible schedule",
            "enrolled": "997,307" if is_deep_learning else "10,000+",
        },
    )