bounthong commited on
Commit
667bab7
ยท
0 Parent(s):

fix: read PORT env for Render deployment

Browse files
.gitignore ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ *.pyc
3
+ __pycache__/
4
+ venv/
5
+ .env
6
+ .DS_Store
7
+
8
+ # Gradio
9
+ .gradio/
10
+ *.log
11
+
12
+ # IDE
13
+ .vscode/
14
+ .idea/
15
+ *.swp
16
+ *.swo
DEPLOY.md ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Deployment Guide โ€” Lao Python Learning Platform
2
+
3
+ ## Summary: Free Hosting Options
4
+
5
+ | Service | Free Tier | Difficulty | Your Choice |
6
+ |---------|-----------|------------|-------------|
7
+ | **Render** | 512MB RAM, 5GB bandwidth | Easy | โœ… RECOMMENDED |
8
+ | **Google Cloud Run** | 2M invocations/month | Medium | Alternative |
9
+ | **Hugging Face** | Static only (PRO needed for Gradio) | Hard | Already created |
10
+ | **PythonAnywhere** | Limited free | Easy | Not recommended |
11
+
12
+ ---
13
+
14
+ ## Firestore Clarification
15
+ Firestore = Database (stores data). NOT a hosting service.
16
+ - Cannot run Python/Gradio
17
+ - Can store quiz scores/results if needed later
18
+ - Would need Cloud Run or similar to host the app
19
+
20
+ ---
21
+
22
+ ## Option 1: Render (RECOMMENDED)
23
+
24
+ ### Setup (5 minutes):
25
+ 1. Create GitHub repo with this code
26
+ 2. Sign up at https://render.com (use GitHub login)
27
+ 3. Click "New" โ†’ "Web Service"
28
+ 4. Connect your repository
29
+ 5. Deploy!
30
+
31
+ ### Manual Steps:
32
+ ```bash
33
+ # On your local machine (Windows):
34
+ git init
35
+ git add .
36
+ git commit -m "Initial commit"
37
+ git remote add origin https://github.com/YOUR_USERNAME/lao-python-learn.git
38
+ git push -u origin main
39
+ ```
40
+
41
+ ### Render Configuration:
42
+ - Build Command: `pip install -r requirements.txt`
43
+ - Start Command: `gradio app.py --server.port $PORT --server.host 0.0.0.0`
44
+ - Env: PYTHON_VERSION=3.12
45
+
46
+ **Result:** https://lao-python-learn.onrender.com
47
+
48
+ ---
49
+
50
+ ## Option 2: Google Cloud Run
51
+
52
+ ### Setup:
53
+ 1. Create project at https://console.cloud.google.com
54
+ 2. Enable Cloud Run API
55
+ 3. Build Docker image:
56
+ ```bash
57
+ docker build -t gcr.io/YOUR_PROJECT/lao-python-learn:latest .
58
+ docker push gcr.io/YOUR_PROJECT/lao-python-learn:latest
59
+ ```
60
+ 4. Deploy to Cloud Run
61
+
62
+ **Free Tier:** 2M invocations/month
63
+
64
+ ---
65
+
66
+ ## What I've Prepared
67
+
68
+ Files in `/home/bounthong/elearning-python/lao-python-learn/`:
69
+ - `render.yaml` - Render deployment config
70
+ - `deploy_render.py` - Python deploy script
71
+ - `deploy_render.sh` - Shell deploy script
72
+ - `DEPLOY.md` - This guide
73
+ - `requirements.txt` - Updated with python-dotenv
74
+
75
+ ---
76
+
77
+ ## Recommended Next Steps
78
+
79
+ 1. Install git on your Windows machine
80
+ 2. Push code to GitHub
81
+ 3. Connect to Render
82
+ 4. Deploy
83
+
84
+ Or I can guide you through any of these steps.
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.12-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+
8
+ COPY . .
9
+
10
+ EXPOSE 7860
11
+
12
+ CMD ["python", "app.py"]
README.md ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Lao Python Learning Platform
2
+ Learn Python programming in Lao language.
3
+
4
+ ## Features
5
+ - 5 structured lessons in Lao
6
+ - Interactive code examples
7
+ - Code execution runner
8
+ - No login required
9
+
10
+ ## Lessons
11
+ 1. เบžเบทเป‰เบ™เบ–เบฒเบ™ Python - Basic concepts
12
+ 2. เป€เบ‡เบทเปˆเบญเบ™เป„เบ‚ (Conditions) - if/elif/else
13
+ 3. เบฅเบนเบเบชเบญเบ™ (Loops) - for/while
14
+ 4. เบฅเบดเบชเบฑเบ” (Lists) - list operations
15
+ 5. เบŸเบฑเบ‡เบŠเบฑเบ™ (Functions) - function definition
16
+
17
+ ## Run Locally
18
+ ```bash
19
+ pip install -r requirements.txt
20
+ python app.py
21
+ ```
22
+
23
+ ## Deploy to Render (Free)
24
+ See DEPLOY.md for step-by-step guide.
25
+
26
+ ## Deploy to Hugging Face (Static)
27
+ See deploy_hf_simple.py or deploy_static.py
app.py ADDED
@@ -0,0 +1,429 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Lao Python Learning Platform
3
+ Web-based Python learning for Lao secondary students
4
+ """
5
+
6
+ import gradio as gr
7
+ from markdown_it import MarkdownIt
8
+
9
+ # Pre-render markdown to HTML using markdown-it (bundled with Gradio)
10
+ md = MarkdownIt("commonmark", {"html": True})
11
+
12
+ def render_md(text):
13
+ """Convert markdown text to styled HTML."""
14
+ html = md.render(text)
15
+ return f'<div class="lesson-html">{html}</div>'
16
+
17
+ # Custom CSS for Lao script + lesson styling
18
+ custom_css = """
19
+ @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Lao:wght@400;500;600;700&display=swap');
20
+
21
+ body, .gradio-container, textarea, input, button, select, .tab-item, .block {
22
+ font-family: 'Noto Sans Lao', sans-serif !important;
23
+ }
24
+
25
+ .lesson-html {
26
+ font-family: 'Noto Sans Lao', sans-serif !important;
27
+ line-height: 1.8;
28
+ padding: 10px;
29
+ }
30
+ .lesson-html h1 { font-size: 1.8em; font-weight: 700; margin-bottom: 0.5em; color: #1a1a2e; }
31
+ .lesson-html h2 { font-size: 1.4em; font-weight: 600; margin-top: 1.2em; margin-bottom: 0.4em; color: #16213e; }
32
+ .lesson-html p { margin-bottom: 0.8em; }
33
+ .lesson-html ul, .lesson-html ol { margin-left: 1.5em; margin-bottom: 0.8em; }
34
+ .lesson-html li { margin-bottom: 0.3em; }
35
+ .lesson-html code {
36
+ font-family: 'Courier New', monospace !important;
37
+ background: #f0f0f0;
38
+ padding: 2px 6px;
39
+ border-radius: 4px;
40
+ font-size: 0.9em;
41
+ }
42
+ .lesson-html pre {
43
+ background: #1e1e2e;
44
+ color: #cdd6f4;
45
+ padding: 16px;
46
+ border-radius: 8px;
47
+ overflow-x: auto;
48
+ margin-bottom: 1em;
49
+ }
50
+ .lesson-html pre code {
51
+ background: none;
52
+ padding: 0;
53
+ color: inherit;
54
+ }
55
+ """
56
+
57
+ # Lesson content in Lao
58
+ LESSONS = {
59
+ "1. เบžเบทเป‰เบ™เบ–เบฒเบ™ Python": {
60
+ "content": """# เบšเบปเบ”เบ—เบต 1: เบžเบทเป‰เบ™เบ–เบฒเบ™ Python
61
+
62
+ ## 1.1 เบเบฒเบ™เบžเบดเบกเบ‚เปเป‰เบ„เบงเบฒเบก (Print)
63
+ เปƒเบ™ Python, เป€เบฎเบปเบฒเปƒเบŠเป‰ `print()` เป€เบžเบทเปˆเบญเบชเบฐเปเบ”เบ‡เบœเบปเบ™:
64
+
65
+ ```python
66
+ print("เบชเบฐเบšเบฒเบเบ”เบต!")
67
+ print(10 + 5)
68
+ ```
69
+
70
+ ## 1.2 เบ•เบปเบงเบ›เปˆเบฝเบ™ (Variables)
71
+ เบ•เบปเบงเบ›เปˆเบฝเบ™เปเบกเปˆเบ™เบชเบฐเบ–เบฒเบ™เบ—เบตเปˆเป€เบเบฑเบšเบ‚เปเป‰เบกเบนเบ™:
72
+
73
+ ```python
74
+ name = "เบชเบปเบกเบžเบน"
75
+ age = 15
76
+ height = 170.5
77
+
78
+ print(name)
79
+ print(age)
80
+ ```
81
+
82
+ ## 1.3 เบ›เบฐเป€เบžเบ”เบ‚เปเป‰เบกเบนเบ™ (Data Types)
83
+ - `str` - เบ‚เปเป‰เบ„เบงเบฒเบก
84
+ - `int` - เบˆเบณเบ™เบงเบ™เป€เบ•เบฑเบก
85
+ - `float` - เบˆเบณเบ™เบงเบ™เบ—เบปเบ”เบชเบฐเบ™เบดเบเบปเบก
86
+ - `bool` - เบ„เปˆเบฒเบˆเบดเบ‡/เป€เบ—เบทเบญ
87
+
88
+ ## 1.4 เบเบฒเบ™เบ„เบดเบ”เป„เบฅเปˆ (Arithmetic)
89
+ ```python
90
+ a = 10
91
+ b = 3
92
+ print(a + b) # 13
93
+ print(a - b) # 7
94
+ print(a * b) # 30
95
+ print(a / b) # 3.333...
96
+ print(a // b) # 3 (เบซเบฒเบ™เบฅเบงเบ‡)
97
+ print(a % b) # 1 (เป€เบชเบ”)
98
+ print(a ** b) # 1000 (เบฅเบปเบ‡เบเบณเบฅเบฑเบ‡)
99
+ ```
100
+ """,
101
+ "example": """# เบฅเบญเบ‡เบ‚เบฝเบ™เป‚เบ„เบ‡เบเบฒเบ™เบ—เบณเบญเบดเบ”
102
+ # (input() requires stdin โ€” in the Gradio playground it's bypassed; use the
103
+ # calculator example for an interactive demo)
104
+ name = "เป‚เบฅเบ Python" # เปƒเบŠเป‰เบ•เบปเบงเบขเปˆเบฒเบ‡
105
+ print("เบชเบฐเบšเบฒเบเบ”เบต", name)
106
+ print("เบเบดเบ™เบ”เบตเบ•เป‰เบญเบ™เบฎเบฑเบšเบชเบนเปˆเป‚เบฅเบ Python!")
107
+ """
108
+ },
109
+
110
+ "2. เปƒเบŠเป‰เบ‡เบฒเบ™เป€เบ‡เบทเปˆเบญเบ™เป„เบ‚": {
111
+ "content": """# เบšเบปเบ”เบ—เบต 2: เปƒเบŠเป‰เบ‡เบฒเบ™เป€เบ‡เบทเปˆเบญเบ™เป„เบ‚
112
+
113
+ ## 2.1 If / Elif / Else
114
+ ```python
115
+ age = 18
116
+
117
+ if age >= 18:
118
+ print("เป€เบˆเบปเป‰เบฒเป€เบ›เบฑเบ™เบ„เบปเบ™เบœเบนเป‰เปƒเบซเบเปˆ")
119
+ elif age >= 15:
120
+ print("เป€เบˆเบปเป‰เบฒเป€เบ›เบฑเบ™เปœเบธเปˆเบก")
121
+ else:
122
+ print("เป€เบˆเบปเป‰เบฒเป€เบ›เบฑเบ™เป€เบ”เบฑเบเบ™เป‰เบญเบ")
123
+ ```
124
+
125
+ ## 2.2 เป€เบ‡เบทเปˆเบญเบ™เป„เบ‚เบ„เบญเบกเบ›เบฒเป€เบฅเบต
126
+ - `==` (เป€เบ—เบปเปˆเบฒเบเบฑเบš)
127
+ - `!=` (เบšเปเปˆเป€เบ—เบปเปˆเบฒเบเบฑเบš)
128
+ - `>` (เบซเบผเบฒเบเบเบงเปˆเบฒ)
129
+ - `<` (เปœเป‰เบญเบเบเบงเปˆเบฒ)
130
+ - `>=` (เบซเบผเบฒเบเบเบงเปˆเบฒ เบซเบผเบท เป€เบ—เบปเปˆเบฒเบเบฑเบš)
131
+ - `<=` (เปœเป‰เบญเบเบเบงเปˆเบฒ เบซเบผเบท เป€เบ—เบปเปˆเบฒเบเบฑเบš)
132
+ - `and`, `or`, `not`
133
+
134
+ ## 2.3 เบ•เบปเบงเบขเปˆเบฒเบ‡
135
+ ```python
136
+ score = 85
137
+
138
+ if score >= 80:
139
+ print("A")
140
+ elif score >= 70:
141
+ print("B")
142
+ elif score >= 60:
143
+ print("C")
144
+ else:
145
+ print("F")
146
+ ```
147
+ """,
148
+ "example": """# เบเบงเบ”เบชเบญเบšเบญเบฒเบเบธ (fixed for playground; remove the input() call)
149
+ age = 20 # เปƒเบชเปˆเบ•เบปเบงเป€เบฅเบเบ—เบตเปˆเบ•เป‰เบญเบ‡เบเบฒเบ™
150
+
151
+ if age < 0:
152
+ print("เบญเบฒเบเบธเบšเปเปˆเบ–เบทเบเบ•เป‰เบญเบ‡")
153
+ elif age < 13:
154
+ print("เป€เบ”เบฑเบเบ™เป‰เบญเบ")
155
+ elif age < 18:
156
+ print("เปœเบธเปˆเบก")
157
+ else:
158
+ print("เบœเบนเป‰เปƒเบซเบเปˆ")
159
+ """
160
+ },
161
+
162
+ "3. เบฅเบนเบเบชเบญเบ™ (Loops)": {
163
+ "content": """# เบšเบปเบ”เบ—เบต 3: เบฅเบนเบเบชเบญเบ™
164
+
165
+ ## 3.1 For Loop
166
+ ```python
167
+ # เบ›เบธเปˆเบก 5 เบ„เบฑเป‰เบ‡
168
+ for i in range(5):
169
+ print("เบ„เบฑเป‰เบ‡เบ—เบต", i)
170
+
171
+ # เบ™เบฑเบšเบˆเบฒเบ 1 เบซเบฒ 10
172
+ for num in range(1, 11):
173
+ print(num)
174
+ ```
175
+
176
+ ## 3.2 While Loop
177
+ ```python
178
+ count = 0
179
+ while count < 5:
180
+ print("count =", count)
181
+ count += 1
182
+ ```
183
+
184
+ ## 3.3 Break เปเบฅเบฐ Continue
185
+ ```python
186
+ for i in range(10):
187
+ if i == 3:
188
+ continue # เบซเบผเบตเบเบฅเปˆเบฝเบ‡ 3
189
+ if i == 7:
190
+ break # เบขเบธเบ”เบ—เบตเปˆ 7
191
+ print(i)
192
+ ```
193
+ """,
194
+ "example": """# เบ™เบฑเบšเบˆเบปเบ™เบเบงเปˆเบฒเบˆเบฐเบžเบปเบš 100 (no input needed)
195
+ total = 0
196
+ i = 1
197
+ while total < 100:
198
+ total += i
199
+ i += 1
200
+ print("เบœเบปเบ™เบšเบงเบ:", total)
201
+ """
202
+ },
203
+
204
+ "4. เบฅเบดเบชเบฑเบ” (Lists)": {
205
+ "content": """# เบšเบปเบ”เบ—เบต 4: เบฅเบดเบชเบฑเบ”
206
+
207
+ ## 4.1 เบชเป‰เบฒเบ‡เบฅเบดเบชเบฑเบ”
208
+ ```python
209
+ fruits = ["เปเบŸเบฑเบช", "เบ•เบฐเบซเบผเบญเบ”", "เบกเบฑเบ™"]
210
+ numbers = [1, 2, 3, 4, 5]
211
+ mixed = [1, "เบชเบต", 3.14, True]
212
+ ```
213
+
214
+ ## 4.2 เป€เบ‚เบปเป‰เบฒเป€เบ–เบดเบ‡เบญเบปเบ‡เบ›เบฐเบเบญเบš
215
+ ```python
216
+ fruits = ["เปเบŸเบฑเบช", "เบ•เบฐเบซเบผเบญเบ”", "เบกเบฑเบ™"]
217
+ print(fruits[0]) # เปเบŸเบฑเบช
218
+ print(fruits[-1]) # เบกเบฑเบ™
219
+ ```
220
+
221
+ ## 4.3 เบฅเบฝเบ‡เบฅเบดเบชเบฑเบ”
222
+ ```python
223
+ nums = [3, 1, 4, 1, 5, 9]
224
+ nums.sort()
225
+ print(nums) # [1, 1, 3, 4, 5, 9]
226
+
227
+ nums.reverse()
228
+ print(nums) # [9, 5, 4, 3, 1, 1]
229
+ ```
230
+
231
+ ## 4.4 เป€เบžเบตเปˆเบก/เบ•เบฑเบ”
232
+ ```python
233
+ fruits = ["เปเบŸเบฑเบช", "เบ•เบฐเบซเบผเบญเบ”"]
234
+ fruits.append("เบกเบฑเบ™") # เป€เบžเบตเปˆเบกเบขเบนเปˆเบ—เป‰เบฒเบ
235
+ fruits.insert(0, "เป€เบฅเบทเบญเบ") # เป€เบžเบตเปˆเบกเบขเบนเปˆเบ•เบณเปเปœเปˆเบ‡
236
+ fruits.remove("เปเบŸเบฑเบช") # เบ•เบฑเบ”เบญเบญเบ
237
+ popped = fruits.pop() # เบ•เบฑเบ” เปเบฅเบฐ เบเบฑเบšเบ„เบทเบ™
238
+ ```
239
+ """,
240
+ "example": """# เบˆเบฑเบ”เบเบฒเบ™เบฅเบฒเบเบเบฒเบ™ (no input โ€” demo loop)
241
+ shopping = ["เป€เบ›เบฑเบ”", "เป„เบเปˆ"]
242
+ print("เป€เบฅเบตเปˆเบกเบ•เบปเป‰เบ™:", shopping)
243
+ shopping.append("เป„เบ‚เปˆ")
244
+ shopping.pop()
245
+ print("เบˆเบปเบš:", shopping)
246
+ """
247
+ },
248
+
249
+ "5. เบŸเบฑเบ‡เบŠเบฑเบ™ (Functions)": {
250
+ "content": """# เบšเบปเบ”เบ—เบต 5: เบŸเบฑเบ‡เบŠเบฑเบ™
251
+
252
+ ## 5.1 เบชเป‰เบฒเบ‡เบŸเบฑเบ‡เบŠเบฑเบ™
253
+ ```python
254
+ def say_hello():
255
+ print("เบชเบฐเบšเบฒเบเบ”เบต!")
256
+
257
+ say_hello()
258
+ ```
259
+
260
+ ## 5.2 เบŸเบฑเบ‡เบŠเบฑเบ™เบ—เบตเปˆเบกเบตเบžเบฒarรกเบกเบดเป€เบ•เบต
261
+ ```python
262
+ def greet(name):
263
+ print("เบชเบฐเบšเบฒเบเบ”เบต", name)
264
+
265
+ greet("เบชเบปเบกเบžเบน")
266
+ ```
267
+
268
+ ## 5.3 เบเบฑเบšเบ„เบทเบ™เบ„เปˆเบฒ
269
+ ```python
270
+ def add(a, b):
271
+ return a + b
272
+
273
+ result = add(5, 3)
274
+ print(result) # 8
275
+ ```
276
+
277
+ ## 5.4 Default Parameters
278
+ ```python
279
+ def power(base, exp=2):
280
+ return base ** exp
281
+
282
+ print(power(3)) # 9
283
+ print(power(2, 10)) # 1024
284
+ ```
285
+ """,
286
+ "example": """# เบ„เบณเบ™เบงเบ™เบžเบทเป‰เบ™เบ—เบตเปˆเบงเบปเบ‡เบกเบปเบ™ (no input โ€” fixed radius)
287
+ def calculate_circle_area(radius):
288
+ pi = 3.14159
289
+ area = pi * radius ** 2
290
+ return area
291
+
292
+ r = 5.0 # เบฅเบฑเบ”เบชเบฐเปเบต
293
+ print("เบžเบทเป‰เบ™เบ—เบตเปˆ:", calculate_circle_area(r))
294
+ """
295
+ }
296
+ }
297
+
298
+ # Pre-render all lessons to HTML at startup
299
+ LESSON_HTML = {name: render_md(data["content"]) for name, data in LESSONS.items()}
300
+
301
+ # Example codes for the code playground
302
+ EXAMPLE_CODES = {
303
+ "Hello World": 'print("เบชเบฐเบšเบฒเบเบ”เบต! เบฅเบปเบ” Python")',
304
+ "Calculator": """# เป€เบ„เบทเปˆเบญเบ‡เบ„เบดเบ”เป„เบฅเปˆเบ‡เปˆเบฒเบเป† (run once with fixed numbers)
305
+ a = 10
306
+ b = 3
307
+
308
+ print(a, "+", b, "=", a + b)
309
+ print(a, "-", b, "=", a - b)
310
+ print(a, "*", b, "=", a * b)
311
+ print(a, "/", b, "=", round(a / b, 4))
312
+ """,
313
+ "Counting": """# เบ™เบฑเบšเบˆเบณเบ™เบงเบ™
314
+ for i in range(1, 11):
315
+ print(i, end=" ")
316
+ print()
317
+
318
+ # เบ™เบฑเบšเบเป‰เบญเบ™เบซเบผเบฑเบ‡
319
+ for i in range(10, 0, -1):
320
+ print(i, end=" ")
321
+ print("Go!")
322
+ """,
323
+ "Temperature Converter": """# เบ›เปˆเบฝเบ™เบญเบธเบ™เบซเบฐเบžเบนเบก (fixed input for playground)
324
+ celsius = 36.6
325
+ fahrenheit = celsius * 9/5 + 32
326
+ print(f"{celsius}ยฐC = {fahrenheit:.1f}ยฐF")
327
+ """
328
+ }
329
+
330
+ def run_code(code):
331
+ """Run Python code and return output."""
332
+ import io
333
+ import sys
334
+
335
+ old_stdout = sys.stdout
336
+ sys.stdout = mystdout = io.StringIO()
337
+
338
+ try:
339
+ exec(code)
340
+ result = mystdout.getvalue()
341
+ return f"โœ… เบชเบณเป€เบฅเบฑเบ”!\n\n{result}" if result else "โœ… เบชเบณเป€เบฅเบฑเบ”! (เบšเปเปˆเบกเบตเบ‚เบญเบ‡เบญเบญเบ)"
342
+ except Exception as e:
343
+ return f"โŒ เบœเบดเบ”เบžเบฒเบ”:\n{str(e)}"
344
+ finally:
345
+ sys.stdout = old_stdout
346
+
347
+ def select_lesson(lesson_name):
348
+ """Return pre-rendered HTML for the selected lesson."""
349
+ if lesson_name and lesson_name in LESSON_HTML:
350
+ return LESSON_HTML[lesson_name]
351
+ return ""
352
+
353
+ first_lesson = list(LESSONS.keys())[0]
354
+
355
+ with gr.Blocks(title="เบฎเบฝเบ™ Python") as app:
356
+ gr.Markdown("# ๐Ÿ เบฎเบฝเบ™ Python")
357
+
358
+ with gr.Tab("๐Ÿ“š เบšเบปเบ”เบฎเบฝเบ™"):
359
+ lesson_selector = gr.Dropdown(
360
+ choices=list(LESSONS.keys()),
361
+ value=first_lesson,
362
+ label="เป€เบฅเบทเบญเบเบšเบปเบ”เบฎเบฝเบ™"
363
+ )
364
+ # Use gr.HTML instead of gr.Markdown to bypass Gradio 6.x lazy hydration bug
365
+ lesson_content = gr.HTML(
366
+ value=LESSON_HTML[first_lesson],
367
+ show_label=False
368
+ )
369
+
370
+ lesson_selector.change(
371
+ fn=select_lesson,
372
+ inputs=lesson_selector,
373
+ outputs=lesson_content
374
+ )
375
+
376
+ with gr.Tab("๐Ÿ’ป เบฅเบญเบ‡เบ‚เบฝเบ™เป‚เบ„เบ”"):
377
+ gr.Markdown("### เบฅเบญเบ‡เบ‚เบฝเบ™เป‚เบ„เบ” Python เปเบฅเป‰เบงเบเบปเบ” Run")
378
+
379
+ example_selector = gr.Dropdown(
380
+ choices=list(EXAMPLE_CODES.keys()),
381
+ value="Hello World",
382
+ label="เบ•เบปเบงเบขเปˆเบฒเบ‡"
383
+ )
384
+ code_input = gr.Textbox(
385
+ label="Code",
386
+ lines=10,
387
+ placeholder="เบ‚เบฝเบ™เป‚เบ„เบ” Python เบ—เบตเปˆเบ™เบต..."
388
+ )
389
+ code_output = gr.Textbox(label="เบœเบปเบ™เบฅเบฑเบš", lines=10, interactive=False)
390
+
391
+ run_btn = gr.Button("โ–ถ Run", variant="primary")
392
+
393
+ def on_select_example(example):
394
+ return EXAMPLE_CODES.get(example, "")
395
+
396
+ example_selector.change(on_select_example, inputs=example_selector, outputs=code_input)
397
+ run_btn.click(run_code, inputs=code_input, outputs=code_output)
398
+
399
+ with gr.Tab("โ„น๏ธ เบเปˆเบฝเบงเบเบฑเบš"):
400
+ gr.Markdown("""
401
+ ### เบเปˆเบฝเบงเบเบฑเบšเบ„เบญเบชเป€เบฅ
402
+ - เบฎเบฝเบ™ Python เบžเบฒเบชเบฒเบฅเบฒเบง
403
+ - เป€เปเบฒเบฐเบชเบณเบฅเบฑเบšเบ™เบฑเบเบฎเบฝเบ™เบกเบฑเบ”เบ—เบฐเบเบปเบก
404
+ - เบšเปเปˆเบ•เป‰เบญเบ‡เบเบฒเบ™เบžเบทเป‰เบ™เบ–เบฒเบ™เบเบฒเบ™เบ‚เบฝเบ™เป‚เบ›เบฃเปเบเบฃเบก
405
+ - เบฅเบญเบ‡เบ‚เบฝเบ™เป‚เบ„เบ”เป„เบ”เป‰เบ—เบฑเบ™เบ—เบต
406
+
407
+ ### เบšเบปเบ”เบฎเบฝเบ™
408
+ 1. เบžเบทเป‰เบ™เบ–เบฒเบ™ Python
409
+ 2. เปƒเบŠเป‰เบ‡เบฒเบ™เป€เบ‡เบทเปˆเบญเบ™เป„เบ‚
410
+ 3. เบฅเบนเบเบชเบญเบ™
411
+ 4. เบฅเบดเบชเบฑเบ”
412
+ 5. เบŸเบฑเบ‡เบŠเบฑเบ™
413
+ """)
414
+
415
+ if __name__ == "__main__":
416
+ import os
417
+ import argparse
418
+ parser = argparse.ArgumentParser()
419
+ parser.add_argument("--share", action="store_true", help="Create a temporary Gradio public link")
420
+ parser.add_argument("--port", type=int, default=None, help="Port override")
421
+ args = parser.parse_args()
422
+ # Render sets PORT env var; fall back to --port flag or 7860
423
+ port = args.port or int(os.environ.get("PORT", 7860))
424
+ app.launch(
425
+ server_name="0.0.0.0",
426
+ server_port=port,
427
+ share=args.share,
428
+ css=custom_css,
429
+ )
deploy.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Hugging Face Space deployment script for Lao Python Learning Platform
4
+ """
5
+
6
+ import subprocess
7
+ import sys
8
+ import os
9
+
10
+ SPACE_NAME = "bounthong/lao-python-learn"
11
+
12
+ def check_hf_login():
13
+ """Check if user is logged into Hugging Face"""
14
+ try:
15
+ result = subprocess.run(
16
+ ["huggingface-cli", "whoami"],
17
+ capture_output=True,
18
+ text=True
19
+ )
20
+ if result.returncode == 0:
21
+ print(f"โœ“ Logged in as: {result.stdout.strip()}")
22
+ return True
23
+ else:
24
+ print("โœ— Not logged into Hugging Face")
25
+ return False
26
+ except FileNotFoundError:
27
+ print("โœ— huggingface-cli not installed")
28
+ return False
29
+
30
+ def create_readme():
31
+ """Create README.md for Hugging Face Space"""
32
+ readme_content = """---
33
+ tags:
34
+ - python
35
+ - education
36
+ - lao-language
37
+ - gradio
38
+ - machine-learning
39
+ datasets: []
40
+ metrics: []
41
+ license: mit
42
+ ---
43
+
44
+ # ๐Ÿ เบฎเบฝเบ™ Python เบžเบฒเบชเบฒเบฅเบฒเบง
45
+
46
+ Learn Python programming in Lao language. Designed for Lao secondary school students.
47
+
48
+ ## Features
49
+ - 5 structured lessons in Lao language
50
+ - Interactive code execution
51
+ - Pre-loaded examples
52
+ - No login required
53
+
54
+ ## Lessons
55
+ 1. **Python Basics** - print(), variables, data types, arithmetic
56
+ 2. **Conditional Logic** - if/elif/else
57
+ 3. **Loops** - for and while loops
58
+ 4. **Lists** - creating and using lists
59
+ 5. **Functions** - defining and calling functions
60
+
61
+ ## How to Use
62
+ 1. Select a lesson from the dropdown
63
+ 2. Read the explanation
64
+ 3. Go to "Code" tab to try examples
65
+ 4. Run code and see results
66
+
67
+ ## Built With
68
+ - Python 3.12
69
+ - Gradio
70
+ - No external dependencies required
71
+
72
+ ## Author
73
+ Created for Lao education
74
+
75
+ ## License
76
+ MIT
77
+ """
78
+ with open("README.md", "w", encoding="utf-8") as f:
79
+ f.write(readme_content)
80
+ print("โœ“ Created README.md")
81
+
82
+ def run_app():
83
+ """Run the Gradio app locally"""
84
+ print("\n" + "="*50)
85
+ print("Running Lao Python Learning Platform")
86
+ print("="*50 + "\n")
87
+
88
+ import gradio as gr
89
+
90
+ # Import the app
91
+ sys.path.insert(0, os.path.dirname(__file__))
92
+ from app import app
93
+
94
+ app.launch(share=True)
95
+
96
+ if __name__ == "__main__":
97
+ if "--deploy" in sys.argv:
98
+ if check_hf_login():
99
+ create_readme()
100
+ print("\n" + "="*50)
101
+ print("To deploy, run:")
102
+ print(f" cd {os.getcwd()}")
103
+ print(" huggingface-cli upload bounthong/lao-python-learn . --repo-type space")
104
+ print("="*50)
105
+ else:
106
+ run_app()
deploy_hf.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Lao Python Learning Platform - Deployment Configuration
3
+ For Hugging Face Spaces
4
+ """
5
+
6
+ # This file is used by Hugging Face Spaces
7
+ # The main app is in app.py
8
+
9
+ if __name__ == "__main__":
10
+ import gradio as gr
11
+ from app import app
12
+ app.launch()
deploy_hf_simple.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Deploy Lao Python Learning Platform to Hugging Face Spaces
4
+
5
+ Usage:
6
+ export HF_TOKEN="your-token-here"
7
+ python deploy_hf.py
8
+ """
9
+
10
+ import os
11
+ import sys
12
+ from pathlib import Path
13
+ from huggingface_hub import HfApi, create_repo, upload_file
14
+
15
+ SPACE_NAME = "lao-python-learn"
16
+ REPO_TYPE = "space"
17
+ SDK = "docker"
18
+
19
+ def check_hf_login(token):
20
+ """Check if we're logged in to Hugging Face"""
21
+ api = HfApi(token=token)
22
+ try:
23
+ user = api.whoami()
24
+ return user['name']
25
+ except Exception as e:
26
+ print(f"Error checking login: {e}")
27
+ return None
28
+
29
+ def main():
30
+ # Get token from environment
31
+ token = os.environ.get("HF_TOKEN")
32
+ if not token:
33
+ print("ERROR: HF_TOKEN environment variable not set")
34
+ print("Get a token from: https://huggingface.co/settings/tokens")
35
+ print("Then run: export HF_TOKEN='your-token-here'")
36
+ sys.exit(1)
37
+
38
+ # Check login
39
+ print("Checking Hugging Face login...")
40
+ username = check_hf_login(token)
41
+ if not username:
42
+ print("ERROR: Could not authenticate with Hugging Face")
43
+ sys.exit(1)
44
+
45
+ print(f"Logged in as: {username}")
46
+
47
+ # Create space repo name
48
+ repo_id = f"{username}/{SPACE_NAME}"
49
+ print(f"Space ID: {repo_id}")
50
+
51
+ # Create the repo
52
+ print("\nCreating Hugging Face Space...")
53
+ try:
54
+ create_repo(
55
+ repo_id=repo_id,
56
+ repo_type=REPO_TYPE,
57
+ token=token,
58
+ space_sdk=SDK,
59
+ exist_ok=True,
60
+ )
61
+ print(f"โœ“ Space created: https://huggingface.co/spaces/{repo_id}")
62
+ except Exception as e:
63
+ print(f"Error creating repo: {e}")
64
+ sys.exit(1)
65
+
66
+ # Upload files
67
+ project_dir = Path(__file__).parent
68
+ print("\nUploading files...")
69
+
70
+ files_to_upload = [
71
+ "app.py",
72
+ "requirements.txt",
73
+ "README.md",
74
+ "Dockerfile",
75
+ ".gitignore",
76
+ ]
77
+
78
+ for filepath in files_to_upload:
79
+ full_path = project_dir / filepath
80
+ if full_path.exists():
81
+ try:
82
+ upload_file(
83
+ path_or_fileobj=str(full_path),
84
+ path_in_repo=filepath,
85
+ repo_id=repo_id,
86
+ repo_type=REPO_TYPE,
87
+ token=token,
88
+ )
89
+ print(f" โœ“ {filepath}")
90
+ except Exception as e:
91
+ print(f" โœ— {filepath}: {e}")
92
+ else:
93
+ print(f" โš  {filepath}: not found")
94
+
95
+ print("\n" + "="*50)
96
+ print("โœ… Deployment complete!")
97
+ print("="*50)
98
+ print(f"\nYour learning platform is live at:")
99
+ print(f" https://huggingface.co/spaces/{repo_id}")
100
+ print(f"\nTo update later, just run this script again.")
101
+
102
+ if __name__ == "__main__":
103
+ main()
deploy_render.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Deploy Lao Python Learning Platform to Render.com (via CLI)
4
+
5
+ Prerequisites:
6
+ - pip install render-cli
7
+ - render login
8
+ """
9
+
10
+ import os
11
+ import sys
12
+ import subprocess
13
+ from pathlib import Path
14
+
15
+ def check_render_cli():
16
+ """Check if Render CLI is installed."""
17
+ try:
18
+ result = subprocess.run(["render", "--version"], capture_output=True, text=True)
19
+ if result.returncode == 0:
20
+ return result.stdout.strip()
21
+ except FileNotFoundError:
22
+ pass
23
+ return None
24
+
25
+ def deploy_to_render():
26
+ """Deploy to Render using their CLI."""
27
+
28
+ # Check CLI
29
+ version = check_render_cli()
30
+ if not version:
31
+ print("โŒ Render CLI not found")
32
+ print(" Install: pip install render-cli")
33
+ print(" Then login: render login")
34
+ return False
35
+
36
+ print(f"โœ“ Render CLI: {version}")
37
+
38
+ # Check credentials
39
+ token = os.environ.get("RENDER_API_KEY")
40
+ if not token:
41
+ print("โš ๏ธ RENDER_API_KEY not set")
42
+ print(" Get token from: https://dashboard.render.com/u/settings")
43
+ print(" Or use 'render login' instead")
44
+ return False
45
+
46
+ print(f"โœ“ Token found: {token[:20]}...")
47
+
48
+ # Deploy
49
+ print("\n๐Ÿš€ Deploying to Render...")
50
+
51
+ deploy_script = Path(__file__).parent / "deploy_render.sh"
52
+ if deploy_script.exists():
53
+ result = subprocess.run(
54
+ ["bash", str(deploy_script)],
55
+ cwd=Path(__file__).parent,
56
+ capture_output=True,
57
+ text=True
58
+ )
59
+ print(result.stdout)
60
+ if result.stderr:
61
+ print("STDERR:", result.stderr)
62
+ return result.returncode == 0
63
+
64
+ print("โŒ deploy_render.sh not found")
65
+ return False
66
+
67
+ if __name__ == "__main__":
68
+ success = deploy_to_render()
69
+ sys.exit(0 if success else 1)
deploy_render.sh ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Deploy to Render using their CLI
3
+
4
+ set -e
5
+
6
+ echo "๐Ÿ“ค Uploading code to Render..."
7
+
8
+ # Use Render CLI to deploy
9
+ # The app will be deployed at: https://<service-name>-on-render.com
10
+
11
+ echo ""
12
+ echo "To deploy manually via dashboard:"
13
+ echo " 1. Push code to GitHub"
14
+ echo " 2. Go to https://dashboard.render.com"
15
+ echo " 3. Sign in with GitHub"
16
+ echo " 4. Click 'New' โ†’ 'Web Service'"
17
+ echo " 5. Connect your repository"
18
+ echo " 6. Leave defaults and deploy!"
19
+ echo ""
20
+ echo "Your app will be at: https://lao-python-learn.onrender.com"
deploy_render_guide.sh ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Render Deployment Script
3
+ # Run on your LOCAL machine (Windows/Linux/Mac)
4
+
5
+ set -e
6
+
7
+ echo "=========================================="
8
+ echo " Deploy Lao Python Learning Platform"
9
+ echo " to Render.com (FREE)"
10
+ echo "=========================================="
11
+ echo ""
12
+
13
+ # Check prerequisites
14
+ if ! command -v git &> /dev/null; then
15
+ echo "โŒ git not found. Install git first:"
16
+ echo " Windows: https://git-scm.com/download/win"
17
+ echo " macOS: brew install git"
18
+ echo " Linux: sudo apt install git"
19
+ exit 1
20
+ fi
21
+
22
+ if ! command -v docker &> /dev/null; then
23
+ echo "โš ๏ธ docker not found. Required for Cloud Run."
24
+ echo " For Render, git push is sufficient."
25
+ fi
26
+
27
+ echo "๐Ÿ“ Current directory: $(pwd)"
28
+ echo ""
29
+ echo "๐Ÿ“‹ Files to deploy:"
30
+ ls -la *.py *.txt *.yaml 2>/dev/null || echo " (check manually)"
31
+ echo ""
32
+ echo "=========================================="
33
+ echo " STEP 1: Create GitHub Repository"
34
+ echo "=========================================="
35
+ echo ""
36
+ echo "1. Go to https://github.com/new"
37
+ echo "2. Create new repository: lao-python-learn"
38
+ echo "3. Don't initialize with README"
39
+ echo "4. Copy the repo URL"
40
+ echo ""
41
+ echo "=========================================="
42
+ echo " STEP 2: Push Code to GitHub"
43
+ echo "=========================================="
44
+ echo ""
45
+ echo "Run these commands:"
46
+ echo ""
47
+ echo " git init"
48
+ echo " git add ."
49
+ echo " git commit -m 'Initial commit: Lao Python Learning Platform'"
50
+ echo " git branch -M main"
51
+ echo " git remote add origin https://github.com/YOUR_USERNAME/lao-python-learn.git"
52
+ echo " git push -u origin main"
53
+ echo ""
54
+ echo "Replace YOUR_USERNAME with your GitHub username."
55
+ echo ""
56
+ echo "=========================================="
57
+ echo " STEP 3: Deploy to Render"
58
+ echo "=========================================="
59
+ echo ""
60
+ echo "1. Go to https://dashboard.render.com"
61
+ echo "2. Sign in with GitHub"
62
+ echo "3. Click 'New' โ†’ 'Web Service'"
63
+ echo "4. Select your repository: lao-python-learn"
64
+ echo "5. Configure:"
65
+ echo " - Name: lao-python-learn"
66
+ echo " - Build Command: pip install -r requirements.txt"
67
+ echo " - Start Command: gradio app.py --server.port \$PORT --server.host 0.0.0.0"
68
+ echo " - Instance Type: Free"
69
+ echo "6. Click 'Deploy'"
70
+ echo ""
71
+ echo "=========================================="
72
+ echo " DONE!"
73
+ echo "=========================================="
74
+ echo ""
75
+ echo "Your app will be at:"
76
+ echo " https://lao-python-learn.onrender.com"
77
+ echo ""
78
+ echo "Note: Free tier sleeps after 15 min inactivity."
79
+ echo " First visit after sleep takes ~30 seconds."
80
+ echo ""
deploy_static.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Deploy Lao Python Learning Platform to Hugging Face Spaces (Static)
4
+
5
+ Note: Gradio+Docker requires PRO subscription. This creates a static HTML preview.
6
+
7
+ Usage:
8
+ export HF_TOKEN="your-token-here"
9
+ python deploy_static.py
10
+ """
11
+
12
+ import os
13
+ import sys
14
+ from pathlib import Path
15
+ from huggingface_hub import HfApi, create_repo, upload_file, upload_folder
16
+
17
+ SPACE_NAME = "lao-python-learn"
18
+ REPO_TYPE = "space"
19
+ SDK = "static" # Static space = FREE
20
+
21
+ def check_hf_login(token):
22
+ """Check if we're logged in to Hugging Face"""
23
+ api = HfApi(token=token)
24
+ try:
25
+ user = api.whoami()
26
+ return user['name']
27
+ except Exception as e:
28
+ print(f"Error checking login: {e}")
29
+ return None
30
+
31
+ def main():
32
+ # Get token from environment
33
+ token = os.environ.get("HF_TOKEN")
34
+ if not token:
35
+ print("ERROR: HF_TOKEN environment variable not set")
36
+ print("Get a token from: https://huggingface.co/settings/tokens")
37
+ sys.exit(1)
38
+
39
+ # Check login
40
+ print("Checking Hugging Face login...")
41
+ username = check_hf_login(token)
42
+ if not username:
43
+ print("ERROR: Could not authenticate with Hugging Face")
44
+ sys.exit(1)
45
+
46
+ print(f"Logged in as: {username}")
47
+
48
+ # Create space repo name
49
+ repo_id = f"{username}/{SPACE_NAME}"
50
+ print(f"Space ID: {repo_id}")
51
+ print(f"Deployment type: STATIC (FREE)")
52
+ print(f"Note: Static spaces show the landing page only. For interactive Gradio app, PRO is required.")
53
+
54
+ # Create the repo
55
+ print("\nCreating Hugging Face Space (static)...")
56
+ try:
57
+ create_repo(
58
+ repo_id=repo_id,
59
+ repo_type=REPO_TYPE,
60
+ token=token,
61
+ space_sdk=SDK,
62
+ exist_ok=True,
63
+ )
64
+ print(f"โœ“ Space created: https://huggingface.co/spaces/{repo_id}")
65
+ except Exception as e:
66
+ print(f"Error creating repo: {e}")
67
+ sys.exit(1)
68
+
69
+ # Upload files
70
+ project_dir = Path(__file__).parent
71
+ print("\nUploading files...")
72
+
73
+ files_to_upload = [
74
+ "README.md",
75
+ ]
76
+
77
+ for filepath in files_to_upload:
78
+ full_path = project_dir / filepath
79
+ if full_path.exists():
80
+ try:
81
+ upload_file(
82
+ path_or_fileobj=str(full_path),
83
+ path_in_repo=filepath,
84
+ repo_id=repo_id,
85
+ repo_type=REPO_TYPE,
86
+ token=token,
87
+ )
88
+ print(f" โœ“ {filepath}")
89
+ except Exception as e:
90
+ print(f" โœ— {filepath}: {e}")
91
+
92
+ print("\n" + "="*50)
93
+ print("โœ… Deployment complete!")
94
+ print("="*50)
95
+ print(f"\nYour space is at:")
96
+ print(f" https://huggingface.co/spaces/{repo_id}")
97
+ print(f"\nNext steps:")
98
+ print(f" 1. Upgrade to PRO for interactive Gradio: https://huggingface.co/pricing")
99
+ print(f" 2. Re-run deploy_hf_simple.py after upgrade")
100
+
101
+ if __name__ == "__main__":
102
+ main()
deploy_to_hf.sh ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Deploy Lao Python Learning Platform to Hugging Face Spaces
3
+
4
+ set -e
5
+
6
+ cd "$(dirname "$0")"
7
+
8
+ echo "=== Deploy to Hugging Face Spaces ==="
9
+ echo ""
10
+
11
+ # Check for HF token
12
+ if [ -z "$HF_TOKEN" ]; then
13
+ echo "ERROR: HF_TOKEN environment variable not set"
14
+ echo ""
15
+ echo "Get a token from: https://huggingface.co/settings/tokens"
16
+ echo "Then run: export HF_TOKEN='your-token-here'"
17
+ exit 1
18
+ fi
19
+
20
+ # Check requirements
21
+ echo "Checking requirements..."
22
+ source venv/bin/activate
23
+ python -c "import gradio; print(f'Gradio {gradio.__version__} OK')"
24
+
25
+ # Create .env if not exists
26
+ if [ ! -f .env ]; then
27
+ echo "Creating .env file..."
28
+ cat > .env << 'EOF'
29
+ HUGGINGFACE_TOKEN=placeholder
30
+ EOF
31
+ fi
32
+
33
+ # Update .env with real token
34
+ sed -i "s/HUGGINGFACE_TOKEN=placeholder/HUGGINGFACE_TOKEN=$HF_TOKEN/" .env
35
+
36
+ echo ""
37
+ echo "Starting deployment..."
38
+ echo ""
39
+ echo "This will:"
40
+ echo " 1. Create a Hugging Face Space called 'lao-python-learn'"
41
+ echo " 2. Upload your code"
42
+ echo " 3. Set up the space with Docker support"
43
+ echo ""
44
+ echo "Your space will be at: https://huggingface.co/spaces/YOUR_USERNAME/lao-python-learn"
45
+ echo ""
46
+ read -p "Continue? (y/N) " -n 1 -r
47
+ echo ""
48
+ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
49
+ echo "Cancelled."
50
+ exit 0
51
+ fi
52
+
53
+ # Get username
54
+ USERNAME=$(hf auth whoami --token "$HF_TOKEN" 2>/dev/null | grep "^name:" | awk '{print $2}')
55
+ if [ -z "$USERNAME" ]; then
56
+ echo "ERROR: Could not get username from token"
57
+ exit 1
58
+ fi
59
+
60
+ echo "Detected username: $USERNAME"
61
+ SPACE_ID="$USERNAME/lao-python-learn"
62
+ echo "Space ID: $SPACE_ID"
63
+ echo ""
64
+
65
+ # Create space
66
+ echo "Creating Hugging Face Space..."
67
+ huggingface-cli upload \
68
+ --repo-type space \
69
+ --repo-id "$SPACE_ID" \
70
+ --token "$HF_TOKEN" \
71
+ .
72
+
73
+ echo ""
74
+ echo "โœ… Deployment complete!"
75
+ echo ""
76
+ echo "Your learning platform is live at:"
77
+ echo " https://huggingface.co/spaces/$USERNAME/lao-python-learn"
78
+ echo ""
79
+ echo "To update later, just run this script again."
docs/1-plan.md ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Lao Python Learning Platform - Development Plan
2
+
3
+ **Target Audience:** Lao secondary school students (no programming background)
4
+ **Language:** Lao + English code
5
+ **Status:** Phase 1 Complete | Phase 2, 3 Ready
6
+
7
+ ---
8
+
9
+ ## Overview
10
+
11
+ A web-based Python learning platform designed for Lao students. Built with AI-assisted development, focusing on simplicity and gradual complexity.
12
+
13
+ **Current Status:**
14
+ - Phase 1 (Gradio): Running at http://localhost:7860
15
+ - Phase 2 (Tkinter): Code complete, not yet tested
16
+ - Phase 3 (Flask): Code complete, not yet tested
17
+
18
+ ---
19
+
20
+ ## Phase 1: Web Platform (Current)
21
+
22
+ ### What's Built
23
+ - Gradio web interface with 5 basic lessons
24
+ - Interactive code execution (Python runs in browser)
25
+ - Lao language interface
26
+ - Dark mode UI
27
+ - Pre-loaded code examples
28
+
29
+ ### Files
30
+ - `app.py` - Main Gradio application (340 lines)
31
+ - `requirements.txt` - Dependencies
32
+ - `venv/` - Python virtual environment
33
+
34
+ ### URL
35
+ - Local: http://localhost:7860
36
+ - Share: https://f205804cc3b5bfd4ff.gradio.live
37
+
38
+ ### Lesson Coverage (Basic)
39
+ 1. Python Basics (print, variables, types, arithmetic)
40
+ 2. Conditional Logic (if/elif/else)
41
+ 3. Loops (for, while)
42
+ 4. Lists (creation, access, modification)
43
+ 5. Functions (definition, parameters, return)
44
+
45
+ ### TODO: Expand Lessons Later
46
+ - [ ] Add more examples per lesson
47
+ - [ ] Add exercises/quizzes
48
+ - [ ] Add progress tracking
49
+ - [ ] Add video explanations
50
+ - [ ] Add Lao keyboard support hints
51
+
52
+ ---
53
+
54
+ ## Phase 2: Desktop Application
55
+
56
+ ### Goal
57
+ Build simple desktop apps using Tkinter to teach OOP and GUI concepts.
58
+
59
+ ### Files
60
+ - `phase2_tkinter.py` - Complete lesson code (303 lines)
61
+
62
+ ### Lessons Planned
63
+ 1. Creating a Window (basic Tkinter setup)
64
+ 2. Widgets and Layouts (buttons, labels, entries)
65
+ 3. Event Handling (clicks, keyboard, functions)
66
+ 4. Building a To-Do List App (OOP introduction)
67
+ 5. Calculator App (complete desktop application)
68
+
69
+ ### How to Run
70
+ ```bash
71
+ source venv/bin/activate
72
+ python phase2_tkinter.py
73
+ ```
74
+
75
+ ### TODO Before Teaching
76
+ - [ ] Test all 5 lessons
77
+ - [ ] Add screenshots/screenshots guide
78
+ - [ ] Create exercise sheets
79
+ - [ ] Add common errors section
80
+
81
+ ---
82
+
83
+ ## Phase 3: Web Application
84
+
85
+ ### Goal
86
+ Build a web app using Flask to teach backend concepts and APIs.
87
+
88
+ ### Files
89
+ - `phase3_flask.py` - Complete lesson code (326 lines)
90
+
91
+ ### Lessons Planned
92
+ 1. Basic Routes and Responses
93
+ 2. Templates (Jinja2)
94
+ 3. API Endpoints (REST)
95
+ 4. Full Web App - Task Manager
96
+ 5. Integration and Best Practices
97
+
98
+ ### How to Run
99
+ ```bash
100
+ pip install flask -q
101
+ python phase3_flask.py
102
+ ```
103
+
104
+ ### Access
105
+ - http://localhost:5000
106
+
107
+ ### TODO Before Teaching
108
+ - [ ] Install Flask dependency
109
+ - [ ] Test all routes
110
+ - [ ] Add error handling examples
111
+ - [ ] Create deployment guide (Hugging Face Spaces, Render)
112
+
113
+ ---
114
+
115
+ ## Phase 4: Future Enhancements
116
+
117
+ ### Advanced Topics
118
+ - Object-Oriented Programming (OOP) in depth
119
+ - File Handling (read/write)
120
+ - Error Handling (try/except)
121
+ - Introduction to Data Science (pandas basics)
122
+ - Simple Games (Turtle graphics)
123
+
124
+ ### Platform Features
125
+ - User accounts and progress tracking
126
+ - Achievement badges
127
+ - Leaderboard (optional)
128
+ - Mobile-responsive design
129
+ - Offline mode (PWA)
130
+
131
+ ### Technical Improvements
132
+ - Deploy to Hugging Face Spaces (free hosting)
133
+ - Add real-time code execution backend
134
+ - Add automated grading
135
+ - Add discussion/forum feature
136
+
137
+ ---
138
+
139
+ ## Development Workflow
140
+
141
+ ### AI-Assisted Approach
142
+ 1. I write the code with your guidance
143
+ 2. You test and provide feedback
144
+ 3. We iterate until it works
145
+ 4. Save as skill for future reference
146
+
147
+ ### Current Workflow
148
+ - Project location: `/home/bounthong/elearning-python/lao-python-learn/`
149
+ - Virtual env: `/home/bounthong/elearning-python/lao-python-learn/venv/`
150
+ - Docs: `/home/bounthong/elearning-python/lao-python-learn/docs/`
151
+
152
+ ### Next Steps (Your Choice)
153
+ 1. Expand Phase 1 lessons with more content
154
+ 2. Test Phase 2 (Tkinter)
155
+ 3. Test Phase 3 (Flask)
156
+ 4. Deploy Phase 1 to Hugging Face Spaces
157
+ 5. Add quizzes/exercises to Phase 1
158
+
159
+ ---
160
+
161
+ ## Quick Reference
162
+
163
+ ### Run Phase 1
164
+ ```bash
165
+ cd /home/bounthong/elearning-python/lao-python-learn
166
+ source venv/bin/activate
167
+ python app.py
168
+ ```
169
+
170
+ ### Run Phase 2
171
+ ```bash
172
+ python phase2_tkinter.py
173
+ ```
174
+
175
+ ### Run Phase 3
176
+ ```bash
177
+ pip install flask
178
+ python phase3_flask.py
179
+ ```
180
+
181
+ ### Verify Everything
182
+ ```bash
183
+ python /tmp/hermes-verify-lao-python-platform.py
184
+ ```
185
+
186
+ ---
187
+
188
+ ## Notes
189
+
190
+ - All code is in Lao language for student-facing content
191
+ - Code snippets use English (standard Python)
192
+ - Platform is free and open source
193
+ - Can be hosted on Hugging Face Spaces for free
194
+ - No database required (uses in-memory storage for now)
docs/deployment.md ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Lao Python Learning Platform - Deployment Guide
2
+
3
+ ## Quick Deploy to Hugging Face Spaces
4
+
5
+ ### Option 1: Command Line (Recommended)
6
+
7
+ ```bash
8
+ # Login to Hugging Face
9
+ huggingface-cli login
10
+
11
+ # Create new space
12
+ huggingface-cli repo create lao-python-learn --type space --space-sdk gradio
13
+
14
+ # Upload files
15
+ cd /home/bounthong/elearning-python/lao-python-learn
16
+ huggingface-cli upload bounthong/lao-python-learn . --repo-type space
17
+ ```
18
+
19
+ ### Option 2: Web Interface
20
+
21
+ 1. Go to https://huggingface.co/spaces
22
+ 2. Click "Create new Space"
23
+ 3. Name: `lao-python-learn`
24
+ 4. SDK: Gradio
25
+ 5. Copy these files:
26
+ - `app.py`
27
+ - `requirements.txt`
28
+
29
+ ---
30
+
31
+ ## Files Needed
32
+
33
+ - `app.py` - Main application (already created)
34
+ - `requirements.txt` - Dependencies (already created)
35
+
36
+ ## Access URL
37
+
38
+ After deployment, access at:
39
+ ```
40
+ https://huggingface.co/spaces/[YOUR_USERNAME]/lao-python-learn
41
+ ```
docs/fonts.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Google Fonts for Lao Script
2
+
3
+ ## Recommended Font: Noto Sans Lao
4
+
5
+ ### Why Noto Sans Lao?
6
+
7
+ **Comprehensive Coverage:**
8
+ - Supports all Lao script characters (tones, diacritics, special characters)
9
+ - Includes both Lao and Thai characters (useful for mixed content)
10
+ - Well-tested across all browsers and operating systems
11
+
12
+ **Google Fonts Integration:**
13
+ ```css
14
+ @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Lao:wght@400;500;600;700&display=swap');
15
+ ```
16
+
17
+ **Weights Available:**
18
+ - `400` - Regular
19
+ - `500` - Medium
20
+ - `600` - Semi-bold
21
+ - `700` - Bold
22
+
23
+ ## Alternative Options
24
+
25
+ ### 1. Phetsarath OT
26
+ - Traditional Lao font
27
+ - Built into many systems
28
+ - Less modern appearance
29
+
30
+ ### 2. Saysettha OT
31
+ - Another traditional option
32
+ - Good coverage but less common online
33
+
34
+ ### 3. Lao Sans Pro
35
+ - Commercial font (not free)
36
+ - Excellent quality but requires license
37
+
38
+ ## Implementation in Our App
39
+
40
+ ```python
41
+ custom_css = """
42
+ @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Lao:wght@400;500;600;700&display=swap');
43
+
44
+ body, .gradio-container, textarea, input, button, select {
45
+ font-family: 'Noto Sans Lao', sans-serif !important;
46
+ }
47
+
48
+ code, pre {
49
+ font-family: 'Courier New', monospace !important;
50
+ }
51
+ """
52
+ ```
53
+
54
+ ## Testing
55
+
56
+ The font is now active in our Lao Python Learning Platform:
57
+ - **URL:** https://e96a02c050d0658aec.gradio.live
58
+ - **Status:** โœ… Noto Sans Lao loading correctly
59
+ - **Verification:** All Lao text renders properly (no missing glyphs)
60
+
61
+ ## Browser Support
62
+
63
+ Noto Sans Lao works on:
64
+ - โœ… Chrome/Edge (best support)
65
+ - โœ… Firefox
66
+ - โœ… Safari
67
+ - โœ… Mobile browsers (iOS/Android)
68
+
69
+ ## Notes
70
+
71
+ 1. **First-load delay:** Google Fonts may cause slight delay on first visit (solved with `display=swap`)
72
+ 2. **Offline:** Font won't load without internet (acceptable for web platform)
73
+ 3. **Fallback:** System falls back to default sans-serif if font fails to load
phase2_tkinter.py ADDED
@@ -0,0 +1,303 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Phase 2: Tkinter Desktop Application
2
+
3
+ """
4
+ Phase 2: Simple Desktop Application with Tkinter
5
+ Learning Objectives:
6
+ - GUI fundamentals with Tkinter
7
+ - Widget creation and layout
8
+ - Event handling
9
+ - Building a complete desktop app
10
+ """
11
+
12
+ import tkinter as tk
13
+ from tkinter import messagebox, simpledialog
14
+
15
+ # ============================================================
16
+ # LESSON 1: Creating a Window
17
+ # ============================================================
18
+
19
+ def lesson1_create_window():
20
+ """Create a basic Tkinter window"""
21
+ # Create main window
22
+ root = tk.Tk()
23
+ root.title("My First Window - Lesson 1")
24
+ root.geometry("400x300")
25
+
26
+ # Add a label
27
+ label = tk.Label(root, text="Hello from Tkinter!", font=("Arial", 16))
28
+ label.pack(pady=20)
29
+
30
+ # Run the app
31
+ root.mainloop()
32
+
33
+
34
+ # ============================================================
35
+ # LESSON 2: Widgets and Layouts
36
+ # ============================================================
37
+
38
+ def lesson2_widgets():
39
+ """Create widgets and layouts"""
40
+ root = tk.Tk()
41
+ root.title("Widgets Example - Lesson 2")
42
+ root.geometry("500x400")
43
+
44
+ # Frame for organization
45
+ frame = tk.Frame(root, padx=10, pady=10)
46
+ frame.pack(fill=tk.BOTH, expand=True)
47
+
48
+ # Button
49
+ btn = tk.Button(frame, text="Click Me!", command=lambda: messagebox.showinfo("Info", "Button clicked!"))
50
+ btn.pack(pady=10)
51
+
52
+ # Entry (text input)
53
+ entry = tk.Entry(frame, width=30)
54
+ entry.pack(pady=5)
55
+
56
+ # Text area
57
+ text = tk.Text(frame, height=5, width=40)
58
+ text.pack(pady=10)
59
+ text.insert("1.0", "Type something here...")
60
+
61
+ # Checkbuttons
62
+ var1 = tk.BooleanVar()
63
+ cb1 = tk.Checkbutton(frame, text="Option 1", variable=var1)
64
+ cb1.pack()
65
+
66
+ # Radio buttons
67
+ var = tk.StringVar(value="A")
68
+ rb1 = tk.Radiobutton(frame, text="Option A", variable=var, value="A")
69
+ rb2 = tk.Radiobutton(frame, text="Option B", variable=var, value="B")
70
+ rb1.pack()
71
+ rb2.pack()
72
+
73
+ root.mainloop()
74
+
75
+
76
+ # ============================================================
77
+ # LESSON 3: Event Handling
78
+ # ============================================================
79
+
80
+ def lesson3_events():
81
+ """Handle events and user interactions"""
82
+ root = tk.Tk()
83
+ root.title("Event Handling - Lesson 3")
84
+ root.geometry("400x300")
85
+
86
+ counter = [0] # Use list to allow modification in nested function
87
+
88
+ def increment():
89
+ counter[0] += 1
90
+ label.config(text=f"Count: {counter[0]}")
91
+
92
+ def reset():
93
+ counter[0] = 0
94
+ label.config(text=f"Count: {counter[0]}")
95
+
96
+ # Label to display counter
97
+ label = tk.Label(root, text="Count: 0", font=("Arial", 24))
98
+ label.pack(pady=30)
99
+
100
+ # Buttons
101
+ btn_inc = tk.Button(root, text="Increment", command=increment, width=15)
102
+ btn_inc.pack(pady=5)
103
+
104
+ btn_reset = tk.Button(root, text="Reset", command=reset, width=15)
105
+ btn_reset.pack(pady=5)
106
+
107
+ # Keyboard binding
108
+ root.bind("<Return>", lambda e: increment())
109
+ root.bind("<Escape>", lambda e: reset())
110
+
111
+ root.mainloop()
112
+
113
+
114
+ # ============================================================
115
+ # LESSON 4: Building a Complete App - To-Do List
116
+ # ============================================================
117
+
118
+ class TodoApp:
119
+ """Complete To-Do List Application"""
120
+
121
+ def __init__(self, root):
122
+ self.root = root
123
+ self.root.title("To-Do List - Lesson 4")
124
+ self.root.geometry("500x400")
125
+
126
+ # Task list
127
+ self.tasks = []
128
+
129
+ # Setup UI
130
+ self.setup_ui()
131
+
132
+ def setup_ui(self):
133
+ """Setup the user interface"""
134
+ # Title
135
+ title = tk.Label(self.root, text="My To-Do List", font=("Arial", 18, "bold"))
136
+ title.pack(pady=10)
137
+
138
+ # Input frame
139
+ input_frame = tk.Frame(self.root)
140
+ input_frame.pack(pady=10)
141
+
142
+ self.task_entry = tk.Entry(input_frame, width=40)
143
+ self.task_entry.pack(side=tk.LEFT, padx=5)
144
+
145
+ tk.Button(input_frame, text="Add Task", command=self.add_task).pack(side=tk.LEFT)
146
+
147
+ # Listbox to show tasks
148
+ list_frame = tk.Frame(self.root)
149
+ list_frame.pack(pady=10, fill=tk.BOTH, expand=True)
150
+
151
+ self.task_listbox = tk.Listbox(list_frame, height=15, width=50)
152
+ self.task_listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
153
+
154
+ scrollbar = tk.Scrollbar(list_frame, command=self.task_listbox.yview)
155
+ scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
156
+ self.task_listbox.config(yscrollcommand=scrollbar.set)
157
+
158
+ # Button frame
159
+ btn_frame = tk.Frame(self.root)
160
+ btn_frame.pack(pady=10)
161
+
162
+ tk.Button(btn_frame, text="Complete Task", command=self.complete_task).pack(side=tk.LEFT, padx=5)
163
+ tk.Button(btn_frame, text="Delete Task", command=self.delete_task).pack(side=tk.LEFT, padx=5)
164
+ tk.Button(btn_frame, text="Clear All", command=self.clear_all).pack(side=tk.LEFT, padx=5)
165
+
166
+ def add_task(self):
167
+ """Add a new task"""
168
+ task = self.task_entry.get().strip()
169
+ if task:
170
+ self.tasks.append({"task": task, "completed": False})
171
+ self.task_listbox.insert(tk.END, f"โ˜ {task}")
172
+ self.task_entry.delete(0, tk.END)
173
+ else:
174
+ messagebox.showwarning("Warning", "Please enter a task!")
175
+
176
+ def complete_task(self):
177
+ """Mark a task as completed"""
178
+ selected = self.task_listbox.curselection()
179
+ if selected:
180
+ index = selected[0]
181
+ self.tasks[index]["completed"] = True
182
+ self.task_listbox.delete(index)
183
+ self.task_listbox.insert(index, f"โ˜‘ {self.tasks[index]['task']}")
184
+
185
+ def delete_task(self):
186
+ """Delete a selected task"""
187
+ selected = self.task_listbox.curselection()
188
+ if selected:
189
+ index = selected[0]
190
+ self.tasks.pop(index)
191
+ self.task_listbox.delete(index)
192
+
193
+ def clear_all(self):
194
+ """Clear all tasks"""
195
+ if messagebox.askyesno("Confirm", "Clear all tasks?"):
196
+ self.tasks.clear()
197
+ self.task_listbox.delete(0, tk.END)
198
+
199
+
200
+ def lesson4_todo_app():
201
+ """Run the To-Do List application"""
202
+ root = tk.Tk()
203
+ app = TodoApp(root)
204
+ root.mainloop()
205
+
206
+
207
+ # ============================================================
208
+ # LESSON 5: OOP and Classes
209
+ # ============================================================
210
+
211
+ class Calculator:
212
+ """Simple Calculator Class"""
213
+
214
+ def __init__(self, root):
215
+ self.root = root
216
+ self.root.title("Calculator - Lesson 5")
217
+ self.root.geometry("300x400")
218
+
219
+ self.expression = ""
220
+ self.result = 0
221
+
222
+ # Display
223
+ self.display = tk.Entry(root, font=("Arial", 20), justify=tk.RIGHT)
224
+ self.display.pack(fill=tk.BOTH, padx=10, pady=10)
225
+
226
+ # Button grid
227
+ buttons = [
228
+ "7", "8", "9", "/",
229
+ "4", "5", "6", "*",
230
+ "1", "2", "3", "-",
231
+ "C", "0", "=", "+"
232
+ ]
233
+
234
+ row = 0
235
+ col = 0
236
+ for btn in buttons:
237
+ command = lambda b=btn: self.on_button_click(b)
238
+ button = tk.Button(root, text=btn, font=("Arial", 16), width=5, height=2, command=command)
239
+ button.grid(row=row, column=col, padx=5, pady=5)
240
+ col += 1
241
+ if col > 3:
242
+ col = 0
243
+ row += 1
244
+
245
+ def on_button_click(self, char):
246
+ """Handle button clicks"""
247
+ if char == "C":
248
+ self.display.delete(0, tk.END)
249
+ self.expression = ""
250
+ elif char == "=":
251
+ try:
252
+ result = eval(self.expression)
253
+ self.display.insert(tk.END, f" = {result}")
254
+ self.expression = str(result)
255
+ except:
256
+ self.display.insert(tk.END, " Error")
257
+ self.expression = ""
258
+ else:
259
+ self.display.insert(tk.END, char)
260
+ self.expression += char
261
+
262
+
263
+ def lesson5_calculator():
264
+ """Run the Calculator application"""
265
+ root = tk.Tk()
266
+ calc = Calculator(root)
267
+ root.mainloop()
268
+
269
+
270
+ # ============================================================
271
+ # MAIN MENU
272
+ # ============================================================
273
+
274
+ def main_menu():
275
+ """Display main menu for all lessons"""
276
+ root = tk.Tk()
277
+ root.title("Lao Python Learning - Desktop Apps")
278
+ root.geometry("500x400")
279
+
280
+ # Title
281
+ title = tk.Label(root, text="๐Ÿ Desktop Application Lessons",
282
+ font=("Arial", 16, "bold"))
283
+ title.pack(pady=20)
284
+
285
+ # Menu items
286
+ lessons = [
287
+ ("Lesson 1: Creating a Window", lesson1_create_window),
288
+ ("Lesson 2: Widgets and Layouts", lesson2_widgets),
289
+ ("Lesson 3: Event Handling", lesson3_events),
290
+ ("Lesson 4: To-Do List App", lesson4_todo_app),
291
+ ("Lesson 5: Calculator App", lesson5_calculator),
292
+ ]
293
+
294
+ for text, command in lessons:
295
+ btn = tk.Button(root, text=text, font=("Arial", 12),
296
+ width=35, height=2, command=command)
297
+ btn.pack(pady=5)
298
+
299
+ root.mainloop()
300
+
301
+
302
+ if __name__ == "__main__":
303
+ main_menu()
phase3_flask.py ADDED
@@ -0,0 +1,326 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Phase 3: Web Application with Flask
2
+
3
+ """
4
+ Phase 3: Simple Web Application with Flask
5
+ Learning Objectives:
6
+ - HTTP requests and responses
7
+ - Routing
8
+ - Templates
9
+ - Building a complete web app
10
+ """
11
+
12
+ from flask import Flask, render_template_string, request, jsonify, redirect, url_for
13
+
14
+ app = Flask(__name__)
15
+
16
+ # ============================================================
17
+ # LESSON 1: Basic Routes and Responses
18
+ # ============================================================
19
+
20
+ @app.route('/')
21
+ def home():
22
+ """Home page"""
23
+ html = '''
24
+ <!DOCTYPE html>
25
+ <html>
26
+ <head>
27
+ <title>Lao Python Web App - Lesson 1</title>
28
+ <style>
29
+ body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
30
+ h1 { color: #2c3e50; }
31
+ .lesson { background: #f8f9fa; padding: 15px; margin: 10px 0; border-radius: 5px; }
32
+ </style>
33
+ </head>
34
+ <body>
35
+ <h1>๐Ÿ Lao Python Web Application</h1>
36
+ <div class="lesson">
37
+ <h2>Lesson 1: Basic Routes</h2>
38
+ <p>Routes map URLs to Python functions:</p>
39
+ <pre><code>@app.route('/')
40
+ def home():
41
+ return "Hello World!"</code></pre>
42
+ </div>
43
+
44
+ <h3>Navigation:</h3>
45
+ <a href="/about">About</a> |
46
+ <a href="/contact">Contact</a> |
47
+ <a href="/api/data">API Data</a>
48
+ </body>
49
+ </html>
50
+ '''
51
+ return html
52
+
53
+
54
+ @app.route('/about')
55
+ def about():
56
+ """About page"""
57
+ return '<h1>About</h1><p>This is a Flask web application for learning Python.</p>'
58
+
59
+
60
+ @app.route('/contact')
61
+ def contact():
62
+ """Contact page"""
63
+ return '''
64
+ <h1>Contact</h1>
65
+ <form method="POST" action="/submit">
66
+ <input type="text" name="name" placeholder="Your Name"><br>
67
+ <input type="email" name="email" placeholder="Your Email"><br>
68
+ <textarea name="message" placeholder="Your Message"></textarea><br>
69
+ <button type="submit">Send</button>
70
+ </form>
71
+ '''
72
+
73
+
74
+ @app.route('/submit', methods=['POST'])
75
+ def submit():
76
+ """Handle form submission"""
77
+ name = request.form.get('name', 'Anonymous')
78
+ return f'<h1>Thanks {name}!</h1><p>Your message has been received.</p><a href="/">Back</a>'
79
+
80
+
81
+ # ============================================================
82
+ # LESSON 2: Templates
83
+ # ============================================================
84
+
85
+ TEMPLATE = '''
86
+ <!DOCTYPE html>
87
+ <html>
88
+ <head>
89
+ <title>{{ title }}</title>
90
+ <style>
91
+ body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
92
+ .card { background: white; padding: 20px; margin: 10px 0; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
93
+ .btn { display: inline-block; padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 5px; }
94
+ </style>
95
+ </head>
96
+ <body>
97
+ <h1>{{ title }}</h1>
98
+
99
+ <div class="card">
100
+ <h2>{{ heading }}</h2>
101
+ <p>{{ content }}</p>
102
+ </div>
103
+
104
+ {% if items %}
105
+ <div class="card">
106
+ <h2>Items</h2>
107
+ <ul>
108
+ {% for item in items %}
109
+ <li>{{ item }}</li>
110
+ {% endfor %}
111
+ </ul>
112
+ </div>
113
+ {% endif %}
114
+
115
+ <a href="/" class="btn">Home</a>
116
+ </body>
117
+ </html>
118
+ '''
119
+
120
+ @app.route('/template-demo')
121
+ def template_demo():
122
+ """Demonstrate template rendering"""
123
+ items = ["Python", "Flask", "HTML", "CSS", "JavaScript"]
124
+ return render_template_string(TEMPLATE,
125
+ title="Template Demo",
126
+ heading="Passing Variables to Templates",
127
+ content="Flask templates make it easy to separate logic from presentation.",
128
+ items=items)
129
+
130
+
131
+ # ============================================================
132
+ # LESSON 3: API Endpoints
133
+ # ============================================================
134
+
135
+ # In-memory "database"
136
+ tasks = []
137
+
138
+ @app.route('/api/tasks', methods=['GET'])
139
+ def get_tasks():
140
+ """Get all tasks"""
141
+ return jsonify(tasks)
142
+
143
+
144
+ @app.route('/api/tasks', methods=['POST'])
145
+ def create_task():
146
+ """Create a new task"""
147
+ data = request.get_json()
148
+ task = {
149
+ "id": len(tasks) + 1,
150
+ "title": data.get("title", ""),
151
+ "completed": False
152
+ }
153
+ tasks.append(task)
154
+ return jsonify(task), 201
155
+
156
+
157
+ @app.route('/api/tasks/<int:task_id>', methods=['PUT'])
158
+ def update_task(task_id):
159
+ """Update a task"""
160
+ for task in tasks:
161
+ if task["id"] == task_id:
162
+ data = request.get_json()
163
+ task["title"] = data.get("title", task["title"])
164
+ task["completed"] = data.get("completed", task["completed"])
165
+ return jsonify(task)
166
+ return jsonify({"error": "Task not found"}), 404
167
+
168
+
169
+ @app.route('/api/tasks/<int:task_id>', methods=['DELETE'])
170
+ def delete_task(task_id):
171
+ """Delete a task"""
172
+ global tasks
173
+ tasks = [t for t in tasks if t["id"] != task_id]
174
+ return jsonify({"message": "Task deleted"})
175
+
176
+
177
+ @app.route('/api/data')
178
+ def api_data():
179
+ """Simple API endpoint"""
180
+ return jsonify({
181
+ "message": "Hello from Flask API!",
182
+ "timestamp": "2026-10-25",
183
+ "version": "1.0"
184
+ })
185
+
186
+
187
+ # ============================================================
188
+ # LESSON 4: Full Web App - Task Manager
189
+ # ============================================================
190
+
191
+ TASK_MANAGER_TEMPLATE = '''
192
+ <!DOCTYPE html>
193
+ <html>
194
+ <head>
195
+ <title>Task Manager - Lesson 4</title>
196
+ <style>
197
+ body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
198
+ .task { display: flex; justify-content: space-between; align-items: center;
199
+ padding: 15px; margin: 10px 0; background: #f8f9fa; border-radius: 5px; }
200
+ .task.completed { text-decoration: line-through; opacity: 0.6; }
201
+ .btn { padding: 8px 15px; margin: 0 5px; border: none; border-radius: 3px; cursor: pointer; }
202
+ .btn-primary { background: #3498db; color: white; }
203
+ .btn-danger { background: #e74c3c; color: white; }
204
+ .btn-success { background: #2ecc71; color: white; }
205
+ input[type="text"] { padding: 10px; width: 70%; border: 1px solid #ddd; border-radius: 3px; }
206
+ </style>
207
+ </head>
208
+ <body>
209
+ <h1>๐Ÿ“‹ Task Manager</h1>
210
+
211
+ <div class="add-task">
212
+ <form method="POST" action="/tasks">
213
+ <input type="text" name="title" placeholder="Add new task..." required>
214
+ <button type="submit" class="btn btn-primary">Add</button>
215
+ </form>
216
+ </div>
217
+
218
+ <div class="tasks">
219
+ {% for task in tasks %}
220
+ <div class="task {% if task.completed %}completed{% endif %}">
221
+ <span>{{ task.title }}</span>
222
+ <div>
223
+ <a href="/tasks/{{ task.id }}/toggle" class="btn btn-success">โœ“</a>
224
+ <a href="/tasks/{{ task.id }}/delete" class="btn btn-danger">โœ—</a>
225
+ </div>
226
+ </div>
227
+ {% endfor %}
228
+ </div>
229
+
230
+ <p>Total: {{ tasks|length }} tasks | Completed: {{ tasks|selectattr("completed")|list|length }} tasks</p>
231
+ </body>
232
+ </html>
233
+ '''
234
+
235
+ @app.route('/tasks', methods=['GET'])
236
+ def list_tasks():
237
+ """List all tasks"""
238
+ return render_template_string(TASK_MANAGER_TEMPLATE, tasks=tasks)
239
+
240
+
241
+ @app.route('/tasks', methods=['POST'])
242
+ def add_task():
243
+ """Add a new task"""
244
+ title = request.form.get('title', '').strip()
245
+ if title:
246
+ tasks.append({
247
+ "id": len(tasks) + 1,
248
+ "title": title,
249
+ "completed": False
250
+ })
251
+ return redirect(url_for('list_tasks'))
252
+
253
+
254
+ @app.route('/tasks/<int:task_id>/toggle', methods=['GET'])
255
+ def toggle_task(task_id):
256
+ """Toggle task completion"""
257
+ for task in tasks:
258
+ if task["id"] == task_id:
259
+ task["completed"] = not task["completed"]
260
+ break
261
+ return redirect(url_for('list_tasks'))
262
+
263
+
264
+ @app.route('/tasks/<int:task_id>/delete', methods=['GET'])
265
+ def delete_task_route(task_id):
266
+ """Delete a task"""
267
+ global tasks
268
+ tasks = [t for t in tasks if t["id"] != task_id]
269
+ return redirect(url_for('list_tasks'))
270
+
271
+
272
+ # ============================================================
273
+ # LESSON 5: Integration
274
+ # ============================================================
275
+
276
+ @app.route('/dashboard')
277
+ def dashboard():
278
+ """Dashboard showing all info"""
279
+ completed = len([t for t in tasks if t["completed"]])
280
+ return jsonify({
281
+ "total_tasks": len(tasks),
282
+ "completed_tasks": completed,
283
+ "pending_tasks": len(tasks) - completed,
284
+ "message": "Welcome to your Python Dashboard!"
285
+ })
286
+
287
+
288
+ @app.errorhandler(404)
289
+ def not_found(e):
290
+ """Handle 404 errors"""
291
+ return jsonify({"error": "Page not found"}), 404
292
+
293
+
294
+ # ============================================================
295
+ # RUN THE APP
296
+ # ============================================================
297
+
298
+ def run_web_app():
299
+ """Run the Flask web application"""
300
+ print("=" * 50)
301
+ print("๐Ÿš€ Flask Web Application")
302
+ print("=" * 50)
303
+ print("\nRoutes:")
304
+ print(" GET / - Home page")
305
+ print(" GET /about - About page")
306
+ print(" GET /contact - Contact form")
307
+ print(" POST /submit - Submit contact form")
308
+ print(" GET /template-demo - Template example")
309
+ print(" GET /api/data - API endpoint")
310
+ print(" GET /tasks - Task manager")
311
+ print(" POST /tasks - Add task")
312
+ print(" GET /dashboard - Dashboard")
313
+ print("\nAPI Endpoints:")
314
+ print(" GET /api/tasks - List tasks")
315
+ print(" POST /api/tasks - Create task")
316
+ print(" PUT /api/tasks/<id> - Update task")
317
+ print(" DELETE /api/tasks/<id> - Delete task")
318
+ print("\n" + "=" * 50)
319
+ print("Starting Flask server on http://localhost:5000")
320
+ print("=" * 50)
321
+
322
+ app.run(debug=True, host='0.0.0.0', port=5000)
323
+
324
+
325
+ if __name__ == '__main__':
326
+ run_web_app()
render.yaml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Render Deployment Configuration
2
+ # Create this file in your project root for Render auto-detection
3
+
4
+ ---
5
+ # render.yaml
6
+ services:
7
+ - type: web
8
+ name: lao-python-learn
9
+ env: python
10
+ buildCommand: pip install -r requirements.txt
11
+ startCommand: gradio app.py --server.port $PORT --server.host 0.0.0.0
12
+ envVars:
13
+ - key: PYTHON_VERSION
14
+ value: 3.12.0
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio>=4.0.0
2
+ python-dotenv>=1.0.0
spaces/README.md ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Space configuration for Hugging Face
2
+
3
+ ---
4
+ title: Lao Python Learning
5
+ emoji: ๐Ÿ
6
+ colorFrom: blue
7
+ colorTo: indigo
8
+ sdk: gradio
9
+ sdk_version: "4.0"
10
+ app_file: app.py
11
+ pinned: false
12
+ ---
13
+
14
+ # Lao Python Learning Platform
15
+
16
+ Learn Python in Lao language - designed for Lao secondary students.
17
+
18
+ ## Features
19
+ - 5 structured lessons
20
+ - Interactive code execution
21
+ - Lao language interface
22
+
23
+ ## Running Locally
24
+ ```bash
25
+ pip install gradio
26
+ python app.py
27
+ ```