Spaces:
Paused

File size: 17,790 Bytes
62bdd1b
f78142c
 
 
 
62bdd1b
 
 
 
 
f78142c
62bdd1b
 
f78142c
 
 
 
 
 
 
 
f30de34
 
 
f78142c
f8aaa7d
 
 
 
f78142c
af4eb60
 
 
 
 
 
 
 
 
3705940
f78142c
 
 
 
 
3705940
f8aaa7d
 
 
 
 
 
 
7c6459b
 
 
 
 
4707b1a
 
7c6459b
4707b1a
e9f1e84
 
 
 
5eeaf48
e9f1e84
5eeaf48
e538f4b
 
 
 
 
 
 
 
 
5eeaf48
 
 
 
e538f4b
 
 
aae8a70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b919784
 
f78142c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eea1fd8
 
f78142c
 
f8aaa7d
 
f78142c
 
 
f8aaa7d
 
 
 
4707b1a
 
 
 
 
 
 
 
 
 
 
 
 
f8aaa7d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f78142c
 
 
 
 
 
 
7c6459b
f78142c
 
 
 
 
 
7c6459b
 
e9f1e84
 
 
 
 
 
 
4707b1a
e9a92c8
 
 
 
7c6459b
 
 
 
 
 
4707b1a
 
 
 
 
7c6459b
5eeaf48
 
 
e9f1e84
5eeaf48
e538f4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5eeaf48
 
 
 
 
 
 
 
 
 
 
 
 
e538f4b
 
 
 
 
 
 
 
aae8a70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
af4eb60
18cf817
af4eb60
 
 
 
18cf817
f78142c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c6459b
 
 
f78142c
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
---
title: M1 Mechanics Quest
emoji: ๐Ÿš€
colorFrom: indigo
colorTo: pink
sdk: gradio
sdk_version: 6.24.0
app_file: app.py
pinned: false
license: mit
short_description: Gamified IAL M1 practice with 3D diagrams
---

# M1 Mechanics Quest

A polished Hugging Face Gradio Space for original Pearson Edexcel International
Advanced Level Mechanics 1-style practice.

## What is included

- deterministic, seeded generators for eight M1 skill zones;
- an always-visible two-row workspace navigator: all 12 primary tabs appear as
  six tabs per row, remain available while scrolling within the workspace, and
  are never moved into Gradio's three-dot overflow menu;
- original multi-part exam-style questions and validated worked solutions;
- a question-driven visual concept studio on every generated mission: first a
  graphical picture, then parameter-accurate animation, then editable sliders
  for exploring changed mass, velocity, acceleration, friction, force, time,
  angle, gravity and other relevant factors;
- 2D exam line diagrams and rotatable colour 3D concept models;
- a dynamic Creative Mechanics Lab with roller collision, electric train,
  rocket launch and cargo trolley experiments; object, setting, question,
  diagrams, theory and worked solution all change from the same parameters;
- visual controls for mass/size, distance, velocity, acceleration, braking,
  gravity, friction, force and angle, depending on the selected experiment;
- click-to-start object-specific motion with rebound, acceleration/cruising/
  braking, ascent/landing and rough-floor effects;
- local real-time sound cues, lights, shockwaves, sparks and optional very-light
  synthesized background musicโ€”no audio files or network stream required;
- photo/webcam upload for handwritten work on generated and custom missions;
- local OCR plus exact numeric checking;
- optional multimodal review when an OpenAI API key is configured;
- colourful topic-aware correction animation;
- theory notes, hints, method marks and modelling assumptions;
- XP, levels, streaks, hearts, badges and topic mastery;
- custom questions with synchronized motion replay, worked solutions and downloads;
- a **Question Intake** workspace that accepts pasted text, `.txt`, `.md`,
  `.json`, images, PDF, Word `.doc/.docx`, uploaded audio and microphone input;
- automatic text extraction/OCR/transcription, numbered-question splitting,
  duplicate detection, mechanics-concept identification, and an editable visual
  model for each newly added question;
- a reusable user question bank with JSON backup and restore-by-upload, extending
  the original mapping of 149 reference questions without rebuilding the app;
- a **Mechanics Tutor Chat** automatically grounded in the active generated
  question, verified solution, expected answers, hints and theory;
- six suggested clarification prompts plus free-form follow-up questions using
  typed text, microphone/uploaded audio, or an uploaded equation, diagram or
  handwritten image;
- a grounded open-source tutor using selectable Qwen models through Hugging
  Face Inference Providers, with automatic verified-local fallback;
