production deployment
Browse files- Dockerfile +47 -0
- README.md +86 -7
- app.py +17 -0
- dockerignore +64 -0
- requirements-hf.txt +29 -0
Dockerfile
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Dockerfile for Bhagwad Gita RAG Chatbot on Hugging Face Spaces
|
| 2 |
+
# Based on: https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 3 |
+
|
| 4 |
+
FROM python:3.9-slim
|
| 5 |
+
|
| 6 |
+
# Set up a new user named "user" with user ID 1000 (HF Spaces requirement)
|
| 7 |
+
RUN useradd -m -u 1000 user
|
| 8 |
+
|
| 9 |
+
# Switch to the "user" user
|
| 10 |
+
USER user
|
| 11 |
+
|
| 12 |
+
# Set home to the user's home directory
|
| 13 |
+
ENV HOME=/home/user \
|
| 14 |
+
PATH=/home/user/.local/bin:$PATH
|
| 15 |
+
|
| 16 |
+
# Set the working directory to the user's home directory
|
| 17 |
+
WORKDIR $HOME/app
|
| 18 |
+
|
| 19 |
+
# Try and run pip command after setting the user to avoid permission issues
|
| 20 |
+
RUN pip install --no-cache-dir --upgrade pip
|
| 21 |
+
|
| 22 |
+
# Copy requirements first for better caching
|
| 23 |
+
COPY --chown=user requirements.txt .
|
| 24 |
+
|
| 25 |
+
# Install Python dependencies
|
| 26 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 27 |
+
|
| 28 |
+
# Copy the current directory contents into the container
|
| 29 |
+
COPY --chown=user . .
|
| 30 |
+
|
| 31 |
+
# Create data directory and ensure proper permissions
|
| 32 |
+
RUN mkdir -p dataset && chmod 755 dataset
|
| 33 |
+
|
| 34 |
+
# Expose the port that HF Spaces expects (7860)
|
| 35 |
+
EXPOSE 7860
|
| 36 |
+
|
| 37 |
+
# Set environment variables for HF Spaces
|
| 38 |
+
ENV API_HOST=0.0.0.0
|
| 39 |
+
ENV API_PORT=7860
|
| 40 |
+
ENV ENVIRONMENT=production
|
| 41 |
+
|
| 42 |
+
# Health check
|
| 43 |
+
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
| 44 |
+
CMD curl -f http://localhost:7860/health || exit 1
|
| 45 |
+
|
| 46 |
+
# Start the FastAPI application on port 7860 (HF Spaces requirement)
|
| 47 |
+
CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
|
@@ -1,11 +1,90 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
-
|
| 8 |
-
license: mit
|
| 9 |
---
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Bhagwad Gita RAG Chatbot
|
| 3 |
+
emoji: 🕉️
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: docker
|
| 7 |
+
app_port: 7860
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
+
# 🕉️ Bhagwad Gita RAG Chatbot
|
| 11 |
+
|
| 12 |
+
An intelligent chatbot that provides wisdom from the Bhagavad Gita and Patanjali Yoga Sutras using advanced RAG (Retrieval Augmented Generation) technology.
|
| 13 |
+
|
| 14 |
+
## 🌟 Features
|
| 15 |
+
|
| 16 |
+
- **Sacred Text Querying**: Ask questions and get relevant verses from Bhagavad Gita and Patanjali Yoga Sutras
|
| 17 |
+
- **Intelligent RAG**: Uses TF-IDF and cosine similarity for accurate verse matching
|
| 18 |
+
- **Automatic Summaries**: Get concise explanations of complex spiritual concepts
|
| 19 |
+
- **Bilingual Support**: Sanskrit and English language support
|
| 20 |
+
- **Interactive API**: Full REST API with Swagger documentation
|
| 21 |
+
|
| 22 |
+
## 🚀 Quick Start
|
| 23 |
+
|
| 24 |
+
1. **Clone the repository**:
|
| 25 |
+
```bash
|
| 26 |
+
git clone https://huggingface.co/spaces/AbhavBhanot/Indian-Mythology-Chatbot
|
| 27 |
+
cd Indian-Mythology-Chatbot
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
2. **Install dependencies**:
|
| 31 |
+
```bash
|
| 32 |
+
pip install -r requirements.txt
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
3. **Run the application**:
|
| 36 |
+
```bash
|
| 37 |
+
python backend/main.py
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
4. **Access the API**:
|
| 41 |
+
- Main API: http://localhost:8000
|
| 42 |
+
- Interactive Docs: http://localhost:8000/docs
|
| 43 |
+
- Health Check: http://localhost:8000/health
|
| 44 |
+
|
| 45 |
+
## 📚 API Endpoints
|
| 46 |
+
|
| 47 |
+
- `GET /` - Main landing page
|
| 48 |
+
- `GET /health` - Health check
|
| 49 |
+
- `POST /query` - Process spiritual queries
|
| 50 |
+
- `GET /sources` - Get available text sources
|
| 51 |
+
- `POST /translate` - Translate text between languages
|
| 52 |
+
- `GET /supported-languages` - List supported languages
|
| 53 |
+
|
| 54 |
+
## 🐳 Docker Deployment
|
| 55 |
+
|
| 56 |
+
This project is configured for deployment on Hugging Face Spaces using Docker. The Dockerfile automatically:
|
| 57 |
+
|
| 58 |
+
- Sets up the Python environment
|
| 59 |
+
- Installs all dependencies
|
| 60 |
+
- Configures the FastAPI application
|
| 61 |
+
- Exposes the service on port 7860
|
| 62 |
+
|
| 63 |
+
## 🔧 Configuration
|
| 64 |
+
|
| 65 |
+
Set these environment variables for customization:
|
| 66 |
+
|
| 67 |
+
- `DATA_DIR`: Path to dataset directory
|
| 68 |
+
- `CORS_ORIGINS`: Allowed CORS origins
|
| 69 |
+
- `API_HOST`: API host (default: 0.0.0.0)
|
| 70 |
+
- `API_PORT`: API port (default: 8000)
|
| 71 |
+
|
| 72 |
+
## 📖 Dataset Structure
|
| 73 |
+
|
| 74 |
+
The chatbot uses structured CSV datasets containing:
|
| 75 |
+
- Bhagavad Gita verses in Sanskrit and English
|
| 76 |
+
- Patanjali Yoga Sutras
|
| 77 |
+
- Word meanings and translations
|
| 78 |
+
- Question-answer pairs for training
|
| 79 |
+
|
| 80 |
+
## 🤝 Contributing
|
| 81 |
+
|
| 82 |
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
| 83 |
+
|
| 84 |
+
## 📄 License
|
| 85 |
+
|
| 86 |
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
| 87 |
+
|
| 88 |
+
---
|
| 89 |
+
|
| 90 |
+
**Built with ❤️ for spiritual seekers and knowledge enthusiasts**
|
app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Entry point for Hugging Face Spaces deployment
|
| 3 |
+
This file imports and runs the main FastAPI application from the backend
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import sys
|
| 7 |
+
import os
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
# Add the current directory to Python path so we can import from backend
|
| 11 |
+
sys.path.insert(0, str(Path(__file__).parent))
|
| 12 |
+
|
| 13 |
+
# Import the FastAPI app from backend.main
|
| 14 |
+
from backend.main import app
|
| 15 |
+
|
| 16 |
+
# The app variable is what HF Spaces will use to run the application
|
| 17 |
+
# No need to run uvicorn here - HF Spaces handles that automatically
|
dockerignore
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Git and version control
|
| 2 |
+
.git
|
| 3 |
+
.gitignore
|
| 4 |
+
.gitattributes
|
| 5 |
+
|
| 6 |
+
# Documentation
|
| 7 |
+
README.md
|
| 8 |
+
*.md
|
| 9 |
+
docs/
|
| 10 |
+
|
| 11 |
+
# Development files
|
| 12 |
+
.env
|
| 13 |
+
.env.local
|
| 14 |
+
.env.production
|
| 15 |
+
*.log
|
| 16 |
+
*.pyc
|
| 17 |
+
__pycache__/
|
| 18 |
+
.pytest_cache/
|
| 19 |
+
.coverage
|
| 20 |
+
|
| 21 |
+
# IDE and editor files
|
| 22 |
+
.vscode/
|
| 23 |
+
.idea/
|
| 24 |
+
*.swp
|
| 25 |
+
*.swo
|
| 26 |
+
*~
|
| 27 |
+
|
| 28 |
+
# OS generated files
|
| 29 |
+
.DS_Store
|
| 30 |
+
.DS_Store?
|
| 31 |
+
._*
|
| 32 |
+
.Spotlight-V100
|
| 33 |
+
.Trashes
|
| 34 |
+
ehthumbs.db
|
| 35 |
+
Thumbs.db
|
| 36 |
+
|
| 37 |
+
# Node.js (if any)
|
| 38 |
+
node_modules/
|
| 39 |
+
npm-debug.log*
|
| 40 |
+
yarn-debug.log*
|
| 41 |
+
yarn-error.log*
|
| 42 |
+
|
| 43 |
+
# Build artifacts
|
| 44 |
+
build/
|
| 45 |
+
dist/
|
| 46 |
+
*.egg-info/
|
| 47 |
+
|
| 48 |
+
# Temporary files
|
| 49 |
+
tmp/
|
| 50 |
+
temp/
|
| 51 |
+
*.tmp
|
| 52 |
+
|
| 53 |
+
# Large data files (will be mounted at runtime)
|
| 54 |
+
# dataset/
|
| 55 |
+
|
| 56 |
+
# Docker files
|
| 57 |
+
Dockerfile*
|
| 58 |
+
docker-compose*
|
| 59 |
+
.dockerignore
|
| 60 |
+
|
| 61 |
+
# Deployment files
|
| 62 |
+
render.yaml
|
| 63 |
+
netlify.toml
|
| 64 |
+
build_production.sh
|
requirements-hf.txt
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Requirements for Hugging Face Spaces deployment
|
| 2 |
+
# Optimized for faster builds and smaller image size
|
| 3 |
+
|
| 4 |
+
# Core FastAPI dependencies
|
| 5 |
+
fastapi
|
| 6 |
+
uvicorn[standard]
|
| 7 |
+
pydantic
|
| 8 |
+
|
| 9 |
+
# Data processing
|
| 10 |
+
pandas
|
| 11 |
+
numpy
|
| 12 |
+
scikit-learn
|
| 13 |
+
|
| 14 |
+
# ML/AI dependencies (CPU-only for HF Spaces)
|
| 15 |
+
torch
|
| 16 |
+
torchvision
|
| 17 |
+
torchaudio
|
| 18 |
+
transformers
|
| 19 |
+
accelerate
|
| 20 |
+
sentencepiece
|
| 21 |
+
|
| 22 |
+
# Utility libraries
|
| 23 |
+
python-multipart
|
| 24 |
+
jinja2
|
| 25 |
+
python-dotenv
|
| 26 |
+
aiofiles
|
| 27 |
+
|
| 28 |
+
# Add curl for health checks
|
| 29 |
+
curl
|