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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import textwrap
2
+ import gradio as gr
3
+
4
+
5
+ def md(text: str) -> str:
6
+ """
7
+ Small formatting helper so long markdown strings stay readable in code.
8
+ """
9
+ return textwrap.dedent(text).strip()
10
+
11
+
12
+ # ============================================================
13
+ # GLOSSARY DATABASE
14
+ # ------------------------------------------------------------
15
+ # This app is intentionally simpler and less technical.
16
+ # It assumes the learner may not know how repos, APIs,
17
+ # containers, or ML engineering fit together.
18
+ #
19
+ # Each term has:
20
+ # - a plain-English definition
21
+ # - a business analogy
22
+ # - a "what to learn first" section
23
+ # ============================================================
24
+ TERM_DB = {
25
+ "Software engineering": md("""
26
+ ## Software engineering
27
+
28
+ **Plain-English meaning:** Building software in a way that other people can understand, test, maintain, and improve.
29
+
30
+ **Business analogy:**
31
+ This is the difference between a one-off clever spreadsheet and a repeatable business process with documentation.
32
+
33
+ **What to learn first:**
34
+ - files and folders
35
+ - functions
36
+ - Git
37
+ - debugging
38
+ - testing mindset
39
+ """),
40
+
41
+ "API": md("""
42
+ ## API
43
+
44
+ **Plain-English meaning:** A clearly defined way for one system to ask another system to do something or send back data.
45
+
46
+ **Business analogy:**
47
+ Think of an API like a standard intake form between departments. The format matters.
48
+
49
+ **What to learn first:**
50
+ - request
51
+ - response
52
+ - JSON
53
+ - GET vs POST
54
+ """),
55
+
56
+ "Docker": md("""
57
+ ## Docker
58
+
59
+ **Plain-English meaning:** A way to package an app so it runs more consistently across environments.
60
+
61
+ **Business analogy:**
62
+ It is like shipping not just the recipe, but the kitchen setup too.
63
+
64
+ **What to learn first:**
65
+ - image vs container
66
+ - Dockerfile
67
+ - why environment drift is painful
68
+ """),
69
+
70
+ "CI/CD": md("""
71
+ ## CI/CD
72
+
73
+ **Plain-English meaning:** Automation that checks code and sometimes deploys it when changes are made.
74
+
75
+ **Business analogy:**
76
+ It is a quality gate plus release pipeline.
77
+
78
+ **What to learn first:**
79
+ - what happens on a code push
80
+ - what a workflow file is
81
+ - why automated checks reduce chaos
82
+ """),
83
+
84
+ "ML engineer": md("""
85
+ ## ML engineer
86
+
87
+ **Plain-English meaning:** The person who helps make machine learning useful in a real product or workflow.
88
+
89
+ **Business analogy:**
90
+ A data scientist proves value; an ML engineer makes that value repeatable and deployable.
91
+
92
+ **What to learn first:**
93
+ - data pipeline basics
94
+ - model inputs and outputs
95
+ - APIs
96
+ - deployment
97
+ - monitoring
98
+ """),
99
+
100
+ "MLOps": md("""
101
+ ## MLOps
102
+
103
+ **Plain-English meaning:** The operating discipline around training, shipping, observing, and updating ML systems.
104
+
105
+ **Business analogy:**
106
+ It is operations for machine learning, not just modeling.
107
+
108
+ **What to learn first:**
109
+ - experiment tracking
110
+ - versioning
111
+ - deployment
112
+ - monitoring
113
+ - iteration
114
+ """),
115
+
116
+ "Hugging Face Space": md("""
117
+ ## Hugging Face Space
118
+
119
+ **Plain-English meaning:** A hosted app repo where you can deploy Gradio, Docker, or static apps.
120
+
121
+ **Business analogy:**
122
+ Think of it as a lightweight demo showroom for AI apps.
123
+
124
+ **What to learn first:**
125
+ - README metadata block
126
+ - `app.py`
127
+ - commit and rebuild cycle
128
+ """)
129
+ }
130
+
131
+
132
+ COURSE_LIBRARY = md("""
133
+ # Free and beginner-friendly references
134
+
135
+ ## Beginner coding
136
+ - CS50 Python: https://cs50.harvard.edu/python
137
+
138
+ ## Modern AI / LLM learning
139
+ - Hugging Face Learn: https://huggingface.co/learn
140
+ - Hugging Face LLM Course: https://huggingface.co/learn/llm-course/chapter1/1
141
+
142
+ ## Building real AI products
143
+ - Full Stack Deep Learning: https://fullstackdeeplearning.com/
144
+
145
+ ## Practical docs you eventually grow into
146
+ - FastAPI: https://fastapi.tiangolo.com/
147
+ - Docker Get Started: https://docs.docker.com/get-started/
148
+ - GitHub Actions: https://docs.github.com/actions
149
+ - Model Context Protocol: https://modelcontextprotocol.io/
150
+ """)
151
+
152
+
153
+ DEPLOY_GUIDE = md("""
154
+ # How to deploy this beginner app to a Gradio Space
155
+
156
+ 1. Create a new Hugging Face Space.
157
+ 2. Choose **Gradio**.
158
+ 3. Replace the repo's `README.md` with a metadata block that includes `sdk: gradio` and `app_file: app.py` or `app_file: app1.py`.
159
+ 4. Paste this `app1.py` file.
160
+ 5. Add the `requirements_app1.txt` file provided with this package.
161
+ 6. Commit the changes.
162
+ 7. Open the Space and click through the tabs.
163
+
164
+ This app uses only Gradio and the Python standard library, so the dependency file stays very small.
165
+ """)
166
+
167
+
168
+ def explain_term(term: str) -> str:
169
+ return TERM_DB.get(term, "Select a term.")
170
+
171
+
172
+ def classify_project(problem_type, data_readiness, risk_level, time_horizon, technical_help):
173
+ if problem_type == "Summarize, extract, search, or chat with documents":
174
+ approach = "Start with an LLM workflow or retrieval-style app"
175
+ first_build = "A narrow document assistant with 10-20 realistic examples"
176
+ warning = "Do not promise full automation before you test edge cases and hallucination risks."
177
+
178
+ elif problem_type == "Predict a numeric value or class label":
179
+ approach = "Start with a supervised ML prototype"
180
+ first_build = "A baseline model with a clear label, clean sample data, and one metric"
181
+ warning = "Do not jump to deep learning before you prove a simple baseline is useful."
182
+
183
+ elif problem_type == "Automate repetitive form-like business decisions":
184
+ approach = "Start with rules-based automation first"
185
+ first_build = "A decision rules prototype with explicit inputs and outputs"
186
+ warning = "Many business workflows look like AI problems but are solved faster with rules first."
187
+
188
+ else:
189
+ approach = "Start with process mapping, then add AI where it clearly helps"
190
+ first_build = "A scoped proof of concept tied to one business action"
191
+ warning = "Avoid vague 'AI platform' projects with no narrow first use case."
192
+
193
+ data_note = {
194
+ "No clean data yet": "You likely need data cleanup, examples, or manual labeling before serious modeling.",
195
+ "Some spreadsheets / exports": "That is enough for a first prototype if the fields are understandable.",
196
+ "Clean structured data": "You are in strong shape for a simple prototype.",
197
+ }[data_readiness]
198
+
199
+ risk_note = {
200
+ "Low": "You can move quickly with demos and user feedback.",
201
+ "Medium": "Build review points and basic testing into the process.",
202
+ "High / regulated": "Bias toward traceability, validation, auditability, and human review.",
203
+ }[risk_level]
204
+
205
+ time_note = {
206
+ "2 weeks": "Scope down to a clickable demo, not a full production product.",
207
+ "1 month": "Aim for a working prototype with a few realistic examples and basic error handling.",
208
+ "2+ months": "You can include better structure, documentation, and deployment discipline.",
209
+ }[time_horizon]
210
+
211
+ help_note = {
212
+ "Mostly solo": "Prefer Gradio, simple Python, and small datasets.",
213
+ "One technical partner": "Good moment to split front-end demo and backend logic responsibilities.",
214
+ "Access to engineers": "Use this app to understand terminology so you can coordinate more effectively.",
215
+ }[technical_help]
216
+
217
+ return md(f"""
218
+ ## Recommended project shape
219
+
220
+ **Recommended approach:** {approach}
221
+
222
+ **First build:** {first_build}
223
+
224
+ **Data note:** {data_note}
225
+
226
+ **Risk note:** {risk_note}
227
+
228
+ **Timeline note:** {time_note}
229
+
230
+ **Team note:** {help_note}
231
+
232
+ **Important caution:** {warning}
233
+
234
+ ## First three actions
235
+ 1. Write down the exact business decision this tool should improve.
236
+ 2. Gather 10-20 realistic examples.
237
+ 3. Define what a successful output looks like before adding complexity.
238
+ """)
239
+
240
+
241
+ CODE_WALKTHROUGH = md("""
242
+ # How to read an app like this
243
+
244
+ ## 1) Imports
245
+ ```python
246
+ import textwrap
247
+ import gradio as gr
248
+ ```
249
+ - `textwrap` helps format long strings neatly.
250
+ - `gradio` is the UI framework.
251
+
252
+ ## 2) Knowledge dictionaries
253
+ This app stores explanations in Python dictionaries.
254
+ That means the interface can look up a term and show the matching explanation.
255
+
256
+ ## 3) Functions
257
+ Each button in a Gradio app usually calls a Python function.
258
+
259
+ Example pattern:
260
+ ```python
261
+ button.click(fn=my_function, inputs=[component_a], outputs=[component_b])
262
+ ```
263
+
264
+ That line means:
265
+ - when the button is pressed,
266
+ - run `my_function` using the input component values,
267
+ - then display the result in the output component.
268
+
269
+ ## 4) Layout
270
+ `with gr.Blocks()` creates the app.
271
+ Tabs, rows, buttons, radios, and text boxes are created inside it.
272
+
273
+ ## 5) Launch
274
+ ```python
275
+ demo.launch()
276
+ ```
277
+ This starts the app.
278
+ On Hugging Face Spaces, the platform builds the repo and runs the app for you.
279
+
280
+ ## 6) What to change first
281
+ - add one new glossary term
282
+ - modify one recommendation rule
283
+ - rename one UI label
284
+ - add one new tab
285
+
286
+ That is enough to start feeling ownership over the code.
287
+ """)
288
+
289
+
290
+ def make_30_day_plan(hours_per_week, confidence_level):
291
+ if confidence_level == "Very new":
292
+ week1 = "Learn variables, functions, conditionals, and loops with CS50 Python."
293
+ week2 = "Read simple Python scripts and change tiny pieces without fear."
294
+ week3 = "Learn what an API is, then run one Gradio app locally or in a notebook."
295
+ week4 = "Deploy one simple Space and practice explaining it in business language."
296
+
297
+ elif confidence_level == "Some exposure":
298
+ week1 = "Refresh Python basics and file structure."
299
+ week2 = "Learn APIs, requests, and Gradio events."
300
+ week3 = "Study FastAPI, Docker, and deployment vocabulary at a high level."
301
+ week4 = "Deploy one Space and write down the architecture in plain English."
302
+
303
+ else:
304
+ week1 = "Review Python, Git, and basic app structure."
305
+ week2 = "Learn APIs and small service design."
306
+ week3 = "Understand deployment tools: Docker, CI/CD, hosting."
307
+ week4 = "Compare LLM apps, ML apps, and rules engines using one business case."
308
+
309
+ pacing = (
310
+ "With this time budget, keep the goal to understanding and one tiny deployment each week."
311
+ if hours_per_week <= 4
312
+ else "With this time budget, you can both study and make small edits confidently each week."
313
+ )
314
+
315
+ return md(f"""
316
+ ## 30-day plan
317
+
318
+ **Weekly time budget:** {hours_per_week} hours
319
+
320
+ **Pacing note:** {pacing}
321
+
322
+ ### Week 1
323
+ {week1}
324
+
325
+ ### Week 2
326
+ {week2}
327
+
328
+ ### Week 3
329
+ {week3}
330
+
331
+ ### Week 4
332
+ {week4}
333
+
334
+ ## Recommended free sequence
335
+ 1. CS50 Python
336
+ 2. Hugging Face Learn or LLM Course
337
+ 3. One Gradio Space deployment
338
+ 4. Full Stack Deep Learning after the basics feel less intimidating
339
+ 5. FastAPI and Docker docs when you want to move from demos to services
340
+ """)
341
+
342
+
343
+ def route_decision(problem_statement: str):
344
+ text = problem_statement.lower()
345
+
346
+ if any(word in text for word in ["summarize", "extract", "search", "document", "email", "chat"]):
347
+ bucket = "LLM / language workflow"
348
+ why = "The problem sounds text-heavy and interaction-focused."
349
+
350
+ elif any(word in text for word in ["predict", "forecast", "classify", "score", "churn", "fraud"]):
351
+ bucket = "Classical ML / predictive modeling"
352
+ why = "The problem sounds like it needs a structured prediction target."
353
+
354
+ elif any(word in text for word in ["approve", "route", "if", "then", "policy", "quote", "form"]):
355
+ bucket = "Rules engine or workflow automation first"
356
+ why = "The problem sounds structured and may not need ML in the first version."
357
+
358
+ else:
359
+ bucket = "Needs process mapping first"
360
+ why = "The problem statement is still broad or ambiguous."
361
+
362
+ return md(f"""
363
+ ## First-pass route
364
+
365
+ **Best first bucket:** {bucket}
366
+
367
+ **Reason:** {why}
368
+
369
+ ## How to use this output
370
+ This is not a final architecture. It is a fast way to stop calling everything 'AI' and instead start by matching the problem to a build style.
371
+ """)
372
+
373
+
374
+ INTRO = md("""
375
+ # Business-to-Technical AI On-Ramp
376
+
377
+ This Space is for someone who works around AI, product, operations, or business strategy and wants to become much more technically fluent without starting from a math-heavy or engineering-heavy place.
378
+
379
+ ## What this app helps with
380
+ - translating technical terms into plain English
381
+ - deciding whether a problem needs rules, ML, or LLM tooling
382
+ - creating a realistic 30-day upskilling plan
383
+ - learning enough code structure to stop being intimidated by app repositories
384
+ """)
385
+
386
+
387
+ with gr.Blocks(title="Business-to-Technical AI On-Ramp") as demo:
388
+ gr.Markdown(INTRO)
389
+
390
+ with gr.Tab("Glossary"):
391
+ term = gr.Dropdown(list(TERM_DB.keys()), value="Software engineering", label="Pick a term")
392
+ term_btn = gr.Button("Explain this term")
393
+ term_out = gr.Markdown(value=explain_term("Software engineering"))
394
+ term_btn.click(explain_term, inputs=term, outputs=term_out)
395
+
396
+ with gr.Tab("Project Scoper"):
397
+ problem_type = gr.Radio(
398
+ [
399
+ "Summarize, extract, search, or chat with documents",
400
+ "Predict a numeric value or class label",
401
+ "Automate repetitive form-like business decisions",
402
+ "Still not sure",
403
+ ],
404
+ value="Still not sure",
405
+ label="What kind of business problem is it?",
406
+ )
407
+
408
+ data_readiness = gr.Radio(
409
+ ["No clean data yet", "Some spreadsheets / exports", "Clean structured data"],
410
+ value="Some spreadsheets / exports",
411
+ label="How ready is the data?",
412
+ )
413
+
414
+ risk_level = gr.Radio(
415
+ ["Low", "Medium", "High / regulated"],
416
+ value="Medium",
417
+ label="What is the risk level?",
418
+ )
419
+
420
+ time_horizon = gr.Radio(
421
+ ["2 weeks", "1 month", "2+ months"],
422
+ value="1 month",
423
+ label="What is the delivery horizon?",
424
+ )
425
+
426
+ technical_help = gr.Radio(
427
+ ["Mostly solo", "One technical partner", "Access to engineers"],
428
+ value="One technical partner",
429
+ label="What technical help exists?",
430
+ )
431
+
432
+ scoper_btn = gr.Button("Generate recommendation")
433
+ scoper_out = gr.Markdown()
434
+
435
+ scoper_btn.click(
436
+ classify_project,
437
+ inputs=[problem_type, data_readiness, risk_level, time_horizon, technical_help],
438
+ outputs=scoper_out,
439
+ )
440
+
441
+ with gr.Tab("30-Day Plan"):
442
+ hours = gr.Slider(2, 12, value=4, step=1, label="Hours per week available")
443
+ confidence = gr.Radio(
444
+ ["Very new", "Some exposure", "Comfortable but inconsistent"],
445
+ value="Very new",
446
+ label="Current confidence level",
447
+ )
448
+ plan_btn = gr.Button("Build my 30-day plan")
449
+ plan_out = gr.Markdown()
450
+ plan_btn.click(make_30_day_plan, inputs=[hours, confidence], outputs=plan_out)
451
+
452
+ with gr.Tab("Problem Router"):
453
+ statement = gr.Textbox(
454
+ lines=5,
455
+ label="Describe the business problem",
456
+ placeholder="Example: We want to automate quote generation for industrial ventilation jobs using past quote files and customer specs.",
457
+ )
458
+ route_btn = gr.Button("Route this problem")
459
+ route_out = gr.Markdown()
460
+ route_btn.click(route_decision, inputs=statement, outputs=route_out)
461
+
462
+ with gr.Tab("Read the Code"):
463
+ gr.Markdown(CODE_WALKTHROUGH)
464
+
465
+ with gr.Tab("Deploy This Space"):
466
+ gr.Markdown(DEPLOY_GUIDE)
467
+
468
+ with gr.Tab("Free References"):
469
+ gr.Markdown(COURSE_LIBRARY)
470
+
471
+
472
+ demo.launch()
requirements_app1.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio>=5.0