- a deterministic local tutor for core explanations and image/OCR checking,
  plus an optional OpenAI route when `OPENAI_API_KEY` is configured;
- three fixed native **Ask Teacher** bots at the top-right, middle-right, and
  bottom-right on the first page and every tab; each opens over the page without
  changing tabs, maintains an independent mission-linked conversation, uses the
  same Qwen/local/OpenAI routes, and links to the full multimodal tutor;
- a protected **Examination lock** that disables the mission generator, every
  training tab, worksheet tools, theory, progress, and all Ask Teacher bots during an
  active attempt;
- reproducible **Midterm 1** and **Midterm 2** papers with 10 questions each by
  default, plus a default 25-question **Final examination**; all three question
  counts can be changed before the protected attempt starts;
- nine assessment formats: multiple choice, fill-in-the-blank, numerical
  problem, explanation, theory, mathematical calculation, match the following,
  diagram interpretation, and paragraph analysis;
- a 10-minute locked reading/setup phase, configurable protected-session clock
  up to 130 minutes, deadline auto-submission, and optional per-question pacing
  timers assigned through 1โ€“7 minute question-number lists;
- one answer field per question, numbered handwritten image/PDF answer-sheet
  OCR, deterministic rubric-based marking, typed-versus-OCR mismatch flags,
  post-submission solutions, and a flattened encrypted PDF containing the
  questions, responses, marks, and solutions;
- a separate **Assignments** studio with an adjustable question count, original
  assignment generation, numbered typed/image/PDF submission, evaluation,
  solutions, and a downloadable report;
- an **Extraordinary Activities** record for assessed projects, competitions,
  investigations, presentations, prototypes, tutoring, outreach, and other
  work outside the three protected examinations and assignments, including
  optional image/PDF/Word evidence;
- an **Outcome-Based Education (OBE)** calculator on a maximum attainment of
  3.000, with editable component percentages, automatic latest-score loading,
  a transparent contribution table, and a fixed 0โ€“3 Plotly spider chart;
- default OBE weights of 10% Midterm 1, 10% Midterm 2, 10% Assignment, 50%
  Final examination, and 20% Extraordinary activities, which correspond to
  maximum contributions of 0.3, 0.3, 0.3, 1.5, and 0.6;
- a question-by-question **Mistake Analysis** studio that reports the response,
  marking feedback, correct answer, topic/format success rates, strengths,
  weaknesses, opportunities, challenges, and a prioritized improvement plan;
- a mistake-analysis chatbot grounded in the selected completed assessment,
  with Qwen, verified-local, and optional OpenAI tutor routes;
- congratulatory standard, silver distinction, gold excellence, and diamond
  achievement certificate previews with rendered ribbon/medal artwork and a
  print-enabled, edit-locked, verification-coded PDF download;
- a classroom worksheet generator with teacher solutions in Markdown, editable
  Word, and print-ready PDF formats.

## Skill coverage

1. vertical motion under gravity;
2. speedโ€“time graphs and area/gradient reasoning;
3. impulse, momentum and direct collisions;
4. moments, reactions, uniform beams and tilting;
5. friction and limiting equilibrium;
6. connected particles on rough inclined planes;
7. two-dimensional vector motion and bearings;
8. force resolution and particle equilibrium.

## Deploy on Hugging Face Spaces

1. **Extract the ZIP first. Do not upload the unopened ZIP as a single file.**
2. Create a new **Gradio** Space.
3. Upload every extracted file. The app now has embedded styling and also ships
   a root-level `style.css`, so a missing `assets` folder will not stop startup.
   The required Hugging Face application entry point is **`app.py`**, located
   at the root beside this README.
4. The Space installs Python dependencies from `requirements.txt`, and installs
   Tesseract, Antiword and FFmpeg from `packages.txt`.
5. Wait for the build to complete and open the Space.

No secret is required for generation, diagrams, theory, OCR, numeric marking,
gamification, worksheets, or local audio transcription. The first local audio
transcription downloads the compact Whisper model selected by
`LOCAL_WHISPER_MODEL` (default: `tiny.en`).

### Open-source Qwen tutor

Both tutor interfaces use **Open-source Qwen (Hugging Face)** by default. Add
an `HF_TOKEN` Space secret with permission to call Inference Providers. The
student can select `Qwen/Qwen3-4B-Instruct-2507` (default),
`Qwen/Qwen3-30B-A3B-Instruct-2507`, or `Qwen/Qwen2.5-7B-Instruct`.

