Spaces:
Sleeping
Sleeping
File size: 4,790 Bytes
e1ce262 | 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 | ---
title: My Challenge
emoji: π
colorFrom: purple
colorTo: green
sdk: gradio
sdk_version: "5.50.0"
pinned: false
---
# π Gradio Challenge Template
A ready-to-deploy template for hosting science challenges with Gradio.
Participants can register, submit results, and track their position on a live leaderboard.
---
## Features
- **The platform** for participants to learn about the challenge, register, submit their results and track their position on the leaderboard.
- **HuggingFace dataset backend** β registrations and submissions are stored as two dataset configs (`registrations`, `submissions`)
- **Duplicate guard** β prevents the same e-mail from registering twice
- **Single config file** β change challenge name, description, dataset path, and scoring direction in `config.py`
---
## File Structure
```
.
βββ app.py # Entry point, assembles all tabs
βββ config.py # β Edit this to configure your challenge
βββ utils.py # HuggingFace load / push data helpers
βββ tabs # About tab
βββ about.py # About (details about the challenges)
βββ registration.py # Registration tab
βββ submission.py # Submission tab
βββ leaderboard.py # Leaderboard tab
βββ requirements.txt # the app requirements
βββ .gitignore
βββ README.md
βββ .env # Your HF token to run the app locally β never commit this
```
---
## Quickstart β Run Locally
### 1. Clone the repo
```bash
git clone https://github.com/EmmaScharfmann/challenge-template.git
cd challenge-template
```
### 2. Create a virtual environment and install dependencies
```bash
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
```
### 3. Set up your HuggingFace token
Create a `.env` file at the root of the project:
```bash
# .env
HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```
> **Where to get a token:** you need a Hugging Face account. Then, go to [huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) and create a token with **write** access.
> β οΈ **Never commit `.env` to git.** Add it to `.gitignore`:
> ```
> .env
> ```
### 4. Configure the challenge
Open `about.py` and edit the values at the top:
```python
CHALLENGE_NAME = "My Challenge"
CHALLENGE_DESCRIPTION = "..." # Markdown supported
HF_DATASET_PATH = "your-org/your-challenge-dataset"
LEADERBOARD_SCORE_COLUMN = "score"
LEADERBOARD_HIGHER_IS_BETTER = True
```
### 5. Create the HuggingFace dataset
The dataset must exist before the app can push to it. Create an empty dataset repo on [huggingface.co/new-dataset](https://huggingface.co/new-dataset) matching the path you set in `about.py`. The two configs (`registrations`, `submissions`) are created automatically on first write.
### 6. Launch
```bash
python app.py
```
The app will be available at `http://localhost:7860`.
---
## Deploy on HuggingFace Spaces
### 1. Create a new Space
Go to [huggingface.co/new-space](https://huggingface.co/new-space) and choose:
- **SDK:** Gradio
- **Visibility:** Public or Private
### 2. Push your code
```bash
git remote add space https://huggingface.co/spaces/your-org/your-space
git push space main
```
Or connect your GitHub repo directly from the Space settings page.
### 3. Add your HF token as a Secret
In your Space, go to **Settings β Variables and Secrets β New Secret** and add:
| Name | Value |
|---|---|
| `HF_TOKEN` | `hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` |
Secrets are injected as environment variables at runtime. The `datasets` library will pick up `HF_TOKEN` automatically β no code change needed compared to local.
> **Why a secret and not a variable?** Variables are visible to anyone who views the Space settings. Secrets are encrypted and only exposed to the running container.
---
## Dataset Schema
Two configs are pushed to your HuggingFace dataset:
**`registrations`**
| Column | Type | Description |
|---|---|---|
| `timestamp` | string | ISO 8601 UTC |
| `name` | string | Participant's full name |
| `email` | string | Used as unique identifier |
| `affiliation` | string | University / company |
| `team_name` | string | Used to link submissions |
**`submissions`**
| Column | Type | Description |
|---|---|---|
| `timestamp` | string | ISO 8601 UTC |
| `team_name` | string | Must match a registered team |
| `method` | string | Short description of the approach |
| `score` | float | The metric value |
| `file_name` | string | Optional uploaded file path |
---
## Custom challenge
This is a simple challenge template.
Feel free to adapt this template to your need and to contribute to this repo.
## License
MIT |