Skip to content

Commit

Permalink
Merge branch 'main' of github.com:epfl-ada/ada-2024-project-cyberbab0…
Browse files Browse the repository at this point in the history
…0shka
  • Loading branch information
sevashasla committed Dec 19, 2024
2 parents b1f8a1e + e7f46f2 commit b95c484
Show file tree
Hide file tree
Showing 2 changed files with 226 additions and 5 deletions.
72 changes: 68 additions & 4 deletions pages/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
import sys
import textwrap
from html import escape
import base64
import os
import glob

IMAGES_DIR = os.path.join(
os.path.dirname(__file__),
"assets",
"img",
)


def is_cell_valid(cell):
Expand Down Expand Up @@ -38,6 +47,13 @@ def overflowing_div(content):
"</div>"
)

def raw_context(content):
return (
'\n{% raw %}\n<div markdown="0">\n' +
content +
'\n</div>\n{% endraw %}\n'
)


def render(cell):
match cell['cell_type']:
Expand All @@ -48,6 +64,28 @@ def render(cell):
assert False, f"unknown type {cell['cell_type'] = }"


def save_png_and_get_name(base64_image):
imname = "generated_" + str(hash(base64_image)) + ".png"
path = os.path.join(
IMAGES_DIR,
imname
)
with open(path, "wb") as fh:
fh.write(base64.b64decode(base64_image.encode()))
return imname


def save_svg_and_get_name(svg_code):
imname = "generated_" + str(hash(svg_code)) + ".svg"
path = os.path.join(
IMAGES_DIR,
imname
)
with open(path, "w") as fh:
fh.write(svg_code)
return imname


def render_code(cell):
template = """\
<details><summary>code</summary>
Expand All @@ -71,7 +109,7 @@ def render_code(cell):
if "text/html" in data:
output_text += (
'\n' +
overflowing_div(''.join(data["text/html"])) +
raw_context(overflowing_div(''.join(data["text/html"]))) +
'\n'
)
elif "text/plain" in data:
Expand All @@ -90,9 +128,27 @@ def render_code(cell):
)
elif output['output_type'] == 'display_data':
data = output['data']
if "image/png" in data:
if "text/html" in data:
output_text += (
raw_context(''.join(
filter(
lambda x: len(x.strip()) > 0,
data["text/html"]
)
)
)
)
elif "image/svg+xml" in data:
output_text += (
f'\n<img src="data:image/png;base64, {data["image/png"]}" alt="{"".join(data.get("text/plain", []))}" />\n'
'\n<img src="{{ im_path }}/' +
save_svg_and_get_name(''.join(data["image/svg+xml"])) +
f'" alt="{"".join(data.get("text/plain", []))}" />\n'
)
elif "image/png" in data:
output_text += (
'\n<img src="{{ im_path }}/' +
save_png_and_get_name(data["image/png"]) +
f'" alt="{"".join(data.get("text/plain", []))}" />\n'
)
else:
assert False, f"unknown format: {data.keys() = }"
Expand All @@ -109,7 +165,7 @@ def render_code(cell):
def render_markdown(cell):
return (
"\n" +
escape(''.join(cell['source'])) +
''.join(cell['source']) +
"\n"
)

Expand All @@ -127,8 +183,16 @@ def render_markdown(cell):
mathjax: true
---
{% assign im_path = site.baseurl | append: "/assets/img/" %}
"""

for hgx in (
glob.glob(os.path.join(IMAGES_DIR, "generated*.png")) +
glob.glob(os.path.join(IMAGES_DIR, "generated*.svg"))
):
os.remove(hgx)

for cell in merge_cells(notebook["cells"]):
result_markdown += render(cell)

