aimodelshare 0.1.29__py3-none-any.whl → 0.1.64__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of aimodelshare might be problematic. Click here for more details.
- aimodelshare/__init__.py +94 -14
- aimodelshare/aimsonnx.py +417 -262
- aimodelshare/api.py +13 -12
- aimodelshare/auth.py +163 -0
- aimodelshare/aws.py +4 -4
- aimodelshare/base_image.py +1 -1
- aimodelshare/containerisation.py +1 -1
- aimodelshare/data_sharing/download_data.py +103 -70
- aimodelshare/generatemodelapi.py +7 -6
- aimodelshare/main/authorization.txt +275 -275
- aimodelshare/main/eval_lambda.txt +81 -13
- aimodelshare/model.py +493 -197
- aimodelshare/modeluser.py +89 -1
- aimodelshare/moral_compass/README.md +408 -0
- aimodelshare/moral_compass/__init__.py +37 -0
- aimodelshare/moral_compass/_version.py +3 -0
- aimodelshare/moral_compass/api_client.py +601 -0
- aimodelshare/moral_compass/apps/__init__.py +26 -0
- aimodelshare/moral_compass/apps/ai_consequences.py +297 -0
- aimodelshare/moral_compass/apps/judge.py +299 -0
- aimodelshare/moral_compass/apps/tutorial.py +198 -0
- aimodelshare/moral_compass/apps/what_is_ai.py +426 -0
- aimodelshare/moral_compass/challenge.py +365 -0
- aimodelshare/moral_compass/config.py +187 -0
- aimodelshare/playground.py +26 -14
- aimodelshare/preprocessormodules.py +60 -6
- aimodelshare/pyspark/authorization.txt +258 -258
- aimodelshare/pyspark/eval_lambda.txt +1 -1
- aimodelshare/reproducibility.py +20 -5
- aimodelshare/utils/__init__.py +78 -0
- aimodelshare/utils/optional_deps.py +38 -0
- aimodelshare-0.1.64.dist-info/METADATA +298 -0
- {aimodelshare-0.1.29.dist-info → aimodelshare-0.1.64.dist-info}/RECORD +36 -25
- {aimodelshare-0.1.29.dist-info → aimodelshare-0.1.64.dist-info}/WHEEL +1 -1
- aimodelshare-0.1.64.dist-info/licenses/LICENSE +5 -0
- {aimodelshare-0.1.29.dist-info → aimodelshare-0.1.64.dist-info}/top_level.txt +0 -1
- aimodelshare-0.1.29.dist-info/METADATA +0 -78
- aimodelshare-0.1.29.dist-info/licenses/LICENSE +0 -22
- tests/__init__.py +0 -0
- tests/test_aimsonnx.py +0 -135
- tests/test_playground.py +0 -721
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tutorial Gradio application for onboarding users to the Justice & Equity Challenge.
|
|
3
|
+
|
|
4
|
+
This app teaches:
|
|
5
|
+
1. How to advance slideshow-style steps
|
|
6
|
+
2. How to interact with sliders/buttons
|
|
7
|
+
3. How model prediction output appears
|
|
8
|
+
|
|
9
|
+
Structure:
|
|
10
|
+
- Factory function `create_tutorial_app()` returns a Gradio Blocks object
|
|
11
|
+
- Convenience wrapper `launch_tutorial_app()` launches it inline (for notebooks)
|
|
12
|
+
"""
|
|
13
|
+
import contextlib
|
|
14
|
+
import os
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _build_synthetic_model():
|
|
18
|
+
"""Build a tiny linear regression model on synthetic study habit data."""
|
|
19
|
+
import numpy as np
|
|
20
|
+
from sklearn.linear_model import LinearRegression
|
|
21
|
+
|
|
22
|
+
rng = np.random.default_rng(7)
|
|
23
|
+
n = 200
|
|
24
|
+
hours_study = rng.uniform(0, 12, n)
|
|
25
|
+
hours_sleep = rng.uniform(4, 10, n)
|
|
26
|
+
attendance = rng.uniform(50, 100, n)
|
|
27
|
+
exam_score = 5 * hours_study + 3 * hours_sleep + 0.5 * attendance + rng.normal(0, 10, n)
|
|
28
|
+
|
|
29
|
+
X = np.column_stack([hours_study, hours_sleep, attendance])
|
|
30
|
+
y = exam_score
|
|
31
|
+
lin_reg = LinearRegression().fit(X, y)
|
|
32
|
+
|
|
33
|
+
def predict_exam(sl, slp, att):
|
|
34
|
+
pred = float(lin_reg.predict([[sl, slp, att]])[0])
|
|
35
|
+
import numpy as np
|
|
36
|
+
pred = float(np.clip(pred, 0, 100))
|
|
37
|
+
return f"{round(pred, 1)}%"
|
|
38
|
+
|
|
39
|
+
return predict_exam
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def create_tutorial_app(theme_primary_hue: str = "indigo") -> "gr.Blocks":
|
|
43
|
+
"""Create the tutorial Gradio Blocks app (not launched yet)."""
|
|
44
|
+
try:
|
|
45
|
+
import gradio as gr
|
|
46
|
+
except ImportError as e:
|
|
47
|
+
raise ImportError(
|
|
48
|
+
"Gradio is required for the tutorial app. Install with `pip install gradio`."
|
|
49
|
+
) from e
|
|
50
|
+
|
|
51
|
+
predict_exam = _build_synthetic_model()
|
|
52
|
+
|
|
53
|
+
css = """
|
|
54
|
+
#prediction_output_textbox textarea {
|
|
55
|
+
font-size: 2.5rem !important;
|
|
56
|
+
font-weight: bold !important;
|
|
57
|
+
color: #1E40AF !important;
|
|
58
|
+
text-align: center !important;
|
|
59
|
+
}
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue=theme_primary_hue), css=css) as demo:
|
|
63
|
+
gr.Markdown("<h1 style='text-align:center;'>👋 How to Use an App (A Quick Tutorial)</h1>")
|
|
64
|
+
gr.Markdown(
|
|
65
|
+
"""
|
|
66
|
+
<div style='text-align:left; font-size:20px; max-width: 800px; margin: auto;
|
|
67
|
+
padding: 15px; background-color: #f7f7f7; border-radius: 8px;'>
|
|
68
|
+
This is a simple, 3-step tutorial.<br><br>
|
|
69
|
+
<b>Your Task:</b> Just read the instructions for each step and click the "Next" button to continue.
|
|
70
|
+
</div>
|
|
71
|
+
"""
|
|
72
|
+
)
|
|
73
|
+
gr.HTML("<hr style='margin:24px 0;'>")
|
|
74
|
+
|
|
75
|
+
# Step 1
|
|
76
|
+
with gr.Column(visible=True) as step_1_container:
|
|
77
|
+
gr.Markdown("<h2 style='text-align:center;'>Step 1: How to Use \"Slideshows\"</h2>")
|
|
78
|
+
gr.Markdown(
|
|
79
|
+
"""
|
|
80
|
+
<div style='font-size: 28px; text-align: center; background:#E3F2FD;
|
|
81
|
+
padding:28px; border-radius:16px; min-height: 150px;'>
|
|
82
|
+
<b>This is a "Slideshow" step.</b><br><br>
|
|
83
|
+
Some apps are just for reading. Your only task is to click the "Next" button to move to the next step.
|
|
84
|
+
</div>
|
|
85
|
+
"""
|
|
86
|
+
)
|
|
87
|
+
step_1_next = gr.Button("Next Step ▶️", variant="primary")
|
|
88
|
+
|
|
89
|
+
# Step 2
|
|
90
|
+
with gr.Column(visible=False) as step_2_container:
|
|
91
|
+
gr.Markdown("<h2 style='text-align:center;'>Step 2: How to Use \"Interactive Demos\"</h2>")
|
|
92
|
+
gr.Markdown(
|
|
93
|
+
"""
|
|
94
|
+
<div style='font-size: 20px; text-align: left; background:#FFF3E0;
|
|
95
|
+
padding:20px; border-radius:16px;'>
|
|
96
|
+
<b>This is an "Interactive Demo."</b><br><br>
|
|
97
|
+
Just follow the numbered steps below (from top to bottom) to see how it works!
|
|
98
|
+
</div>
|
|
99
|
+
"""
|
|
100
|
+
)
|
|
101
|
+
gr.HTML("<br>")
|
|
102
|
+
gr.Markdown(
|
|
103
|
+
"""
|
|
104
|
+
<div style="font-size: 24px; text-align:left; padding-left: 10px;">
|
|
105
|
+
<b>[ 1 ] Use these sliders to change the inputs.</b>
|
|
106
|
+
</div>
|
|
107
|
+
"""
|
|
108
|
+
)
|
|
109
|
+
s_hours = gr.Slider(0, 12, step=0.5, value=6, label="Hours Studied per Week")
|
|
110
|
+
s_sleep = gr.Slider(4, 10, step=0.5, value=7, label="Hours of Sleep per Night")
|
|
111
|
+
s_att = gr.Slider(50, 100, step=1, value=90, label="Class Attendance %")
|
|
112
|
+
|
|
113
|
+
gr.HTML("<hr style='margin: 20px 0;'>")
|
|
114
|
+
|
|
115
|
+
gr.Markdown(
|
|
116
|
+
"""
|
|
117
|
+
<div style="font-size: 24px; text-align:left; padding-left: 10px;">
|
|
118
|
+
<b>[ 2 ] Click this button to run.</b>
|
|
119
|
+
</div>
|
|
120
|
+
"""
|
|
121
|
+
)
|
|
122
|
+
with gr.Row():
|
|
123
|
+
gr.HTML(visible=False)
|
|
124
|
+
go = gr.Button("🔮 Predict", variant="primary", scale=2)
|
|
125
|
+
gr.HTML(visible=False)
|
|
126
|
+
|
|
127
|
+
gr.HTML("<hr style='margin: 20px 0;'>")
|
|
128
|
+
|
|
129
|
+
gr.Markdown(
|
|
130
|
+
"""
|
|
131
|
+
<div style="font-size: 24px; text-align:left; padding-left: 10px;">
|
|
132
|
+
<b>[ 3 ] See the result here!</b>
|
|
133
|
+
</div>
|
|
134
|
+
"""
|
|
135
|
+
)
|
|
136
|
+
out = gr.Textbox(
|
|
137
|
+
label="🔮 Predicted Exam Score", elem_id="prediction_output_textbox", interactive=False
|
|
138
|
+
)
|
|
139
|
+
go.click(predict_exam, [s_hours, s_sleep, s_att], out)
|
|
140
|
+
|
|
141
|
+
gr.HTML("<hr style='margin: 15px 0;'>")
|
|
142
|
+
with gr.Row():
|
|
143
|
+
step_2_back = gr.Button("◀️ Back")
|
|
144
|
+
step_2_next = gr.Button("Finish Tutorial ▶️", variant="primary")
|
|
145
|
+
|
|
146
|
+
# Step 3
|
|
147
|
+
with gr.Column(visible=False) as step_3_container:
|
|
148
|
+
gr.Markdown(
|
|
149
|
+
"""
|
|
150
|
+
<div style='text-align:center;'>
|
|
151
|
+
<h2 style='text-align:center; font-size: 2.5rem;'>✅ Tutorial Complete!</h2>
|
|
152
|
+
<div style='font-size: 1.5rem; background:#E8F5E9; padding:28px; border-radius:16px;
|
|
153
|
+
border: 2px solid #4CAF50;'>
|
|
154
|
+
You've mastered the basics!<br><br>
|
|
155
|
+
Your next step is <b>outside</b> this app window.<br><br>
|
|
156
|
+
<h1 style='margin:0; font-size: 3rem;'>👇 SCROLL DOWN 👇</h1><br>
|
|
157
|
+
Look below this app to find <b>Section 3</b> and begin the challenge!
|
|
158
|
+
</div>
|
|
159
|
+
</div>
|
|
160
|
+
"""
|
|
161
|
+
)
|
|
162
|
+
with gr.Row():
|
|
163
|
+
step_3_back = gr.Button("◀️ Back")
|
|
164
|
+
|
|
165
|
+
# Visibility logic (correct ordering & syntax)
|
|
166
|
+
step_1_next.click(
|
|
167
|
+
lambda: (gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)),
|
|
168
|
+
inputs=None,
|
|
169
|
+
outputs=[step_1_container, step_2_container, step_3_container],
|
|
170
|
+
)
|
|
171
|
+
step_2_back.click(
|
|
172
|
+
lambda: (gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)),
|
|
173
|
+
inputs=None,
|
|
174
|
+
outputs=[step_1_container, step_2_container, step_3_container],
|
|
175
|
+
)
|
|
176
|
+
step_2_next.click(
|
|
177
|
+
lambda: (gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)),
|
|
178
|
+
inputs=None,
|
|
179
|
+
outputs=[step_1_container, step_2_container, step_3_container],
|
|
180
|
+
)
|
|
181
|
+
step_3_back.click(
|
|
182
|
+
lambda: (gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)),
|
|
183
|
+
inputs=None,
|
|
184
|
+
outputs=[step_1_container, step_2_container, step_3_container],
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
return demo
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def launch_tutorial_app(height: int = 950, share: bool = False, debug: bool = False) -> None:
|
|
191
|
+
"""Convenience wrapper to create and launch the tutorial app inline."""
|
|
192
|
+
demo = create_tutorial_app()
|
|
193
|
+
try:
|
|
194
|
+
import gradio as gr # noqa: F401
|
|
195
|
+
except ImportError as e:
|
|
196
|
+
raise ImportError("Gradio must be installed to launch the tutorial app.") from e
|
|
197
|
+
with contextlib.redirect_stdout(open(os.devnull, 'w')), contextlib.redirect_stderr(open(os.devnull, 'w')):
|
|
198
|
+
demo.launch(share=share, inline=True, debug=debug, height=height)
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
"""
|
|
2
|
+
What is AI - Gradio application for the Justice & Equity Challenge.
|
|
3
|
+
|
|
4
|
+
This app teaches:
|
|
5
|
+
1. A simple, non-technical explanation of what AI is
|
|
6
|
+
2. How predictive models work (Input → Model → Output)
|
|
7
|
+
3. Real-world examples and connections to the justice challenge
|
|
8
|
+
|
|
9
|
+
Structure:
|
|
10
|
+
- Factory function `create_what_is_ai_app()` returns a Gradio Blocks object
|
|
11
|
+
- Convenience wrapper `launch_what_is_ai_app()` launches it inline (for notebooks)
|
|
12
|
+
"""
|
|
13
|
+
import contextlib
|
|
14
|
+
import os
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _create_simple_predictor():
|
|
18
|
+
"""Create a simple demonstration predictor for teaching purposes."""
|
|
19
|
+
def predict_outcome(age, priors, severity):
|
|
20
|
+
"""Simple rule-based predictor for demonstration."""
|
|
21
|
+
# Simple scoring logic for demonstration
|
|
22
|
+
score = 0
|
|
23
|
+
|
|
24
|
+
# Age factor (younger = higher risk in this simple model)
|
|
25
|
+
if age < 25:
|
|
26
|
+
score += 3
|
|
27
|
+
elif age < 35:
|
|
28
|
+
score += 2
|
|
29
|
+
else:
|
|
30
|
+
score += 1
|
|
31
|
+
|
|
32
|
+
# Prior offenses factor
|
|
33
|
+
if priors >= 3:
|
|
34
|
+
score += 3
|
|
35
|
+
elif priors >= 1:
|
|
36
|
+
score += 2
|
|
37
|
+
else:
|
|
38
|
+
score += 0
|
|
39
|
+
|
|
40
|
+
# Severity factor
|
|
41
|
+
severity_map = {"Minor": 1, "Moderate": 2, "Serious": 3}
|
|
42
|
+
score += severity_map.get(severity, 2)
|
|
43
|
+
|
|
44
|
+
# Determine risk level
|
|
45
|
+
if score >= 7:
|
|
46
|
+
risk = "High Risk"
|
|
47
|
+
color = "#dc2626"
|
|
48
|
+
emoji = "🔴"
|
|
49
|
+
elif score >= 4:
|
|
50
|
+
risk = "Medium Risk"
|
|
51
|
+
color = "#f59e0b"
|
|
52
|
+
emoji = "🟡"
|
|
53
|
+
else:
|
|
54
|
+
risk = "Low Risk"
|
|
55
|
+
color = "#16a34a"
|
|
56
|
+
emoji = "🟢"
|
|
57
|
+
|
|
58
|
+
return f"""
|
|
59
|
+
<div style='background:white; padding:24px; border-radius:12px; border:3px solid {color}; text-align:center;'>
|
|
60
|
+
<h2 style='color:{color}; margin:0; font-size:2.5rem;'>{emoji} {risk}</h2>
|
|
61
|
+
<p style='font-size:18px; color:#6b7280; margin-top:12px;'>Risk Score: {score}/9</p>
|
|
62
|
+
</div>
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
return predict_outcome
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def create_what_is_ai_app(theme_primary_hue: str = "indigo") -> "gr.Blocks":
|
|
69
|
+
"""Create the What is AI Gradio Blocks app (not launched yet)."""
|
|
70
|
+
try:
|
|
71
|
+
import gradio as gr
|
|
72
|
+
except ImportError as e:
|
|
73
|
+
raise ImportError(
|
|
74
|
+
"Gradio is required for the what is AI app. Install with `pip install gradio`."
|
|
75
|
+
) from e
|
|
76
|
+
|
|
77
|
+
predict_outcome = _create_simple_predictor()
|
|
78
|
+
|
|
79
|
+
css = """
|
|
80
|
+
.large-text {
|
|
81
|
+
font-size: 20px !important;
|
|
82
|
+
}
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue=theme_primary_hue), css=css) as demo:
|
|
86
|
+
gr.Markdown("<h1 style='text-align:center;'>🤖 What is AI, Anyway?</h1>")
|
|
87
|
+
gr.Markdown(
|
|
88
|
+
"""
|
|
89
|
+
<div style='text-align:center; font-size:18px; max-width: 900px; margin: auto;
|
|
90
|
+
padding: 20px; background-color: #e0e7ff; border-radius: 12px; border: 2px solid #6366f1;'>
|
|
91
|
+
Before you can build better AI systems, you need to understand what AI actually is.<br>
|
|
92
|
+
Don't worry - we'll explain it in simple, everyday terms!
|
|
93
|
+
</div>
|
|
94
|
+
"""
|
|
95
|
+
)
|
|
96
|
+
gr.HTML("<hr style='margin:24px 0;'>")
|
|
97
|
+
|
|
98
|
+
# Step 1: Introduction
|
|
99
|
+
with gr.Column(visible=True) as step_1:
|
|
100
|
+
gr.Markdown("<h2 style='text-align:center;'>🎯 A Simple Definition</h2>")
|
|
101
|
+
gr.Markdown(
|
|
102
|
+
"""
|
|
103
|
+
<div style='font-size: 20px; background:#dbeafe; padding:28px; border-radius:16px;'>
|
|
104
|
+
<p><b style='font-size:24px;'>Artificial Intelligence (AI) is just a fancy name for:</b></p>
|
|
105
|
+
|
|
106
|
+
<div style='background:white; padding:24px; border-radius:12px; margin:24px 0; border:3px solid #0284c7;'>
|
|
107
|
+
<h2 style='text-align:center; color:#0284c7; margin:0; font-size:2rem;'>
|
|
108
|
+
A system that makes predictions based on patterns
|
|
109
|
+
</h2>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<p>That's it! Let's break down what that means...</p>
|
|
113
|
+
|
|
114
|
+
<h3 style='color:#0369a1; margin-top:24px;'>Think About How YOU Make Predictions:</h3>
|
|
115
|
+
|
|
116
|
+
<ul style='font-size:19px; margin-top:12px;'>
|
|
117
|
+
<li><b>Weather:</b> Dark clouds → You predict rain → You bring an umbrella</li>
|
|
118
|
+
<li><b>Traffic:</b> Rush hour time → You predict congestion → You leave early</li>
|
|
119
|
+
<li><b>Movies:</b> Actor you like → You predict you'll enjoy it → You watch it</li>
|
|
120
|
+
</ul>
|
|
121
|
+
|
|
122
|
+
<div style='background:#fef3c7; padding:20px; border-radius:8px; margin-top:24px; border-left:6px solid #f59e0b;'>
|
|
123
|
+
<p style='font-size:18px; margin:0;'><b>AI does the same thing, but using data and math
|
|
124
|
+
instead of human experience and intuition.</b></p>
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
"""
|
|
128
|
+
)
|
|
129
|
+
step_1_next = gr.Button("Next: The AI Formula ▶️", variant="primary", size="lg")
|
|
130
|
+
|
|
131
|
+
# Step 2: The Three-Part Formula
|
|
132
|
+
with gr.Column(visible=False) as step_2:
|
|
133
|
+
gr.Markdown("<h2 style='text-align:center;'>📐 The Three-Part Formula</h2>")
|
|
134
|
+
gr.Markdown(
|
|
135
|
+
"""
|
|
136
|
+
<div style='font-size: 20px; background:#f0fdf4; padding:28px; border-radius:16px;'>
|
|
137
|
+
<p>Every AI system works the same way, following this simple formula:</p>
|
|
138
|
+
|
|
139
|
+
<div style='background:white; padding:32px; border-radius:12px; margin:24px 0; text-align:center;'>
|
|
140
|
+
<div style='display:inline-block; background:#dbeafe; padding:16px 24px; border-radius:8px; margin:8px;'>
|
|
141
|
+
<h3 style='margin:0; color:#0369a1;'>1️⃣ INPUT</h3>
|
|
142
|
+
<p style='margin:8px 0 0 0; font-size:16px;'>Data goes in</p>
|
|
143
|
+
</div>
|
|
144
|
+
|
|
145
|
+
<div style='display:inline-block; font-size:2rem; margin:0 16px; color:#6b7280;'>→</div>
|
|
146
|
+
|
|
147
|
+
<div style='display:inline-block; background:#fef3c7; padding:16px 24px; border-radius:8px; margin:8px;'>
|
|
148
|
+
<h3 style='margin:0; color:#92400e;'>2️⃣ MODEL</h3>
|
|
149
|
+
<p style='margin:8px 0 0 0; font-size:16px;'>AI processes it</p>
|
|
150
|
+
</div>
|
|
151
|
+
|
|
152
|
+
<div style='display:inline-block; font-size:2rem; margin:0 16px; color:#6b7280;'>→</div>
|
|
153
|
+
|
|
154
|
+
<div style='display:inline-block; background:#f0fdf4; padding:16px 24px; border-radius:8px; margin:8px;'>
|
|
155
|
+
<h3 style='margin:0; color:#15803d;'>3️⃣ OUTPUT</h3>
|
|
156
|
+
<p style='margin:8px 0 0 0; font-size:16px;'>Prediction comes out</p>
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
|
|
160
|
+
<h3 style='color:#15803d; margin-top:32px;'>Real-World Examples:</h3>
|
|
161
|
+
|
|
162
|
+
<div style='background:white; padding:20px; border-radius:8px; margin:16px 0;'>
|
|
163
|
+
<p style='margin:0; font-size:18px;'>
|
|
164
|
+
<b style='color:#0369a1;'>Input:</b> Photo of a dog<br>
|
|
165
|
+
<b style='color:#92400e;'>Model:</b> Image recognition AI<br>
|
|
166
|
+
<b style='color:#15803d;'>Output:</b> "This is a Golden Retriever"
|
|
167
|
+
</p>
|
|
168
|
+
</div>
|
|
169
|
+
|
|
170
|
+
<div style='background:white; padding:20px; border-radius:8px; margin:16px 0;'>
|
|
171
|
+
<p style='margin:0; font-size:18px;'>
|
|
172
|
+
<b style='color:#0369a1;'>Input:</b> "How's the weather?"<br>
|
|
173
|
+
<b style='color:#92400e;'>Model:</b> Language AI (like ChatGPT)<br>
|
|
174
|
+
<b style='color:#15803d;'>Output:</b> A helpful response
|
|
175
|
+
</p>
|
|
176
|
+
</div>
|
|
177
|
+
|
|
178
|
+
<div style='background:white; padding:20px; border-radius:8px; margin:16px 0;'>
|
|
179
|
+
<p style='margin:0; font-size:18px;'>
|
|
180
|
+
<b style='color:#0369a1;'>Input:</b> Person's criminal history<br>
|
|
181
|
+
<b style='color:#92400e;'>Model:</b> Risk assessment AI<br>
|
|
182
|
+
<b style='color:#15803d;'>Output:</b> "High Risk" or "Low Risk"
|
|
183
|
+
</p>
|
|
184
|
+
</div>
|
|
185
|
+
</div>
|
|
186
|
+
"""
|
|
187
|
+
)
|
|
188
|
+
with gr.Row():
|
|
189
|
+
step_2_back = gr.Button("◀️ Back", size="lg")
|
|
190
|
+
step_2_next = gr.Button("Next: Try It Yourself ▶️", variant="primary", size="lg")
|
|
191
|
+
|
|
192
|
+
# Step 3: Interactive Demo
|
|
193
|
+
with gr.Column(visible=False) as step_3:
|
|
194
|
+
gr.Markdown("<h2 style='text-align:center;'>🎮 Try It Yourself!</h2>")
|
|
195
|
+
gr.Markdown(
|
|
196
|
+
"""
|
|
197
|
+
<div style='font-size: 18px; background:#fef3c7; padding:24px; border-radius:12px; text-align:center;'>
|
|
198
|
+
<p style='margin:0;'><b>Let's use a simple AI model to predict criminal risk.</b><br>
|
|
199
|
+
Adjust the inputs below and see how the model's prediction changes!</p>
|
|
200
|
+
</div>
|
|
201
|
+
"""
|
|
202
|
+
)
|
|
203
|
+
gr.HTML("<br>")
|
|
204
|
+
|
|
205
|
+
gr.Markdown("<h3 style='text-align:center; color:#0369a1;'>1️⃣ INPUT: Adjust the Data</h3>")
|
|
206
|
+
|
|
207
|
+
with gr.Row():
|
|
208
|
+
age_slider = gr.Slider(
|
|
209
|
+
minimum=18,
|
|
210
|
+
maximum=65,
|
|
211
|
+
value=25,
|
|
212
|
+
step=1,
|
|
213
|
+
label="Age",
|
|
214
|
+
info="Defendant's age"
|
|
215
|
+
)
|
|
216
|
+
priors_slider = gr.Slider(
|
|
217
|
+
minimum=0,
|
|
218
|
+
maximum=10,
|
|
219
|
+
value=2,
|
|
220
|
+
step=1,
|
|
221
|
+
label="Prior Offenses",
|
|
222
|
+
info="Number of previous crimes"
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
severity_dropdown = gr.Dropdown(
|
|
226
|
+
choices=["Minor", "Moderate", "Serious"],
|
|
227
|
+
value="Moderate",
|
|
228
|
+
label="Current Charge Severity",
|
|
229
|
+
info="How serious is the current charge?"
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
gr.HTML("<hr style='margin:24px 0;'>")
|
|
233
|
+
|
|
234
|
+
gr.Markdown("<h3 style='text-align:center; color:#92400e;'>2️⃣ MODEL: Process the Data</h3>")
|
|
235
|
+
|
|
236
|
+
predict_btn = gr.Button("🔮 Run AI Prediction", variant="primary", size="lg")
|
|
237
|
+
|
|
238
|
+
gr.HTML("<hr style='margin:24px 0;'>")
|
|
239
|
+
|
|
240
|
+
gr.Markdown("<h3 style='text-align:center; color:#15803d;'>3️⃣ OUTPUT: See the Prediction</h3>")
|
|
241
|
+
|
|
242
|
+
prediction_output = gr.HTML(
|
|
243
|
+
"""
|
|
244
|
+
<div style='background:#f3f4f6; padding:40px; border-radius:12px; text-align:center;'>
|
|
245
|
+
<p style='color:#6b7280; font-size:18px; margin:0;'>
|
|
246
|
+
Click "Run AI Prediction" above to see the result
|
|
247
|
+
</p>
|
|
248
|
+
</div>
|
|
249
|
+
"""
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
# Wire up the prediction
|
|
253
|
+
predict_btn.click(
|
|
254
|
+
predict_outcome,
|
|
255
|
+
inputs=[age_slider, priors_slider, severity_dropdown],
|
|
256
|
+
outputs=prediction_output
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
gr.HTML("<hr style='margin:24px 0;'>")
|
|
260
|
+
|
|
261
|
+
gr.Markdown(
|
|
262
|
+
"""
|
|
263
|
+
<div style='background:#e0f2fe; padding:20px; border-radius:12px; font-size:18px;'>
|
|
264
|
+
<b>What You Just Did:</b><br><br>
|
|
265
|
+
You used a very simple AI model! You provided <b style='color:#0369a1;'>input data</b>
|
|
266
|
+
(age, priors, severity), the <b style='color:#92400e;'>model processed it</b> using rules
|
|
267
|
+
and patterns, and it produced an <b style='color:#15803d;'>output prediction</b>.<br><br>
|
|
268
|
+
Real AI models are more complex, but they work on the same principle!
|
|
269
|
+
</div>
|
|
270
|
+
"""
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
with gr.Row():
|
|
274
|
+
step_3_back = gr.Button("◀️ Back", size="lg")
|
|
275
|
+
step_3_next = gr.Button("Next: Connection to Justice ▶️", variant="primary", size="lg")
|
|
276
|
+
|
|
277
|
+
# Step 4: Connection to the Challenge
|
|
278
|
+
with gr.Column(visible=False) as step_4:
|
|
279
|
+
gr.Markdown("<h2 style='text-align:center;'>🔗 Connecting to Criminal Justice</h2>")
|
|
280
|
+
gr.Markdown(
|
|
281
|
+
"""
|
|
282
|
+
<div style='font-size: 20px; background:#faf5ff; padding:28px; border-radius:16px;'>
|
|
283
|
+
<p><b>Remember the risk prediction you used earlier as a judge?</b></p>
|
|
284
|
+
|
|
285
|
+
<p style='margin-top:20px;'>That was a real-world example of AI in action:</p>
|
|
286
|
+
|
|
287
|
+
<div style='background:white; padding:24px; border-radius:12px; margin:24px 0; border:3px solid #9333ea;'>
|
|
288
|
+
<p style='font-size:18px; margin-bottom:16px;'>
|
|
289
|
+
<b style='color:#0369a1;'>INPUT:</b> Defendant's information<br>
|
|
290
|
+
<span style='margin-left:24px; color:#6b7280;'>• Age, race, gender, prior offenses, charge details</span>
|
|
291
|
+
</p>
|
|
292
|
+
|
|
293
|
+
<p style='font-size:18px; margin:16px 0;'>
|
|
294
|
+
<b style='color:#92400e;'>MODEL:</b> Risk assessment algorithm<br>
|
|
295
|
+
<span style='margin-left:24px; color:#6b7280;'>• Trained on historical criminal justice data</span><br>
|
|
296
|
+
<span style='margin-left:24px; color:#6b7280;'>• Looks for patterns in who re-offended in the past</span>
|
|
297
|
+
</p>
|
|
298
|
+
|
|
299
|
+
<p style='font-size:18px; margin-top:16px; margin-bottom:0;'>
|
|
300
|
+
<b style='color:#15803d;'>OUTPUT:</b> Risk prediction<br>
|
|
301
|
+
<span style='margin-left:24px; color:#6b7280;'>• "High Risk", "Medium Risk", or "Low Risk"</span>
|
|
302
|
+
</p>
|
|
303
|
+
</div>
|
|
304
|
+
|
|
305
|
+
<h3 style='color:#7e22ce; margin-top:32px;'>Why This Matters for Ethics:</h3>
|
|
306
|
+
|
|
307
|
+
<div style='background:#fef2f2; padding:20px; border-radius:8px; margin-top:16px; border-left:6px solid #dc2626;'>
|
|
308
|
+
<ul style='font-size:18px; margin:8px 0;'>
|
|
309
|
+
<li>The <b>input data</b> might contain historical biases</li>
|
|
310
|
+
<li>The <b>model</b> learns patterns from potentially unfair past decisions</li>
|
|
311
|
+
<li>The <b>output predictions</b> can perpetuate discrimination</li>
|
|
312
|
+
</ul>
|
|
313
|
+
</div>
|
|
314
|
+
|
|
315
|
+
<div style='background:#dbeafe; padding:20px; border-radius:8px; margin-top:24px;'>
|
|
316
|
+
<p style='font-size:18px; margin:0;'>
|
|
317
|
+
<b>Understanding how AI works is the first step to building fairer systems.</b><br><br>
|
|
318
|
+
Now that you know what AI is, you're ready to help design better models that
|
|
319
|
+
are more ethical and less biased!
|
|
320
|
+
</p>
|
|
321
|
+
</div>
|
|
322
|
+
</div>
|
|
323
|
+
"""
|
|
324
|
+
)
|
|
325
|
+
with gr.Row():
|
|
326
|
+
step_4_back = gr.Button("◀️ Back", size="lg")
|
|
327
|
+
step_4_next = gr.Button("Complete This Section ▶️", variant="primary", size="lg")
|
|
328
|
+
|
|
329
|
+
# Step 5: Completion
|
|
330
|
+
with gr.Column(visible=False) as step_5:
|
|
331
|
+
gr.Markdown(
|
|
332
|
+
"""
|
|
333
|
+
<div style='text-align:center;'>
|
|
334
|
+
<h2 style='font-size: 2.5rem;'>🎓 You Now Understand AI!</h2>
|
|
335
|
+
<div style='font-size: 1.3rem; background:#e0f2fe; padding:28px; border-radius:16px;
|
|
336
|
+
border: 2px solid #0284c7;'>
|
|
337
|
+
<p><b>Congratulations!</b> You now know:</p>
|
|
338
|
+
|
|
339
|
+
<ul style='font-size:1.1rem; text-align:left; max-width:600px; margin:20px auto;'>
|
|
340
|
+
<li>What AI is (a prediction system)</li>
|
|
341
|
+
<li>How it works (Input → Model → Output)</li>
|
|
342
|
+
<li>Why it matters for criminal justice</li>
|
|
343
|
+
<li>The ethical implications of AI decisions</li>
|
|
344
|
+
</ul>
|
|
345
|
+
|
|
346
|
+
<p style='margin-top:32px;'><b>Next Steps:</b></p>
|
|
347
|
+
<p>In the following sections, you'll learn how to build and improve AI models
|
|
348
|
+
to make them more fair and ethical.</p>
|
|
349
|
+
|
|
350
|
+
<h1 style='margin:20px 0; font-size: 3rem;'>👇 SCROLL DOWN 👇</h1>
|
|
351
|
+
<p style='font-size:1.1rem;'>Continue to the next section below.</p>
|
|
352
|
+
</div>
|
|
353
|
+
</div>
|
|
354
|
+
"""
|
|
355
|
+
)
|
|
356
|
+
back_to_connection_btn = gr.Button("◀️ Back to Review")
|
|
357
|
+
|
|
358
|
+
# Navigation logic
|
|
359
|
+
step_1_next.click(
|
|
360
|
+
lambda: (gr.update(visible=False), gr.update(visible=True), gr.update(visible=False),
|
|
361
|
+
gr.update(visible=False), gr.update(visible=False)),
|
|
362
|
+
inputs=None,
|
|
363
|
+
outputs=[step_1, step_2, step_3, step_4, step_5]
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
step_2_back.click(
|
|
367
|
+
lambda: (gr.update(visible=True), gr.update(visible=False), gr.update(visible=False),
|
|
368
|
+
gr.update(visible=False), gr.update(visible=False)),
|
|
369
|
+
inputs=None,
|
|
370
|
+
outputs=[step_1, step_2, step_3, step_4, step_5]
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
step_2_next.click(
|
|
374
|
+
lambda: (gr.update(visible=False), gr.update(visible=False), gr.update(visible=True),
|
|
375
|
+
gr.update(visible=False), gr.update(visible=False)),
|
|
376
|
+
inputs=None,
|
|
377
|
+
outputs=[step_1, step_2, step_3, step_4, step_5]
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
step_3_back.click(
|
|
381
|
+
lambda: (gr.update(visible=False), gr.update(visible=True), gr.update(visible=False),
|
|
382
|
+
gr.update(visible=False), gr.update(visible=False)),
|
|
383
|
+
inputs=None,
|
|
384
|
+
outputs=[step_1, step_2, step_3, step_4, step_5]
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
step_3_next.click(
|
|
388
|
+
lambda: (gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
|
|
389
|
+
gr.update(visible=True), gr.update(visible=False)),
|
|
390
|
+
inputs=None,
|
|
391
|
+
outputs=[step_1, step_2, step_3, step_4, step_5]
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
step_4_back.click(
|
|
395
|
+
lambda: (gr.update(visible=False), gr.update(visible=False), gr.update(visible=True),
|
|
396
|
+
gr.update(visible=False), gr.update(visible=False)),
|
|
397
|
+
inputs=None,
|
|
398
|
+
outputs=[step_1, step_2, step_3, step_4, step_5]
|
|
399
|
+
)
|
|
400
|
+
|
|
401
|
+
step_4_next.click(
|
|
402
|
+
lambda: (gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
|
|
403
|
+
gr.update(visible=False), gr.update(visible=True)),
|
|
404
|
+
inputs=None,
|
|
405
|
+
outputs=[step_1, step_2, step_3, step_4, step_5]
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
back_to_connection_btn.click(
|
|
409
|
+
lambda: (gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
|
|
410
|
+
gr.update(visible=True), gr.update(visible=False)),
|
|
411
|
+
inputs=None,
|
|
412
|
+
outputs=[step_1, step_2, step_3, step_4, step_5]
|
|
413
|
+
)
|
|
414
|
+
|
|
415
|
+
return demo
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
def launch_what_is_ai_app(height: int = 1100, share: bool = False, debug: bool = False) -> None:
|
|
419
|
+
"""Convenience wrapper to create and launch the what is AI app inline."""
|
|
420
|
+
demo = create_what_is_ai_app()
|
|
421
|
+
try:
|
|
422
|
+
import gradio as gr # noqa: F401
|
|
423
|
+
except ImportError as e:
|
|
424
|
+
raise ImportError("Gradio must be installed to launch the what is AI app.") from e
|
|
425
|
+
with contextlib.redirect_stdout(open(os.devnull, 'w')), contextlib.redirect_stderr(open(os.devnull, 'w')):
|
|
426
|
+
demo.launch(share=share, inline=True, debug=debug, height=height)
|