Each request includes the active problem, verified solution path, accepted
answers, hints, theory and recent conversation. If the token, selected model or
provider is unavailable, the app reports the fallback and answers with the
verified local tutor. Optional overrides are `HF_TUTOR_MODEL`,
`HF_INFERENCE_PROVIDER` and `HF_TUTOR_TIMEOUT`.

### Question Intake and storage

Open **โž• Question intake** to extend the app with a new user guide:

1. paste questions, upload one or several supported files, or record a spoken
   question;
2. select **Automatic detection** or provide a concept hint;
3. choose whether numbered questions should be split;
4. click **Extract, visualize, and add to bank**;
5. inspect the extracted text and use the editable animation to verify the
   interpreted parameters;
6. download the JSON question-bank backup when required. Uploading that JSON
   through Question Intake restores its question prompts with deduplication.

On standard free Space hardware, newly added records are stored in the running
Space filesystem and can be lost when the Space restarts. For permanent server-
side retention, enable Hugging Face Persistent Storage and set
`M1_QUESTION_BANK_PATH` to a file under the mounted persistent directory. The
JSON download remains the portable backup method.

For higher-quality speech transcription, set `OPENAI_API_KEY`; the optional
`TRANSCRIPTION_MODEL` defaults to `gpt-4o-mini-transcribe`. Without that key,
audio is processed locally.

### Optional vision tutor

For step-level interpretation of handwritten work, add these Space secrets:

- `OPENAI_API_KEY` โ€” API credential;
- `VISION_MODEL` โ€” optional model override; defaults to `gpt-4.1-mini`.
- `TUTOR_MODEL` โ€” optional chatbot model override; defaults to `gpt-4.1-mini`.

The learner must also tick **Use optional AI vision tutor** for a submission.
When it is not ticked, the work image stays in the Space runtime and is handled
by local OCR. If optional vision is enabled, the uploaded image is sent to the
configured API for that review.

### Mechanics Tutor Chat

Three fixed **Ask Teacher** launchers stay at the top-right, middle-right, and
bottom-right on Mission Control and every other tab. Each is a complete native
Gradio copy with its own compact chat, text field, First hint, Equation choice,
Clear, model selector, Enter submission, close control, and full-tutor link.
Opening one closes the other panels to prevent overlap. Every copy follows the
current Mission Control or Creative Lab problem and its verified solution.
Qwen is the default engine;
the verified local and optional OpenAI engines remain selectable. Select **Open full
multimodal tutor โ†—** inside the popup only when voice or image input is needed;
that explicit link opens the existing Mechanics Tutor Chat tab in the same
browser window.

The **๐Ÿ’ฌ Mechanics tutor chat** tab follows the current Mission Control
question. Generating a new mission resets and re-grounds the conversation.
Students may select one of six suggested questions, type a follow-up, record a
voice query, or upload an equation/diagram/working image. Voice is transcribed
using the same local-or-configured transcription route as Question Intake.

The Qwen engine handles open-ended clarification while remaining constrained by
validated question data. The verified local tutor can explain theory,
equations, sign conventions, first hints, complete solutions, similar questions
and OCR-detected checkpoints without a key. The optional OpenAI engine uses
`OPENAI_API_KEY`.

### Protected examinations

Turn on **Activate examination section** above the mission generator. The app
hides and disables all training tabs and the three Ask Teacher launchers. After
the learner starts a paper, the examination switch and paper settings stay
locked until the attempt is submitted. Midterm 1 and Midterm 2 default to 10
questions and the Final examination defaults to 25; independent sliders can
change each paper size before starting. Papers rotate through nine formats:
multiple choice, fill-in-the-blank, numerical problem, explanation, theory,
mathematical calculation, match the following, diagram interpretation, and
paragraph analysis.

The protected-session duration defaults to 130 minutes and may be reduced
manually. The first 10 minutes are reserved for preliminary reading and setup;
answer fields and individual timers unlock after that phase. The remaining
default 120 minutes are examination time. Small questions receive a suggested
1-minute timer and descriptive questions receive 4 minutes. Question numbers
can be reassigned manually to any 1โ€“7 minute list. Individual timers are pacing
aids; the main clock continues whether or not they are started. At the deadline,
answer controls lock and the result/PDF submission runs automatically.
The protected browser tab must remain open so its live answers can be captured
and submitted at the deadline.