Expand Down
159 changes: 158 additions & 1 deletion src/story/Question_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,168 @@
"source": [
"# Question 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What Are the Most Common Character Archetypes in Movies?\n",
"What are the most prevalent character archetypes found in films, and how can we define and clusterize them based on existing papers and our own research? Identifying these archetypes involves exploring recurring character types and their roles within various plots."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Selection of archetype categories\n",
"\n",
"The identification of prominent movie archetypes turned out to be a challenging task. A popular way to analyse archetypes in related literature is with a help of the website [Tv tropes](https://tvtropes.org/), which constitutes a large collection of archetypes gathered by tv viewers. We found that the majority of the archetypes presented on the web site are extremely specific and can be applied only to a handful of examples (see [A Chat with Satan](https://tvtropes.org/pmwiki/pmwiki.php/Main/AChatWithSatan), [The Drunken Sailor](https://tvtropes.org/pmwiki/pmwiki.php/Main/TheDrunkenSailor), [Mock Millionaire](https://tvtropes.org/pmwiki/pmwiki.php/Main/MockMillionaire)). Such specific tropes limit the amount of available data, rendering the search of correlation much harder and making the insights less impactful. In our analysis we wanted to see a broader picture.Therefore it was necessary to devise a set of broad and popular archetypes. As a basis, a [list of archetypal tropes](https://tvtropes.org/pmwiki/pmwiki.php/Main/ArchetypalCharacter) was taken from the TV tropes website. Based on this list we tried to join some archetypes into more general categories. As a result, the following list of archetypes has emerged:\n",
"\n",
"##### Devised Archetypes\n",
"|Archetype | Description | Example 1 | Example 2 | Example 3|\n",
"|---|---|---|---|---|\n",
"|Love Interest / Romantic Partner|A character involved in a romantic relationship with a main figure, influencing emotional arcs and sometimes motivating heroic action.|\"Rose DeWitt Bukater\" in \"Titanic\"|\"Elizabeth Swann\" in \"Pirates of the Caribbean\"|\"Rachel Dawes\" in \"Batman Begins\"|\n",
"|Caregiver / Healer|Provides nurture, comfort, or medical/spiritual healing; supports others’ well-being and stability.|\"Dr. Ellen Ripley\" in \"Aliens\"|\"Samwise Gamgee\" in \"The Lord of the Rings\"|\"Molly Weasley\" in \"Harry Potter series\"|\n",
"|Mentor / Wise Guide|Provides knowledge, training, or insight to help the hero or others grow and succeed.|\"Ms. Honey\" in \"Matilda\"|\"Mr. Miyagi\" in \"The Karate Kid\"|\"Obi-Wan Kenobi\" in \"Star Wars: A New Hope\"|\n",
"|Intellectual / Creative (Scholar/Artist/Inventor)|Values knowledge, innovation, or art; provides crucial insights, cultural depth, problem-solving, or visionary ideas.|\"Steve Jobs\" in \"Steve Jobs\"|\"Leonardo da Vinci\" in \"The Da Vinci Code\"|\"Ada Lovelace\" in \"The Imitation Game\"|\n",
"|Ruler / Politician|Holds formal power or influence; shapes policies, alliances, and social orders, whether for good or ill.|\"President Franklin D. Roosevelt\" in \"Hyde Park on Hudson\"|\"Selina Meyer\" in \"Veep\"|\"Duncan Idaho\" in \"Dune\"|\n",
"|Sidekick / Loyal Companion|A supportive ally, assisting the hero, offering loyalty, encouragement, and sometimes comic or emotional relief.|\"Ron Weasley\" in \"Harry Potter and the Philosopher's Stone\"|\"Dr. John Watson\" in \"Sherlock Holmes: A Game of Shadows\"|\"Robin\" in \"Batman: The Movie\"|\n",
"|Warrior / Vigilante|Skilled in combat and physical confrontation; may enforce justice or defend others, sometimes outside legal boundaries.|\"Batman\" in \"The Dark Knight\"|\"John Wick\" in \"John Wick\"|\"The Bride\" in \"Kill Bill\"|\n",
"|Rogue / Trickster / Con Artist|A cunning, rule-bending manipulator who achieves goals through deception, charm, or clever schemes.|\"Frank Abagnale Jr.\" in \"Catch Me If You Can (2002)\"|\"Irving Rosenfeld\" in \"American Hustle (2013)\"|\"Lawrence Jamieson\" in \"Dirty Rotten Scoundrels (1988)\"|\n",
"|Mystic / Seer|Offers spiritual guidance, foresight, or mystical understanding, often steering characters with visions or cryptic wisdom.|\"The Oracle\" in \"The Matrix\"|\"Yoda\" in \"The Empire Strikes Back\"|\"Galadriel\" in \"The Lord of the Rings: The Fellowship of the Ring\"|\n",
"|Outsider / Loner|Operates on the fringe of society, often misunderstood or self-isolated, bringing a unique perspective.|\"Edward Scissorhands\" in \"Edward Scissorhands\"|\"Rick Deckard\" in \"Blade Runner\"|\"Chuck Noland\" in \"Cast Away\"|\n",
"|Innocent / Vulnerable|Naive, inexperienced, or in need of guidance; prompts protection or mentoring, and highlights moral stakes.|\"Daniel LaRusso\" in \"The Karate Kid\"|\"Charlie Bucket\" in \"Willy Wonka & the Chocolate Factory\"|\"Newt\" in \"Aliens\"|\n",
"|Other|Doesn't align with any of the proposed archetype categories|\"George McFly\" in \"Back to the Future\"|\"Victor\" in \"John Wick\"|\"Mayor\" in \"Ghostbusters\"|\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div style=\"max-height: 400px; overflow-y: auto;\">\n",
" <table>\n",
" <thead>\n",
" <tr>\n",
" <th>Archetype</th>\n",
" <th>Description</th>\n",
" <th>Example 1</th>\n",
" <th>Example 2</th>\n",
" <th>Example 3</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>Love Interest / Romantic Partner</td>\n",
" <td>A character involved in a romantic relationship with a main figure, influencing emotional arcs and sometimes motivating heroic action.</td>\n",
" <td>\"Rose DeWitt Bukater\" in \"Titanic\"</td>\n",
" <td>\"Elizabeth Swann\" in \"Pirates of the Caribbean\"</td>\n",
" <td>\"Rachel Dawes\" in \"Batman Begins\"</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Caregiver / Healer</td>\n",
" <td>Provides nurture, comfort, or medical/spiritual healing; supports others’ well-being and stability.</td>\n",
" <td>\"Dr. Ellen Ripley\" in \"Aliens\"</td>\n",
" <td>\"Samwise Gamgee\" in \"The Lord of the Rings\"</td>\n",
" <td>\"Molly Weasley\" in \"Harry Potter series\"</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Mentor / Wise Guide</td>\n",
" <td>Provides knowledge, training, or insight to help the hero or others grow and succeed.</td>\n",
" <td>\"Ms. Honey\" in \"Matilda\"</td>\n",
" <td>\"Mr. Miyagi\" in \"The Karate Kid\"</td>\n",
" <td>\"Obi-Wan Kenobi\" in \"Star Wars: A New Hope\"</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Intellectual / Creative (Scholar/Artist/Inventor)</td>\n",
" <td>Values knowledge, innovation, or art; provides crucial insights, cultural depth, problem-solving, or visionary ideas.</td>\n",
" <td>\"Steve Jobs\" in \"Steve Jobs\"</td>\n",
" <td>\"Leonardo da Vinci\" in \"The Da Vinci Code\"</td>\n",
" <td>\"Ada Lovelace\" in \"The Imitation Game\"</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Ruler / Politician</td>\n",
" <td>Holds formal power or influence; shapes policies, alliances, and social orders, whether for good or ill.</td>\n",
" <td>\"President Franklin D. Roosevelt\" in \"Hyde Park on Hudson\"</td>\n",
" <td>\"Selina Meyer\" in \"Veep\"</td>\n",
" <td>\"Duncan Idaho\" in \"Dune\"</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Sidekick / Loyal Companion</td>\n",
" <td>A supportive ally, assisting the hero, offering loyalty, encouragement, and sometimes comic or emotional relief.</td>\n",
" <td>\"Ron Weasley\" in \"Harry Potter and the Philosopher's Stone\"</td>\n",
" <td>\"Dr. John Watson\" in \"Sherlock Holmes: A Game of Shadows\"</td>\n",
" <td>\"Robin\" in \"Batman: The Movie\"</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Warrior / Vigilante</td>\n",
" <td>Skilled in combat and physical confrontation; may enforce justice or defend others, sometimes outside legal boundaries.</td>\n",
" <td>\"Batman\" in \"The Dark Knight\"</td>\n",
" <td>\"John Wick\" in \"John Wick\"</td>\n",
" <td>\"The Bride\" in \"Kill Bill\"</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Rogue / Trickster / Con Artist</td>\n",
" <td>A cunning, rule-bending manipulator who achieves goals through deception, charm, or clever schemes.</td>\n",
" <td>\"Frank Abagnale Jr.\" in \"Catch Me If You Can (2002)\"</td>\n",
" <td>\"Irving Rosenfeld\" in \"American Hustle (2013)\"</td>\n",
" <td>\"Lawrence Jamieson\" in \"Dirty Rotten Scoundrels (1988)\"</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Mystic / Seer</td>\n",
" <td>Offers spiritual guidance, foresight, or mystical understanding, often steering characters with visions or cryptic wisdom.</td>\n",
" <td>\"The Oracle\" in \"The Matrix\"</td>\n",
" <td>\"Yoda\" in \"The Empire Strikes Back\"</td>\n",
" <td>\"Galadriel\" in \"The Lord of the Rings: The Fellowship of the Ring\"</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Outsider / Loner</td>\n",
" <td>Operates on the fringe of society, often misunderstood or self-isolated, bringing a unique perspective.</td>\n",
" <td>\"Edward Scissorhands\" in \"Edward Scissorhands\"</td>\n",
" <td>\"Rick Deckard\" in \"Blade Runner\"</td>\n",
" <td>\"Chuck Noland\" in \"Cast Away\"</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Innocent / Vulnerable</td>\n",
" <td>Naive, inexperienced, or in need of guidance; prompts protection or mentoring, and highlights moral stakes.</td>\n",
" <td>\"Daniel LaRusso\" in \"The Karate Kid\"</td>\n",
" <td>\"Charlie Bucket\" in \"Willy Wonka & the Chocolate Factory\"</td>\n",
" <td>\"Newt\" in \"Aliens\"</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Other</td>\n",
" <td>Doesn't align with any of the proposed archetype categories</td>\n",
" <td>\"George McFly\" in \"Back to the Future\"</td>\n",
" <td>\"Victor\" in \"John Wick\"</td>\n",
" <td>\"Mayor\" in \"Ghostbusters\"</td>\n",
" </tr>\n",
" </tbody>\n",
" </table>\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.8"
}
},
"nbformat": 4,
Expand Down

0 comments on commit b95c484

Please sign in to comment.