File size: 5,592 Bytes
c7e9899
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# CONTRIBUTING.md

## πŸ› οΈ Development Setup

This project uses [uv](https://github.com/astral-sh/uv) for fast, reliable Python package management.

### Prerequisites

- Python 3.11 or higher
- Git

### Quick Start

1. **Clone the repository**
   ```bash
   git clone https://github.com/amithjkamath/template-matching.git
   cd template-matching
   ```

2. **Run setup**
   ```bash
   ./setup.sh
   ```
   
   Or if you prefer using Make:
   ```bash
   make setup
   ```

3. **Run the app locally**
   ```bash
   ./run_local.sh
   # or
   make run
   ```

### Manual Setup

If you prefer to set things up manually:

1. **Install uv** (if not already installed)
   ```bash
   curl -LsSf https://astral.sh/uv/install.sh | sh
   ```

2. **Install dependencies**
   ```bash
   uv sync --no-build-isolation
   ```

3. **Run the app**
   ```bash
   uv run --no-build-isolation streamlit run app.py
   ```

### Alternative Simple Method

If you encounter build-related issues, you can use a simpler approach:

```bash
# Install dependencies
uv pip install -r requirements.txt

# Run the app
uv run streamlit run app.py
```

## πŸ“‹ Available Commands

### Using Shell Scripts

- `./setup.sh` - Initial setup (install uv and dependencies)
- `./run_local.sh` - Run the app locally
- `./deploy.sh` - Deploy to HuggingFace Spaces

### Using Makefile

- `make help` - Show all available commands
- `make setup` - Initial setup
- `make install` - Install/update dependencies
- `make run` - Run the app locally
- `make deploy` - Deploy to HuggingFace
- `make clean` - Clean up cache and temporary files
- `make format` - Format code (requires black)
- `make lint` - Run linting checks (requires ruff)
- `make update` - Update all dependencies
- `make info` - Show project information

## πŸ§ͺ Testing Locally

Before deploying, always test your changes locally:

1. Run the app: `./run_local.sh`
2. Open your browser to http://localhost:8501
3. Test all interactive features
4. Check console for any errors

## πŸš€ Deployment Process

The app is deployed to HuggingFace Spaces. To deploy:

1. **Ensure all changes are committed**
   ```bash
   git status
   git add .
   git commit -m "Your commit message"
   ```

2. **Deploy**
   ```bash
   ./deploy.sh
   # or
   make deploy
   ```

The script will:
- Check for uncommitted changes
- Push to the remote repository
- HuggingFace Spaces will automatically rebuild

## πŸ“¦ Dependency Management

### Adding a new dependency

1. **Add to pyproject.toml**
   ```toml
   dependencies = [
       "new-package>=1.0.0",
       ...
   ]
   ```

2. **Update requirements.txt** (for HuggingFace Spaces)
   ```
   new-package>=1.0.0
   ```

3. **Sync dependencies**
   ```bash
   uv sync --no-build-isolation
   # or
   make install
   ```

### Updating dependencies

```bash
uv sync --upgrade --no-build-isolation
# or
make update
```

## 🎨 Code Style

- Follow PEP 8 guidelines
- Use meaningful variable names
- Add docstrings to functions
- Keep functions focused and small

### Formatting (optional)

Install formatting tools:
```bash
uv add --dev black ruff
```

Format code:
```bash
make format
```

Lint code:
```bash
make lint
```

## πŸ“ Making Changes

1. Create a new branch for your feature
   ```bash
   git checkout -b feature/your-feature-name
   ```

2. Make your changes

3. Test locally
   ```bash
   make run
   ```

4. Commit your changes
   ```bash
   git add .
   git commit -m "Description of changes"
   ```

5. Push and create a pull request (if working with others)
   ```bash
   git push origin feature/your-feature-name
   ```

6. Or merge to main and deploy
   ```bash
   git checkout main
   git merge feature/your-feature-name
   make deploy
   ```

## πŸ› Troubleshooting

### Module not found error

If you see `ModuleNotFoundError`:
```bash
uv sync --no-build-isolation  # or make install
# Alternative:
uv pip install -r requirements.txt
```

### Build backend errors

The project is configured to skip build steps. If you still encounter hatchling/build errors:
```bash
./run_simple.sh
# or use pip directly:
uv pip install -r requirements.txt
uv run streamlit run app.py
```

### Port already in use

If port 8501 is already in use:
```bash
uv run --no-build-isolation streamlit run app.py --server.port 8502
```

### uv not found

Make sure uv is in your PATH. After installation, restart your terminal or run:
```bash
source ~/.cargo/env
```

## πŸ“š Project Structure

```
template-matching/
β”œβ”€β”€ app.py                 # Main Streamlit application
β”œβ”€β”€ requirements.txt       # Dependencies for HuggingFace Spaces
β”œβ”€β”€ pyproject.toml        # Python project configuration (uv)
β”œβ”€β”€ Dockerfile            # Docker configuration for HF Spaces
β”œβ”€β”€ packages.txt          # System packages for HF Spaces
β”œβ”€β”€ README.md             # User-facing documentation
β”œβ”€β”€ CONTRIBUTING.md       # This file - developer documentation
β”œβ”€β”€ LICENSE               # MIT License
β”œβ”€β”€ setup.sh              # Setup script
β”œβ”€β”€ run_local.sh          # Local run script
β”œβ”€β”€ deploy.sh             # Deployment script
β”œβ”€β”€ Makefile             # Make commands for convenience
└── .gitignore           # Git ignore patterns
```

## 🀝 Contributing Guidelines

1. Keep the educational focus in mind
2. Maintain interactive and engaging features
3. Test thoroughly before deploying
4. Update documentation for any new features
5. Keep dependencies minimal and up-to-date

## πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.