--- title: Chatbot Sports Academies System emoji: 🏆 colorFrom: blue colorTo: green sdk: docker app_port: 7860 pinned: false --- # Chatbot Sports Academies System Django-based chatbot for sports academy services, knowledge-base Q&A, service-intent detection, and backend workflow execution. This Space runs as a **Docker Space** and exposes Django/Gunicorn on port `7860`. ## Runtime Flow ```text User message ↓ Input validation / rate limiting ↓ Prompt routing policy: live platform request, knowledge question, or follow-up ↓ Conservative service candidate ranking with conversation context ↓ If high confidence: return SERVICE_REQUEST to the authenticated backend If ambiguous: return CLARIFICATION_REQUIRED If knowledge-only: search the CSV knowledge base ``` The deterministic router is authoritative for service selection. The optional service-intent model enriches already-selected services with flexible parameters; it does not independently choose or execute a service. Explicit live-data requests never fall through to an unrelated knowledge-base answer. ## Required CSV datasets Copy these files into `apps/chat/training_models/data/` before production/training: - `data.csv` - `service_intents.csv` - `service_intents_model_training.csv` ## Model skip/training logic Startup runs: ```bash python manage.py ensure_model --remote --wait --download-artifact ``` Logic: 1. Check `SERVICE_INTENT_MODEL_DIR`. 2. If Hugging Face model files already exist, skip training. 3. If missing, train remotely using `service_intents_model_training.csv`. 4. If training fails, app still starts with deterministic service detection. ## Environment variables Set these in Hugging Face Space settings: ```text DJANGO_SECRET_KEY=change-me DJANGO_DEBUG=0 DJANGO_ALLOWED_HOSTS=.hf.space,localhost,127.0.0.1 DJANGO_SECURE_SSL_REDIRECT=1 SEMANTIC_SEARCH_ENABLED=False SERVICE_INTENT_MODEL_DIR=/app/artifacts/service_intent_model SERVICE_INTENT_TRAINING_SPACE_URL=https://mortadhabbb-train-model-chatbot.hf.space N8N_BASE_URL=https://mortadhabbb-n8n-service-orchestration.hf.space ``` Optional secrets: ```text CHATBOT_API_KEY= HF_TOKEN= SERVICE_INTENT_TRAINING_SPACE_API_KEY= ``` ## Local run ```bash python -m venv .venv pip install -r requirements.txt python manage.py migrate python manage.py runserver ``` ## Docker run ```bash docker build -t chatbot-sports-academies . docker run --rm -p 7860:7860 -e DJANGO_SECRET_KEY=dev -e DJANGO_DEBUG=0 chatbot-sports-academies ``` ## Push to Hugging Face ```bash git add . git commit -m "Regenerate Django chatbot project" git push space main ``` If replacing the whole Space repository: ```bash git push --force space main ```