Spaces:
Sleeping
Sleeping
File size: 4,008 Bytes
88ad0b8 1d4e756 88ad0b8 1d4e756 88ad0b8 1d4e756 88ad0b8 1d4e756 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf 4d63566 cc5f3bf | 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 | ---
title: Number_one's RAG App
emoji: π€
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 4.44.1
python_version: '3.11'
app_file: app.py
pinned: false
license: apache-2.0
short_description: hackathon space 06/2026
---
# Number_one β RAG App
RAG (Retrieval-Augmented Generation) application built for the Hackathon Gustave Eiffel 2026.
**Team:** Alves Enrique Β· Berry Lise Β· Bessiere Nicolas Β· Duong Davy Β· Coulibaly Fatoumata
---
# RAG Chat API Setup & Deployment Guide
## Key Instructions
### Virtual Environment Setup
```bash
python -m venv ~/.venv/hackathon-eiffel
# Activate (macOS / Linux)
source ~/.venv/hackathon-eiffel/bin/activate
# Activate (Windows PowerShell)
~\.venv\hackathon-eiffel\Scripts\Activate.ps1
# Install dependencies
pip install -r requirements.txt
# Set Azure API key (macOS / Linux)
export AZURE_API_KEY="your_azure_api_key_here"
# Run application
python app.py
# Server starts at http://localhost:7860
```
### Hugging Face CLI Installation
```bash
# Install the hf CLI (requires uv)
uv tool install "huggingface_hub[cli]"
# Login to Hugging Face
export HF_TOKEN="hf_your_token_here"
# or interactively:
hf auth login
```
## Persistent Storage (`/data`)
Each Hugging Face Space has a **persistent storage bucket** mounted at `/data` in the container. This stores:
- **ChromaDB vector store:** `/data/chroma_db/`
- Documents, datasets, and binary files
**Bucket naming convention:**
```
Space: https://huggingface.co/spaces/<org>/<space-name>
Bucket URI: hf://buckets/<org>/<space-name>-storage
```
### Syncing Local Data to Bucket
```bash
# Mirror ./data to bucket (removes remote files deleted locally)
hf sync ./data hf://buckets/<org>/<space-name>-storage --delete
# Sync specific subfolder
hf sync ./data/chroma_db hf://buckets/<org>/<space-name>-storage/chroma_db
# Sync specific file types
hf sync ./data hf://buckets/<org>/<space-name>-storage \
--include "*.pdf" --include "*.sqlite3"
```
### Downloading Bucket to Another Machine
```bash
hf sync hf://buckets/<org>/<space-name>-storage ./data
```
## Training Data Download
The hackathon training datasets (~1GB) are in a shared read-only bucket:
```bash
# Download all training data to local ./train_data folder
hf sync hf://buckets/millimanfrance/Hackathon2026TrainData ./train_data
```
**Expected structure:**
```
./train_data/
βββ Automobile - Train/
βββ Climatique - Train/
βββ ...
```
## Expected Data Directory Structure
```
./data/
βββ chroma_db/ # ChromaDB vector store (binary)
β βββ chroma.sqlite3
./train_data/ # Training datasets (mounted from organizer bucket)
βββ Automobile - Train/
βββ Climatique - Train/
βββ ...
```
## Accessing Files in Application
```python
from pathlib import Path
# /data when running in HF Spaces, ./data for local dev
DATA_DIR = Path("/data") if Path("/data").is_dir() else Path("./data")
CHROMA_PERSIST_DIR = str(DATA_DIR / "chroma_db")
ENV_FILE = str(DATA_DIR / ".env")
```
## API Response Format (Required)
The `/query` endpoint **MUST return** this exact format:
```json
{
"answer": "str",
"sources": [
{
"source": "filename",
"score": 0.95,
"ref_text": "text span from document"
}
],
"explanation": "str",
"total_token": 100,
"prompt_tokens": 50,
"completion_tokens": 50,
"cached_tokens": 0,
"co2_grams": 0.5,
"energy_kwh": 0.001,
"run_time_in_ms": 250.5
}
```
## Configuration (`config.json`)
**NEVER put credentials in config.json** β use environment variables instead.
## Deploying to Hugging Face Spaces
1. Create/configure Space on huggingface.co
2. Go to **Settings β Storage Buckets β Mount a bucket** and select `<org>/<space-name>-storage`
3. Add `AZURE_API_KEY` as a **Space Secret** (Settings β Variables and secrets)
4. Push code to Space repository
5. Sync data: `hf sync ./data hf://buckets/<org>/<space-name>-storage`
|