The learner can type an answer beneath every question and optionally upload
numbered handwritten images or a PDF. Write `Q1`, `Q2`, and so on clearly on
the sheet. Typed answers remain authoritative; OCR fills an empty typed answer
only, and any typed/OCR mismatch is shown for human review. Solutions are
hidden until submission. The downloadable result is a flattened, encrypted PDF
with printing permission but without editing, annotation, form-filling,
assembly, or extraction permissions in compliant PDF readers.

This in-app lock prevents access to the application's own learning tools. A
managed browser or formal invigilation is still necessary to prevent access to
outside websites, phones, notes, or other devices.

### Assignments

Open **๐Ÿ“ Assignments** during training mode. Select the completed topics, set
the assignment question count from 1 to 30, and generate an original paper.
Students can submit typed answers using `Q1`, `Q2`, โ€ฆ headings or upload
numbered handwritten images/PDF. Evaluation reveals the question-by-question
feedback and solutions and creates a downloadable result report.

### Extraordinary activities, OBE, and attainment evidence

Open **๐ŸŒŸ Extraordinary activities** to record one or more activities outside
Midterm 1, Midterm 2, assignments, and the Final examination. Each record has
obtained and maximum marks and can include optional evidence. Multiple activity
marks are added before their combined ratio is used by OBE.

Completed protected examinations and assignments are stored in session
assessment history automatically. In **๐Ÿ“ˆ OBE attainment**, click **Load latest
recorded scores** to copy the newest result of each type plus the combined
extraordinary-activity score. Every mark field remains editable for moderation.

The calculation for each component is:

`3 ร— component percentage weight รท 100 ร— (marks obtained รท maximum marks)`

The five weight percentages must total 100. The defaults are 10%, 10%, 10%,
50%, and 20%, so a fully attained student receives contributions of 0.3, 0.3,
0.3, 1.5, and 0.6, totaling 3.000. A fixed 0โ€“3 spider chart displays the
unweighted attainment level reached within each component so component shapes
remain directly comparable.

### Mistake analysis and certificates

Open **๐Ÿงญ Mistake analysis**, refresh completed assessments, select an attempt,
and click **Analyse mistakes**. The report reveals each lost-mark response,
marker feedback, correct answer, topic-specific next action, performance by
topic and question format, and a strengths/weaknesses/opportunities/challenges
summary. Its dedicated chatbot uses the selected correction record as verified
context and can explain or defend the analysis.

Open **๐Ÿ… Certificates** after computing OBE attainment. To avoid gaps created
by overlapping wording, the app uses these continuous bands:

| Attainment | Overall percentage | Certificate |
|---:|---:|---|
| Below 1.800 | Below 60% | Not generated |
| 1.800 to below 2.400 | 60% to below 80% | Standard achievement |
| 2.400 to below 2.700 | 80% to below 90% | Silver distinction |
| 2.700 to below 2.900 | 90% to below 96.67% | Gold excellence |
| 2.900 to 3.000 | 96.67% to 100% | Diamond achievement |

The exact phrase **100 percent achievement** appears only when attainment is
3.000/3.000. Every eligible certificate congratulates the student, shows the
actual score, includes programmatically rendered ribbon/medal artwork, and is
downloaded as an encrypted PDF that permits printing but not editing.

### Creative Lab sound

Browsers permit sound after a learner gesture. Clicking the model or **Start
experiment** unlocks audio. The collision, train horn, rocket whoosh, landing
and friction sounds are generated locally at the matching event. Learners can
independently turn off experiment sounds and light background music.

## Local run

For an obvious browser-opening launcher, run:

```bash
python launch_app.py
```

Windows users can instead double-click `run_app_windows.bat`. Linux and macOS
users can run `bash run_app_linux_mac.sh`.

The Hugging Face entry point can also be run directly:

```bash
python -m pip install -r requirements.txt
python app.py
```

## Validation

```bash
python -m unittest discover -s tests -v
```

The tests exercise every procedural generator across difficulties and seeds,
all eight editable visual scenes, question ingestion/deduplication, multimodal
tutor grounding, answer matching, gamification, Plotly figure creation and
worksheet output.

## Content and affiliation notice

The supplied past-paper images were used only to map topic coverage, command
words, diagram types and typical mark structures. They are not bundled or
transcribed. Every question emitted by this Space is procedurally generated
original practice content.

This project is unofficial and is not affiliated with, endorsed by, or an
official product of Pearson Edexcel. Pearson and Edexcel are trademarks of
their respective owner.