Spaces:
Runtime error
Runtime error
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,13 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π Handwritten Polynomial Solver
|
| 2 |
+
|
| 3 |
+
This Hugging Face Space fine-tunes a Pix2Tex-style architecture using TrOCR on the [Azu/Handwritten-Mathematical-Expression-Convert-LaTeX](https://huggingface.co/datasets/Azu/Handwritten-Mathematical-Expression-Convert-LaTeX) dataset (~12K labeled handwritten math expressions). It then uses the trained model to extract LaTeX from user-uploaded images and solve polynomial equations step-by-step.
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## π How to Use
|
| 8 |
+
|
| 9 |
+
### π§ Phase 1: Train the OCR Model
|
| 10 |
+
|
| 11 |
+
1. Rename:
|
| 12 |
+
- `app.py` β `app_ui.py`
|
| 13 |
+
- `train.py` β `app.py`
|
| 14 |
+
|
| 15 |
+
2. Rebuild the Space (top-right corner β "Runtime β Restart & Run All").
|
| 16 |
+
|
| 17 |
+
3. Wait for training to finish (~10β20 min). A `trained_model/` directory will be saved.
|
| 18 |
+
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
### π¨ Phase 2: Run the UI
|
| 22 |
+
|
| 23 |
+
1. Rename:
|
| 24 |
+
- `app_ui.py` β `app.py`
|
| 25 |
+
- `app.py` (the old training script) β `train.py` (optional)
|
| 26 |
+
|
| 27 |
+
2. Rebuild again.
|
| 28 |
+
|
| 29 |
+
3. Upload a handwritten math image (like `x^3 + 3x - 2 = 0`), and it will:
|
| 30 |
+
- Extract LaTeX
|
| 31 |
+
- Clean & standardize
|
| 32 |
+
- Parse and simplify
|
| 33 |
+
- Solve and show roots step-by-step
|
| 34 |
+
|
| 35 |
+
---
|
| 36 |
+
|
| 37 |
+
## π» Notes
|
| 38 |
+
|
| 39 |
+
- **CPU-only**: Designed to work in free CPU-only Spaces.
|
| 40 |
+
- **Training config**:
|
| 41 |
+
- Samples: 1,000 (you can increase later)
|
| 42 |
+
- Batch size: 2
|
| 43 |
+
- Epochs: 1
|
| 44 |
+
- Based on `microsoft/trocr-base-handwritten` for OCR.
|
| 45 |
+
|
| 46 |
---
|
| 47 |
+
|
| 48 |
+
## π¦ Files
|
| 49 |
+
|
| 50 |
+
| File | Purpose |
|
| 51 |
+
|--------------|--------------------------------------|
|
| 52 |
+
| `app.py` | Gradio UI (after training is done) |
|
| 53 |
+
| `train.py` | Trains the model |
|
| 54 |
+
| `model.py` | OCR wrapper for inference |
|
| 55 |
+
| `requirements.txt` | Python dependencies |
|
| 56 |
+
|
| 57 |
---
|
| 58 |
|
| 59 |
+
## β
Status
|
| 60 |
+
|
| 61 |
+
- [x] Handwritten OCR
|
| 62 |
+
- [x] Step-by-step solving
|
| 63 |
+
- [x] Fine-tuning on real handwritten dataset
|
| 64 |
+
|