Dr-P commited on
Commit
095bd28
·
verified ·
1 Parent(s): 13d6657

Upload 2 files

Browse files
Files changed (2) hide show
  1. app (1).py +754 -0
  2. requirements (1).txt +1 -0
app (1).py ADDED
@@ -0,0 +1,754 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import textwrap
2
+ import gradio as gr
3
+
4
+
5
+ def md(text: str) -> str:
6
+ """
7
+ Utility helper:
8
+ - Lets us write long multi-line markdown strings with indentation in the code
9
+ - Removes the extra left-side whitespace before Gradio renders it
10
+
11
+ This makes the file much easier to read and maintain.
12
+ """
13
+ return textwrap.dedent(text).strip()
14
+
15
+
16
+ # ============================================================
17
+ # KNOWLEDGE BASE
18
+ # ------------------------------------------------------------
19
+ # This dictionary is the heart of the teaching app.
20
+ # The key is what appears in the dropdown.
21
+ # The value is the markdown shown to the user.
22
+ #
23
+ # This pattern is important to understand:
24
+ # - UI asks for a topic
25
+ # - Python uses that topic as a dictionary key
26
+ # - App returns the matching explanation
27
+ #
28
+ # That is a very common software pattern:
29
+ # "user selection -> lookup -> render result"
30
+ # ============================================================
31
+ TOPIC_DB = {
32
+ "Git & GitHub": md("""
33
+ ## Git & GitHub
34
+
35
+ **What this is:** Git is version control. GitHub is a remote home for your code, history, branches, pull requests, and automation.
36
+
37
+ **Mental model:**
38
+ - Your laptop is your working lab bench.
39
+ - Git is the notebook that records exactly what changed and when.
40
+ - GitHub is the shared lab vault where other people and automation can see the notebook.
41
+
42
+ **Why it matters for AI builders:**
43
+ - You cannot do CI/CD cleanly without a repository.
44
+ - You cannot safely experiment without branches.
45
+ - You cannot collaborate well without pull requests and commit history.
46
+
47
+ **Core commands to understand:**
48
+ ```bash
49
+ git clone <repo-url>
50
+ git status
51
+ git add .
52
+ git commit -m "Describe the change"
53
+ git push origin main
54
+ git checkout -b feature/my-new-idea
55
+ ```
56
+
57
+ **What you should know cold:**
58
+ 1. `clone` brings a remote repo to your machine.
59
+ 2. `status` tells you what changed.
60
+ 3. `add` stages changes.
61
+ 4. `commit` saves a checkpoint in history.
62
+ 5. `push` sends commits to GitHub.
63
+ 6. Branches let you experiment without breaking main.
64
+
65
+ **Common mistakes:**
66
+ - Editing directly on `main` for risky changes.
67
+ - Committing secrets like API keys.
68
+ - Waiting too long between commits.
69
+
70
+ **Mini-project:**
71
+ Make a repo called `ml-platform-lab`, add one `README.md`, one `app.py`, and commit three times as you refine it.
72
+
73
+ **Free references:**
74
+ - Pro Git: https://git-scm.com/book/en/v2
75
+ - GitHub Actions docs: https://docs.github.com/actions
76
+ """),
77
+
78
+ "HTTP, APIs, and Requests": md("""
79
+ ## HTTP, APIs, and Requests
80
+
81
+ **What this is:** An API is a contract for how software talks to software. Most modern app integrations happen over HTTP.
82
+
83
+ **Mental model:**
84
+ - A client sends a request.
85
+ - A server receives it.
86
+ - The server returns a response, often JSON.
87
+
88
+ **The verbs that matter:**
89
+ - `GET` = read data
90
+ - `POST` = create or trigger something
91
+ - `PUT` / `PATCH` = update
92
+ - `DELETE` = remove
93
+
94
+ **Python example:**
95
+ ```python
96
+ import requests
97
+
98
+ response = requests.get("https://example.com/api/health", timeout=15)
99
+ print(response.status_code)
100
+ print(response.text)
101
+ ```
102
+
103
+ **What good API thinking looks like:**
104
+ - Clear inputs
105
+ - Clear outputs
106
+ - Explicit status codes
107
+ - Validation before work happens
108
+ - Logging when things fail
109
+
110
+ **Why this matters for ML engineers:**
111
+ Models are rarely used by calling Python functions directly in production. They are usually wrapped behind APIs.
112
+
113
+ **Mini-project:**
114
+ Call a public API, parse JSON, and render a simplified result in a Gradio textbox.
115
+
116
+ **Free references:**
117
+ - Requests docs: https://requests.readthedocs.io/
118
+ - FastAPI tutorial: https://fastapi.tiangolo.com/tutorial/
119
+ """),
120
+
121
+ "FastAPI & Pydantic": md("""
122
+ ## FastAPI & Pydantic
123
+
124
+ **What this is:** FastAPI is a Python web framework for building APIs quickly. Pydantic gives you structured, validated input and output models.
125
+
126
+ **Mental model:**
127
+ - FastAPI turns functions into web endpoints.
128
+ - Pydantic defines what valid data looks like.
129
+
130
+ **Very small example:**
131
+ ```python
132
+ from fastapi import FastAPI
133
+ from pydantic import BaseModel
134
+
135
+ app = FastAPI()
136
+
137
+ class PredictionRequest(BaseModel):
138
+ age: int
139
+ income: float
140
+
141
+ @app.post("/predict")
142
+ def predict(payload: PredictionRequest):
143
+ score = 0.6 if payload.income > 50000 else 0.3
144
+ return {"score": score}
145
+ ```
146
+
147
+ **Why it matters:**
148
+ - You already know Python.
149
+ - Type hints and schemas reduce ambiguity.
150
+ - The framework auto-generates docs, which is great for learning and debugging.
151
+
152
+ **What to understand deeply:**
153
+ 1. Path operation decorators like `@app.get` and `@app.post`
154
+ 2. Request body vs query parameters
155
+ 3. Validation errors
156
+ 4. JSON in, JSON out
157
+ 5. Separation of app layer from model layer
158
+
159
+ **Mini-project:**
160
+ Put a toy model or even a rules engine behind `/predict`, then call it from a notebook or another Python script.
161
+
162
+ **Free references:**
163
+ - FastAPI main docs: https://fastapi.tiangolo.com/
164
+ - FastAPI tutorial: https://fastapi.tiangolo.com/tutorial/
165
+ """),
166
+
167
+ "Docker": md("""
168
+ ## Docker
169
+
170
+ **What this is:** Docker packages your app and its runtime into a container so it runs more consistently across machines.
171
+
172
+ **Mental model:**
173
+ - Your code alone is not enough.
174
+ - You also need the right Python version, packages, and startup command.
175
+ - A container bundles those together.
176
+
177
+ **Useful distinction:**
178
+ - **Image** = blueprint
179
+ - **Container** = running instance from the blueprint
180
+
181
+ **Tiny Dockerfile example:**
182
+ ```dockerfile
183
+ FROM python:3.10-slim
184
+ WORKDIR /app
185
+ COPY requirements.txt .
186
+ RUN pip install --no-cache-dir -r requirements.txt
187
+ COPY . .
188
+ CMD ["python", "app.py"]
189
+ ```
190
+
191
+ **Why it matters for you:**
192
+ Docker is the bridge between "it works on my laptop" and "it works in a deployment target."
193
+
194
+ **Mini-project:**
195
+ Containerize a FastAPI hello-world app and run it locally.
196
+
197
+ **Free references:**
198
+ - Docker overview: https://docs.docker.com/get-started/docker-overview/
199
+ - Docker getting started: https://docs.docker.com/get-started/
200
+ """),
201
+
202
+ "CI/CD with GitHub Actions": md("""
203
+ ## CI/CD with GitHub Actions
204
+
205
+ **What this is:** CI/CD automates build, test, and deployment workflows. GitHub Actions runs those workflows from your repository.
206
+
207
+ **Mental model:**
208
+ - A code change happens.
209
+ - Automation wakes up.
210
+ - Tests run.
211
+ - Optional deployment happens only if checks pass.
212
+
213
+ **Minimal workflow example:**
214
+ ```yaml
215
+ name: ci
216
+ on: [push, pull_request]
217
+ jobs:
218
+ test:
219
+ runs-on: ubuntu-latest
220
+ steps:
221
+ - uses: actions/checkout@v4
222
+ - uses: actions/setup-python@v5
223
+ with:
224
+ python-version: '3.10'
225
+ - run: python -m pip install --upgrade pip
226
+ - run: pip install -r requirements.txt
227
+ - run: python -m py_compile app.py
228
+ ```
229
+
230
+ **Why it matters:**
231
+ - Catch issues before deployment.
232
+ - Standardize checks.
233
+ - Create trust in main branch.
234
+
235
+ **Mini-project:**
236
+ Add the above workflow to a repo and make sure every push at least syntax-checks your app.
237
+
238
+ **Free references:**
239
+ - GitHub Actions quickstart: https://docs.github.com/actions/quickstart
240
+ - GitHub Actions docs: https://docs.github.com/actions
241
+ """),
242
+
243
+ "Kubernetes": md("""
244
+ ## Kubernetes
245
+
246
+ **What this is:** Kubernetes orchestrates containers across machines. It helps with scaling, rolling updates, service discovery, health checks, and resilience.
247
+
248
+ **Mental model:**
249
+ Docker gives you one packaged app. Kubernetes manages many running containers in a controlled cluster environment.
250
+
251
+ **What not to do:**
252
+ Do not start here unless you already understand local Python apps, APIs, Git, containers, and one simple deployment target.
253
+
254
+ **Terms you should recognize:**
255
+ - Pod
256
+ - Deployment
257
+ - Service
258
+ - Ingress
259
+ - ConfigMap
260
+ - Secret
261
+
262
+ **Why it matters:**
263
+ Even if you are not the platform engineer, you need to be able to read deployment conversations and debug the shape of a service.
264
+
265
+ **Mini-project:**
266
+ Read one minimal deployment YAML and explain it line by line. That is enough for a first pass.
267
+
268
+ **Free references:**
269
+ - Kubernetes docs: https://kubernetes.io/docs/home/
270
+ """),
271
+
272
+ "MCP": md("""
273
+ ## MCP (Model Context Protocol)
274
+
275
+ **What this is:** MCP is a standard for connecting AI applications to tools, resources, and prompts.
276
+
277
+ **Mental model:**
278
+ - A normal REST API exposes endpoints for software-to-software use.
279
+ - An MCP server exposes capabilities that an AI client can discover and use more natively.
280
+
281
+ **Three ideas to know:**
282
+ - **Resources**: readable context, like files or database-derived information
283
+ - **Tools**: callable actions
284
+ - **Prompts**: pre-defined reusable instructions
285
+
286
+ **Why it matters:**
287
+ As AI products become more tool-using and context-rich, MCP gives a cleaner interoperability model than one-off custom glue code.
288
+
289
+ **Mini-project:**
290
+ Read the architecture overview and build one mental map showing client, server, tools, and resources.
291
+
292
+ **Free references:**
293
+ - MCP home: https://modelcontextprotocol.io/
294
+ - Architecture overview: https://modelcontextprotocol.io/docs/learn/architecture
295
+ - Build a server: https://modelcontextprotocol.io/docs/develop/build-server
296
+ """),
297
+
298
+ "MLOps & Deployment Thinking": md("""
299
+ ## MLOps & Deployment Thinking
300
+
301
+ **What this is:** MLOps is the set of practices for getting models and AI systems into reliable operation.
302
+
303
+ **Mental model:**
304
+ Training a model is only one stage. Real systems need:
305
+ 1. data ingestion
306
+ 2. feature logic
307
+ 3. model or prompting layer
308
+ 4. validation
309
+ 5. serving
310
+ 6. logging
311
+ 7. monitoring
312
+ 8. iteration
313
+
314
+ **For your background:**
315
+ You already have the quantitative side. The gap is usually on packaging, interfaces, environments, and lifecycle reliability.
316
+
317
+ **Your shortest path to competence:**
318
+ - build a toy rule-based service
319
+ - convert it to a FastAPI endpoint
320
+ - wrap it in Docker
321
+ - add CI
322
+ - deploy it
323
+ - explain the architecture in plain English
324
+
325
+ **Free references:**
326
+ - Full Stack Deep Learning: https://fullstackdeeplearning.com/
327
+ - Hugging Face Learn: https://huggingface.co/learn
328
+ """)
329
+ }
330
+
331
+
332
+ REFERENCE_LIBRARY = md("""
333
+ # Free references inside this app
334
+
335
+ ## Official docs and free learning resources
336
+ - Git / Pro Git: https://git-scm.com/book/en/v2
337
+ - Requests: https://requests.readthedocs.io/
338
+ - FastAPI: https://fastapi.tiangolo.com/
339
+ - Docker Get Started: https://docs.docker.com/get-started/
340
+ - GitHub Actions: https://docs.github.com/actions
341
+ - Kubernetes docs: https://kubernetes.io/docs/home/
342
+ - Model Context Protocol: https://modelcontextprotocol.io/
343
+ - Hugging Face Learn: https://huggingface.co/learn
344
+ - Full Stack Deep Learning: https://fullstackdeeplearning.com/
345
+
346
+ ## Suggested order for you
347
+ 1. Git basics
348
+ 2. HTTP + requests
349
+ 3. FastAPI + Pydantic
350
+ 4. Docker
351
+ 5. GitHub Actions
352
+ 6. Deploy a Space or small web service
353
+ 7. Kubernetes fundamentals
354
+ 8. MCP fundamentals
355
+ """)
356
+
357
+
358
+ DEPLOY_GUIDE = md("""
359
+ # How to deploy this app to a Gradio Space
360
+
361
+ 1. Create a new Hugging Face Space.
362
+ 2. Pick **Gradio** as the SDK.
363
+ 3. Replace the repo's `README.md` with a metadata block that includes `sdk: gradio` and `app_file: app.py`.
364
+ 4. Add this `app.py` file.
365
+ 5. Add the `requirements.txt` file provided with this package.
366
+ 6. Commit the files.
367
+ 7. Open the Space once the build finishes.
368
+
369
+ ## Why the files matter
370
+ - `README.md` contains the Space metadata block.
371
+ - `app.py` is the main application file.
372
+ - `requirements.txt` lists the Python dependencies.
373
+
374
+ ## Next level
375
+ Once you understand this app, create a second repo where you replace the pure-Python recommendation functions with a real FastAPI backend or a model-serving layer.
376
+ """)
377
+
378
+
379
+ def render_topic(topic: str) -> str:
380
+ return TOPIC_DB.get(topic, "Select a topic.")
381
+
382
+
383
+ def recommend_stack(primary_goal, deployment_target, data_type, team_size, hours_per_week):
384
+ if primary_goal == "Ship ML/AI demos reliably":
385
+ order = [
386
+ "Gradio app -> Git -> GitHub -> Docker basics -> GitHub Actions -> hosted deployment",
387
+ "Then repeat the same project as a FastAPI service.",
388
+ "Only after that, learn Kubernetes vocabulary and deployment anatomy.",
389
+ ]
390
+ first_project = "Build one demo that takes input, returns a decision, and logs edge cases."
391
+
392
+ elif primary_goal == "Build real APIs for models":
393
+ order = [
394
+ "HTTP fundamentals -> requests -> FastAPI -> Pydantic -> local testing",
395
+ "Then containerize with Docker and add CI.",
396
+ "Deploy after the local and container versions both work cleanly.",
397
+ ]
398
+ first_project = "Create `/health` and `/predict` endpoints for a toy model or rules engine."
399
+
400
+ elif primary_goal == "Understand platform / DevOps conversations":
401
+ order = [
402
+ "Git and CI/CD language first.",
403
+ "Docker concepts second.",
404
+ "Kubernetes objects third: pod, deployment, service, ingress, secret.",
405
+ "MCP after you already understand tools, services, and interfaces.",
406
+ ]
407
+ first_project = "Take one deployment diagram and explain every box, arrow, and environment variable."
408
+
409
+ else:
410
+ order = [
411
+ "Git -> APIs -> FastAPI -> Docker -> CI/CD -> deployment -> Kubernetes basics -> MCP",
412
+ "Do not split attention across five stacks at once.",
413
+ "Use one project as the backbone for every new concept.",
414
+ ]
415
+ first_project = "Build a single project repeatedly in deeper forms instead of many unrelated mini-projects."
416
+
417
+ complexity = "solo-friendly" if team_size == "Solo / 1-2 people" else "team-process aware"
418
+
419
+ time_note = (
420
+ "You have enough time each week to make real progress; prioritize shipping one working artifact weekly."
421
+ if hours_per_week >= 8
422
+ else "Keep the scope tiny and focus on one working deliverable per week."
423
+ )
424
+
425
+ if deployment_target == "Hugging Face Space":
426
+ deploy_note = "Start with Gradio Spaces for speed and confidence, then graduate to Dockerized apps."
427
+ elif deployment_target == "Cloud VM / simple host":
428
+ deploy_note = "Bias toward FastAPI + Docker because that stack transfers better to generic hosting."
429
+ else:
430
+ deploy_note = "Learn Docker deeply before touching cluster-level concepts."
431
+
432
+ data_note = {
433
+ "Mostly tabular / structured": "Tabular data makes it easy to prototype small prediction or scoring services.",
434
+ "Mostly text / documents": "Text workflows pair naturally with LLM-style apps, extraction, routing, and summarization.",
435
+ "Mixed / multimodal": "Mixed inputs are powerful but easier to overcomplicate. Start with one narrow slice.",
436
+ }[data_type]
437
+
438
+ bullets = "\n".join([f"- {line}" for line in order])
439
+
440
+ return md(f"""
441
+ ## Recommended pathway
442
+
443
+ **Primary goal:** {primary_goal}
444
+
445
+ **Recommended learning/build order:**
446
+ {bullets}
447
+
448
+ **First project:** {first_project}
449
+
450
+ **Deployment note:** {deploy_note}
451
+
452
+ **Data note:** {data_note}
453
+
454
+ **Process note:** You are working in a **{complexity}** mode.
455
+
456
+ **Time note:** {time_note}
457
+
458
+ ## What success looks like after 30 days
459
+ 1. You can explain the difference between a script, an API, a container, CI/CD, and orchestration.
460
+ 2. You can deploy one Gradio app and one FastAPI-style service prototype.
461
+ 3. You can read a Dockerfile and a GitHub Actions workflow without feeling lost.
462
+ 4. You can follow an MCP tutorial without the terminology feeling alien.
463
+ """)
464
+
465
+
466
+ SCAFFOLDS = {
467
+ "Gradio teaching app": md("""
468
+ ## Blueprint: Gradio teaching app
469
+
470
+ ```text
471
+ project/
472
+ ├── README.md
473
+ ├── app.py
474
+ └── assets/ # optional images or data files
475
+ ```
476
+
477
+ **Purpose:** Best first deployment target when speed matters more than backend purity.
478
+
479
+ **What to practice:**
480
+ - UI layout
481
+ - Python functions as app logic
482
+ - deployment flow on Hugging Face Spaces
483
+ - simple input/output design
484
+
485
+ **Good first extension:**
486
+ Add a logging area, examples, or a quiz tab.
487
+ """),
488
+
489
+ "FastAPI microservice": md("""
490
+ ## Blueprint: FastAPI microservice
491
+
492
+ ```text
493
+ project/
494
+ ├── README.md
495
+ ├── requirements.txt
496
+ ├── app/
497
+ │ ├── main.py
498
+ │ ├── schemas.py
499
+ │ ├── services.py
500
+ │ └── utils.py
501
+ └── tests/
502
+ └── test_smoke.py
503
+ ```
504
+
505
+ **Purpose:** Best when you need explicit API endpoints and cleaner production migration.
506
+
507
+ **What to practice:**
508
+ - request/response models
509
+ - validation
510
+ - separation of business logic from web layer
511
+ - testability
512
+
513
+ **Good first extension:**
514
+ Add `/health` and `/predict`, then call the service from a notebook or a Gradio front end.
515
+ """),
516
+
517
+ "Dockerized ML service": md("""
518
+ ## Blueprint: Dockerized ML service
519
+
520
+ ```text
521
+ project/
522
+ ├── README.md
523
+ ├── requirements.txt
524
+ ├── Dockerfile
525
+ ├── .dockerignore
526
+ ├── app/
527
+ │ ├── main.py
528
+ │ ├── model_logic.py
529
+ │ └── schemas.py
530
+ └── tests/
531
+ └── test_api.py
532
+ ```
533
+
534
+ **Purpose:** Best bridge from local development to reliable deployment.
535
+
536
+ **What to practice:**
537
+ - image creation
538
+ - environment management
539
+ - startup commands
540
+ - reproducibility
541
+
542
+ **Good first extension:**
543
+ Add CI that syntax-checks and builds the container automatically.
544
+ """),
545
+
546
+ "CI/CD-ready repo": md("""
547
+ ## Blueprint: CI/CD-ready repo
548
+
549
+ ```text
550
+ project/
551
+ ├── README.md
552
+ ├── requirements.txt
553
+ ├── app.py
554
+ └── .github/
555
+ └── workflows/
556
+ └── ci.yml
557
+ ```
558
+
559
+ **Purpose:** Best for learning automated quality gates early.
560
+
561
+ **What to practice:**
562
+ - event triggers on push and pull request
563
+ - deterministic install steps
564
+ - automated syntax checks or tests
565
+
566
+ **Good first extension:**
567
+ Add Docker build or deployment steps after the basic checks pass.
568
+ """)
569
+ }
570
+
571
+
572
+ def render_scaffold(name: str) -> str:
573
+ return SCAFFOLDS.get(name, "Select a blueprint.")
574
+
575
+
576
+ QUIZ_KEY = {
577
+ "q1": "An app contract for software-to-software communication",
578
+ "q2": "A package blueprint used to create running containers",
579
+ "q3": "Automating build, test, and deployment workflows",
580
+ "q4": "A Python framework for building APIs",
581
+ "q5": "The main file path for the Space app",
582
+ "q6": "A standard for exposing AI tools, resources, and prompts",
583
+ }
584
+
585
+
586
+ def grade_quiz(q1, q2, q3, q4, q5, q6):
587
+ answers = {"q1": q1, "q2": q2, "q3": q3, "q4": q4, "q5": q5, "q6": q6}
588
+ score = sum(1 for key, value in answers.items() if value == QUIZ_KEY[key])
589
+
590
+ feedback = []
591
+ for key, expected in QUIZ_KEY.items():
592
+ status = "✅" if answers[key] == expected else "❌"
593
+ feedback.append(f"{status} {key.upper()}: {expected}")
594
+
595
+ feedback_md = "\n".join([f"- {item}" for item in feedback])
596
+
597
+ if score == 6:
598
+ verdict = "Excellent. You are reading the platform vocabulary correctly."
599
+ elif score >= 4:
600
+ verdict = "Good. You are close, but a few terms still need repetition."
601
+ else:
602
+ verdict = "This is normal early on. Revisit the Concept Explorer and do one small build step next."
603
+
604
+ return md(f"""
605
+ ## Score: {score}/6
606
+
607
+ **Verdict:** {verdict}
608
+
609
+ **Answer key:**
610
+ {feedback_md}
611
+ """)
612
+
613
+
614
+ INTRO = md("""
615
+ # AI Platform Engineering Accelerator
616
+
617
+ This Space is built for a technically strong ML/physics person who wants to close the gap on software engineering, APIs, deployment, CI/CD, containers, Kubernetes, and MCP.
618
+
619
+ ## How to use this app
620
+ 1. Start in **Concept Explorer** and read one topic at a time.
621
+ 2. Go to **Architecture Lab** and let the app recommend an order of operations.
622
+ 3. Use **Repo Blueprint** to understand what a minimal project should look like.
623
+ 4. Use **Self-Check** to make sure the vocabulary is sticking.
624
+ 5. Read **Deploy This Space** so you understand how the app itself is hosted.
625
+
626
+ ## Important learning philosophy
627
+ Do not try to become a Kubernetes wizard first.
628
+ Become the person who can reliably ship one small Python service end to end.
629
+ """)
630
+
631
+
632
+ with gr.Blocks(title="AI Platform Engineering Accelerator") as demo:
633
+ gr.Markdown(INTRO)
634
+
635
+ with gr.Tab("Concept Explorer"):
636
+ topic = gr.Dropdown(list(TOPIC_DB.keys()), value="Git & GitHub", label="Pick a topic")
637
+ topic_btn = gr.Button("Explain this topic")
638
+ topic_out = gr.Markdown(value=render_topic("Git & GitHub"))
639
+ topic_btn.click(render_topic, inputs=topic, outputs=topic_out)
640
+
641
+ with gr.Tab("Architecture Lab"):
642
+ primary_goal = gr.Radio(
643
+ [
644
+ "Ship ML/AI demos reliably",
645
+ "Build real APIs for models",
646
+ "Understand platform / DevOps conversations",
647
+ "Become end-to-end technical as fast as possible",
648
+ ],
649
+ value="Become end-to-end technical as fast as possible",
650
+ label="What is your main goal right now?",
651
+ )
652
+
653
+ deployment_target = gr.Radio(
654
+ ["Hugging Face Space", "Cloud VM / simple host", "Kubernetes later"],
655
+ value="Hugging Face Space",
656
+ label="What deployment target feels most realistic first?",
657
+ )
658
+
659
+ data_type = gr.Radio(
660
+ ["Mostly tabular / structured", "Mostly text / documents", "Mixed / multimodal"],
661
+ value="Mostly text / documents",
662
+ label="What kind of AI work are you most likely to build first?",
663
+ )
664
+
665
+ team_size = gr.Radio(
666
+ ["Solo / 1-2 people", "Small team / cross-functional"],
667
+ value="Solo / 1-2 people",
668
+ label="What is your current working mode?",
669
+ )
670
+
671
+ hours_per_week = gr.Slider(2, 20, value=8, step=1, label="Hours per week you can seriously invest")
672
+
673
+ plan_btn = gr.Button("Generate my pathway")
674
+ plan_out = gr.Markdown()
675
+
676
+ plan_btn.click(
677
+ recommend_stack,
678
+ inputs=[primary_goal, deployment_target, data_type, team_size, hours_per_week],
679
+ outputs=plan_out,
680
+ )
681
+
682
+ with gr.Tab("Repo Blueprint"):
683
+ scaffold = gr.Radio(list(SCAFFOLDS.keys()), value="Gradio teaching app", label="Choose a project blueprint")
684
+ scaffold_btn = gr.Button("Show blueprint")
685
+ scaffold_out = gr.Markdown(value=render_scaffold("Gradio teaching app"))
686
+ scaffold_btn.click(render_scaffold, inputs=scaffold, outputs=scaffold_out)
687
+
688
+ with gr.Tab("Self-Check"):
689
+ q1 = gr.Radio(
690
+ [
691
+ "A database schema",
692
+ "An app contract for software-to-software communication",
693
+ "A container orchestrator",
694
+ ],
695
+ label="1) What is an API?",
696
+ )
697
+
698
+ q2 = gr.Radio(
699
+ [
700
+ "A package blueprint used to create running containers",
701
+ "A live cluster node",
702
+ "A Git branch",
703
+ ],
704
+ label="2) What is a Docker image?",
705
+ )
706
+
707
+ q3 = gr.Radio(
708
+ [
709
+ "A way to label datasets",
710
+ "Automating build, test, and deployment workflows",
711
+ "A Python package manager",
712
+ ],
713
+ label="3) What is CI/CD?",
714
+ )
715
+
716
+ q4 = gr.Radio(
717
+ [
718
+ "A Python framework for building APIs",
719
+ "A GPU runtime",
720
+ "A GitHub feature for branches",
721
+ ],
722
+ label="4) What is FastAPI?",
723
+ )
724
+
725
+ q5 = gr.Radio(
726
+ [
727
+ "The name of the Space owner",
728
+ "The main file path for the Space app",
729
+ "A private token",
730
+ ],
731
+ label="5) In a Hugging Face Space README metadata block, what is `app_file` for?",
732
+ )
733
+
734
+ q6 = gr.Radio(
735
+ [
736
+ "A standard for exposing AI tools, resources, and prompts",
737
+ "A Linux package manager",
738
+ "A database migration strategy",
739
+ ],
740
+ label="6) What is MCP?",
741
+ )
742
+
743
+ quiz_btn = gr.Button("Grade quiz")
744
+ quiz_out = gr.Markdown()
745
+ quiz_btn.click(grade_quiz, inputs=[q1, q2, q3, q4, q5, q6], outputs=quiz_out)
746
+
747
+ with gr.Tab("Deploy This Space"):
748
+ gr.Markdown(DEPLOY_GUIDE)
749
+
750
+ with gr.Tab("References"):
751
+ gr.Markdown(REFERENCE_LIBRARY)
752
+
753
+
754
+ demo.launch()
requirements (1).txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio>=5.0