{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "**Note:** This notebook is designed for **Google Colab**.\n",
        "\n",
        "If you see the Colab logo <span style='vertical-align:bottom;'><img src='https://colab.research.google.com/img/colab_favicon_256px.png' width='40' alt='Colab logo'></span> in the top-left corner, you're all set! Please **proceed to Section 1**.\n",
        "\n",
        "If you don't see the logo (e.g., you are on GitHub), please click the button below to open it in the correct environment:\n",
        "\n",
        "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mparrott-at-wiris/aimodelshare/blob/master/notebooks/Etica_en_Joc_Justice_Challenge.ipynb)"
      ],
      "metadata": {
        "id": "pjnUTfUOGMX3"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "---\n",
        "# **Section 1: Welcome to Ethics at Play**"
      ],
      "metadata": {
        "id": "T1yDpMQwYJ2i"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "We live in a world where unseen algorithms are making decisions about our lives. We trust them to be **objective**. We trust them to be **fair**.\n",
        "\n",
        "But what if they're not?\n",
        "\n",
        "Welcome to **Ethics at Play**. This isn't a traditional lecture. This is a hands-on mission that puts you in control of a powerful AI system. We believe the ideal way to understand the complex, real-world trade-offs in technology is to experience them for yourself.\n",
        "\n",
        "We have turned AI ethics into a game: earn badges, make high-impact decisions, and compete on a live leaderboard. Every choice shapes your score—and your sense of justice in the age of AI.\n",
        "\n",
        "---\n",
        "\n",
        "## 🎯 **Your Mission**\n",
        "\n",
        "In this module, **The Justice and Equity Challenge**, you will confront one of the biggest ethical risks in AI today: **bias and fairness**.\n",
        "\n",
        "Your journey will begin by taking on two real-world roles:\n",
        "\n",
        "1.  **The Judge:** You’ll use an AI’s recommendations to decide who gets released from prison. But what happens if the algorithm is wrong?\n",
        "2.  **The AI Engineer:** You'll compete with others to build AI models that are much better at identifying criminal risk.  But better by whose definition?\n",
        "\n",
        "Through these roles, you’ll begin to discover how data, design, and human judgment intertwine to produce real-world consequences.\n",
        "\n",
        "---\n",
        "\n",
        "## 🧭 **The Moral Compass**\n",
        "\n",
        "Your goal will shift: rebuild your AI model, this time guided by the **Moral Compass Score**, which rewards **ethical improvement** over raw performance.\n",
        "\n",
        "Following expert guidance from the **UdG's OEIAC AI Ethics Center**, you will compete to detect bias, measure inequity, and redesign your system toward greater justice.\n",
        "\n",
        "---\n",
        "\n",
        "## 💡 **A Tool for Every Learner**\n",
        "\n",
        "This platform is engineered for a diverse audience:\n",
        "\n",
        "* **\"Low-Tech First\":** **No prior coding or AI knowledge is required.** All core interactions use simple buttons and sliders.\n",
        "* **Dual-Pathway:** Advanced students can use **optional, parallel code notebooks** to build and train the models directly.\n",
        "\n",
        "This program directly aligns with Catalan, Spanish, and EU education goals for fostering socially and ethically aware users of digital technology.\n",
        "\n",
        "---"
      ],
      "metadata": {
        "id": "p1TxuJaNn3rx"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## 🚀 **Quick Start Guide**\n",
        "\n",
        "This guide summarizes the simple actions needed to successfully start the challenge.\n",
        "\n",
        "**Read these steps first** and then practice them in **Section 2** below.\n",
        "\n",
        "1.  **Run the First Cell** (How?):\n",
        "    * Find the first block with the ▶ **Play Button** next to it.\n",
        "    * **Click the ▶ Play Button** and wait for a moment.\n",
        "\n",
        "2.  **Install the Software**:\n",
        "    * The next step will ask you to install the necessary software.\n",
        "    * **Click the ▶ Play Button** on the installation cell and wait for it to complete.\n",
        "\n",
        "3.  **Launch Your First Activity**:\n",
        "    * Find the final ▶  **Play Button** in the tutorial section.\n",
        "    * **Click the ▶ Play Button** and wait for the learning app to load.\n",
        "    * **Use the App:** Interact with the mini-website that appears to officially begin the challenge.\n",
        "\n",
        "---\n",
        "### Key Action to Remember:\n",
        "The single most important action for almost every step is to **click the ▶ Play Button** and then wait for the learning activity output to appear."
      ],
      "metadata": {
        "id": "NDsm4UGnXQsq"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "---\n",
        "# **Section 2: Quick Start Tutorial**\n",
        "\n",
        "\n",
        "\n"
      ],
      "metadata": {
        "id": "QfeCcEmEc5cX"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## 🛑 Quick Troubleshooting: When Things Go Wrong\n",
        "\n",
        "Don't panic\\! Here are the three most common issues and their solutions. Read this first so you know what to do if you get stuck.\n",
        "\n",
        "| Issue | Cause | Solution |\n",
        "| :--- | :--- | :--- |\n",
        "| **\"Cell is spinning indefinitely\\!\"** | The notebook disconnected from the computer's resources. | Look in the **upper-right corner**. If it says **\"Connect,\"** click that button to reconnect. |\n",
        "| **\"I see a red error message\\!\"** | A cell higher up in the notebook was skipped or not run. | **Scroll up** and check that *every* Code Cell above the error has been run (look for the numbered bracket next to each play button, like `[1]`). |\n",
        "| **\"I changed the text but nothing happened\\!\"** | You didn't re-run the code after making an edit. | After editing information in a Code Cell, you **must** click the $\\blacktriangleright$ **Play Button** again to use the new information. |\n",
        "\n",
        "-----"
      ],
      "metadata": {
        "id": "m1wbkGNuHEhA"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Now, let's practice each step.\n"
      ],
      "metadata": {
        "id": "kKXb9BBaHVZO"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## 1. **Run** your first code cell\\!\n",
        "\n",
        "Your only job is **to place your cursor above the below code cell**, then to click the ▶ **Play Button** on the left side to run the code in the cell.  \n",
        "\n",
        "**Note:** *A warning message may pop up because the notebook was not authored by Google, select \"RUN ANYWAY\".*"
      ],
      "metadata": {
        "id": "wcbQjwZ5SWCV"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# CODE CELL 1: Click the Play button (circular arrow) to the left of this cell.\n",
        "print(\"✅ Congratulations! You ran your first cell successfully.\")\n",
        "print(\"The new text below the cell is the 'output' of the code. The play button now shows a number like [1] next to it.\")\n",
        "print(\"You are ready to to practice the second quickstart step below!\")"
      ],
      "metadata": {
        "id": "HyNxkyH9SWOl"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "### 2. **Install the Application Software**\n",
        "\n",
        "Almost ready! The tutorial app is part of a special software package that we need to install first.\n",
        "\n",
        "**Your Task:**\n",
        "* Click the ▶ **Play Button** on the code cell below.\n",
        "* Wait for it to finish. You will see a message \"✅ Installation complete!\" when it's done."
      ],
      "metadata": {
        "id": "lSREqPa1hWYX"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# This cell installs the 'aimodelshare' library\n",
        "print(\"Installing required libraries (Give this process 30 seconds or so)...\")\n",
        "!pip install aimodelshare --upgrade -q --no-warn-script-location > /dev/null 2>&1\n",
        "print(\"✅ Installation complete! You can now launch the app in the next step.\")"
      ],
      "metadata": {
        "id": "CXmOjTGphi1z"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "### 3. **Launch Your First Activity - The Tutorial App**\n",
        "\n",
        "Great! Now that the software is installed, you can launch the tutorial app.\n",
        "\n",
        "**Your Task:**\n",
        "* Click the ▶ **Play Button** on the final code cell below.\n",
        "* A small, interactive website window will appear below the cell.\n",
        "* Complete the tasks inside that app to finish the tutorial."
      ],
      "metadata": {
        "id": "ITj7bTFqVbLn"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# This cell imports and runs the tutorial app\n",
        "print(\"Loading tutorial app (in 30 seconds or so...)\")\n",
        "from aimodelshare.moral_compass.apps.tutorial import create_tutorial_app\n",
        "tutorial_app = create_tutorial_app()\n",
        "tutorial_app.launch(inline=True, share=False, debug=False, height=750, quiet=True)"
      ],
      "metadata": {
        "id": "ZgyEhB5jqwfP"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "---\n",
        "# **Section 3: The Justice and Equity Challenge**"
      ],
      "metadata": {
        "id": "ln0kAp0V-6uZ"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Now you are ready to begin the challenge! The next few sections will guide you through an interactive experience where you'll make real ethical decisions."
      ],
      "metadata": {
        "id": "HLqleu3fIJoK"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Activity 1: You Be the Judge**\n",
        "\n",
        "In this first part of the challenge, you will take on the role of a judge. You'll review defendant profiles and decide whether to release them from prison or keep them incarcerated.\n",
        "\n",
        "An AI system will provide risk predictions to help guide your decisions. But remember: these are just predictions.\n",
        "\n",
        "**Your Task:**\n",
        "* Click the ▶ **Play Button** below to launch the \"You Be the Judge\" app.\n",
        "* Make your decisions for each defendant.\n",
        "* When finished, scroll down to continue to the next section."
      ],
      "metadata": {
        "id": "judge_intro_md"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Launch the You Be the Judge app\n",
        "print(\"Loading the Judge Decision App (in 30 seconds or so...)\")\n",
        "from aimodelshare.moral_compass.apps.judge import create_judge_app\n",
        "judge_app = create_judge_app()\n",
        "judge_app.launch(inline=True, share=False, debug=False, height=1200, quiet=True)"
      ],
      "metadata": {
        "id": "judge_app_code"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Activity 2: What If the AI Was Wrong?**\n",
        "\n",
        "You just made several important decisions based on AI predictions. But what happens when those predictions are incorrect?\n",
        "\n",
        "In this section, you'll learn about:\n",
        "* **False Positives** - When AI incorrectly predicts high risk\n",
        "* **False Negatives** - When AI incorrectly predicts low risk\n",
        "* The real-world consequences of each type of error\n",
        "\n",
        "**Your Task:**\n",
        "* Click the ▶ **Play Button** below to launch the interactive slideshow.\n",
        "* Read through each slide carefully.\n",
        "* When finished, scroll down to continue."
      ],
      "metadata": {
        "id": "consequences_intro_md"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Launch the AI Consequences app\n",
        "print(\"Loading the AI Consequences slideshow (in 30 seconds or so...)\")\n",
        "from aimodelshare.moral_compass.apps.ai_consequences import create_ai_consequences_app\n",
        "consequences_app = create_ai_consequences_app()\n",
        "consequences_app.launch(inline=True, share=False, debug=False, height=1000, quiet=True)"
      ],
      "metadata": {
        "id": "consequences_app_code"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Activity 3: So, What Is AI, Really?**\n",
        "\n",
        "Before you can build better AI systems, you need to understand what AI actually is and how it works.\n",
        "\n",
        "In this section, you'll learn:\n",
        "* A simple, non-technical definition of AI\n",
        "* How predictive models work (Input → Model → Output)\n",
        "* How this applies to the criminal justice scenario\n",
        "* Why understanding AI is crucial for building ethical systems\n",
        "\n",
        "**Your Task:**\n",
        "* Click the ▶ **Play Button** below to launch the interactive lesson.\n",
        "* Try out the interactive prediction demo.\n",
        "* When finished, you'll be ready to start building your own AI models!"
      ],
      "metadata": {
        "id": "what_is_ai_intro_md"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Launch the What Is AI app\n",
        "print(\"Loading the What Is AI lesson (in 30 seconds or so...)\")\n",
        "from aimodelshare.moral_compass.apps.what_is_ai import create_what_is_ai_app\n",
        "what_is_ai_app = create_what_is_ai_app()\n",
        "what_is_ai_app.launch(inline=True, share=False, debug=False, height=1100, quiet=True)"
      ],
      "metadata": {
        "id": "what_is_ai_app_code"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "# **Activity 4: The Technical Challenge — Step Into the AI Lead Engineer Role**\n",
        "\n",
        "Get ready—next, **you’ll build your own AI models!**\n",
        "  \n",
        "You’re about to step into a *new builder role*: **AI Lead Engineer**—the person who gets to design, tweak, and improve an AI system.\n",
        "\n",
        "Your mission: **build a smarter AI risk-prediction model** that can help a judge make more accurate decisions.\n",
        "\n",
        "Just like real AI teams, you’ll **experiment**, **test ideas**, and **compare results**.\n",
        "\n",
        "There’s also a **leaderboard** to help you track how your models perform alongside your peers in a model improvement game.\n",
        "\n",
        "Ready to try to build something better? Let’s go.\n",
        "\n",
        "### **What You’ll Learn in This Section**\n",
        "- How different model choices affect prediction accuracy\n",
        "- How experimentation leads to better AI performance  \n",
        "- How to think like an engineer when improving a prediction system  \n",
        "- How leaderboard feedback helps you iterate strategically  \n",
        "\n",
        "### **Your Task**\n",
        "- Click the ▶ **Play Button** below to launch the interactive lesson  \n",
        "- Try out the interactive model building game\n",
        "- Explore how different design choices affect predictive performance.  \n",
        "- Get ready—next, **you’ll build your own AI models!**"
      ],
      "metadata": {
        "id": "jc5a6l-PCTFn"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Launch the the Model Building Game app\n",
        "print(\"Loading the Model Building Game lesson (in 30 seconds or so...)\")\n",
        "from aimodelshare.moral_compass.apps.model_building_game import create_model_building_game_app\n",
        "model_building_game_app = create_model_building_game_app()\n",
        "model_building_game_app.launch(inline=True, share=False, debug=False, height=1100, quiet=True)"
      ],
      "metadata": {
        "id": "ZunO1ff5EtK-"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}