Spaces:
Paused
Paused
update ignore
Browse files- .github/workflows/deploy-hf.yml +22 -0
- .gitignore +17 -0
- .huggingface.yaml +9 -1
- DEPLOYMENT_SUMMARY.md +58 -0
- Dockerfile +27 -13
- HUGGINGFACE_DEPLOYMENT.md +162 -0
- app/main.py +24 -2
- clean-for-deployment.bat +69 -0
- deploy-to-hf.bat +82 -0
- push-to-hf.bat +49 -0
- requirements-hf.txt +47 -0
.github/workflows/deploy-hf.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Deploy to Hugging Face Spaces
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches: [ main, master ]
|
| 6 |
+
pull_request:
|
| 7 |
+
branches: [ main, master ]
|
| 8 |
+
|
| 9 |
+
jobs:
|
| 10 |
+
deploy:
|
| 11 |
+
runs-on: ubuntu-latest
|
| 12 |
+
|
| 13 |
+
steps:
|
| 14 |
+
- uses: actions/checkout@v3
|
| 15 |
+
|
| 16 |
+
- name: Deploy to Hugging Face Spaces
|
| 17 |
+
uses: huggingface/huggingface_hub@main
|
| 18 |
+
with:
|
| 19 |
+
token: ${{ secrets.HF_TOKEN }}
|
| 20 |
+
repo_id: ${{ secrets.HF_REPO_ID }}
|
| 21 |
+
space_sdk: docker
|
| 22 |
+
space_hardware: cpu-basic
|
.gitignore
CHANGED
|
@@ -49,3 +49,20 @@ huggingface/
|
|
| 49 |
*.csv
|
| 50 |
*.tsv
|
| 51 |
*.js*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
*.csv
|
| 50 |
*.tsv
|
| 51 |
*.js*
|
| 52 |
+
|
| 53 |
+
# Vector stores and binary data
|
| 54 |
+
vector_store/
|
| 55 |
+
*.faiss
|
| 56 |
+
*.index
|
| 57 |
+
*.bin
|
| 58 |
+
|
| 59 |
+
# Database files
|
| 60 |
+
*.db
|
| 61 |
+
*.sqlite
|
| 62 |
+
*.sqlite3
|
| 63 |
+
|
| 64 |
+
# Temporary files and caches
|
| 65 |
+
temp/
|
| 66 |
+
tmp/
|
| 67 |
+
.cache/
|
| 68 |
+
cache/
|
.huggingface.yaml
CHANGED
|
@@ -1,2 +1,10 @@
|
|
| 1 |
-
#
|
| 2 |
sdk: docker
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Hugging Face Spaces Configuration
|
| 2 |
sdk: docker
|
| 3 |
+
title: Dubsway Video AI
|
| 4 |
+
emoji: π₯
|
| 5 |
+
colorFrom: blue
|
| 6 |
+
colorTo: purple
|
| 7 |
+
sdk_version: 0.0.20
|
| 8 |
+
app_file: app/main.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
DEPLOYMENT_SUMMARY.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π Quick Deployment Summary
|
| 2 |
+
|
| 3 |
+
## β
Files Created/Updated for Hugging Face Deployment
|
| 4 |
+
|
| 5 |
+
1. **`.huggingface.yaml`** - Hugging Face Spaces configuration
|
| 6 |
+
2. **`Dockerfile`** - Optimized for HF Spaces with CPU-only PyTorch
|
| 7 |
+
3. **`requirements-hf.txt`** - Lightweight dependencies for deployment
|
| 8 |
+
4. **`app/main.py`** - Added health checks and root endpoints
|
| 9 |
+
5. **`.github/workflows/deploy-hf.yml`** - GitHub Actions workflow
|
| 10 |
+
6. **`deploy-to-hf.bat`** - Windows deployment helper script
|
| 11 |
+
7. **`HUGGINGFACE_DEPLOYMENT.md`** - Complete deployment guide
|
| 12 |
+
|
| 13 |
+
## π― Quick Deployment Steps
|
| 14 |
+
|
| 15 |
+
### 1. Push to GitHub
|
| 16 |
+
```bash
|
| 17 |
+
git add .
|
| 18 |
+
git commit -m "Deploy to Hugging Face Spaces"
|
| 19 |
+
git push origin main
|
| 20 |
+
```
|
| 21 |
+
|
| 22 |
+
### 2. Create Hugging Face Space
|
| 23 |
+
1. Go to [huggingface.co/spaces](https://huggingface.co/spaces)
|
| 24 |
+
2. Click "Create new Space"
|
| 25 |
+
3. Settings:
|
| 26 |
+
- **SDK**: Docker
|
| 27 |
+
- **License**: MIT
|
| 28 |
+
- **Connect to your GitHub repo**
|
| 29 |
+
|
| 30 |
+
### 3. Set Environment Variables
|
| 31 |
+
In your Space settings, add:
|
| 32 |
+
```
|
| 33 |
+
GROQ_API_KEY=your_groq_api_key
|
| 34 |
+
DATABASE_URL=sqlite+aiosqlite:///./dubsway_hf.db
|
| 35 |
+
SECRET_KEY=your_secret_key
|
| 36 |
+
ENVIRONMENT=production
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
### 4. Deploy
|
| 40 |
+
- Hugging Face will automatically build and deploy
|
| 41 |
+
- Monitor build logs in your Space
|
| 42 |
+
- Your API will be available at: `https://your-username-dubsway-video-ai.hf.space/`
|
| 43 |
+
|
| 44 |
+
## π Test Your Deployment
|
| 45 |
+
|
| 46 |
+
1. **Health Check**: `GET /health`
|
| 47 |
+
2. **API Docs**: `GET /docs`
|
| 48 |
+
3. **Root Endpoint**: `GET /`
|
| 49 |
+
|
| 50 |
+
## π Need Help?
|
| 51 |
+
|
| 52 |
+
- Run `deploy-to-hf.bat` for step-by-step guidance
|
| 53 |
+
- Check `HUGGINGFACE_DEPLOYMENT.md` for detailed instructions
|
| 54 |
+
- Monitor build logs in your Hugging Face Space
|
| 55 |
+
|
| 56 |
+
---
|
| 57 |
+
|
| 58 |
+
**Your Dubsway Video AI is ready for deployment! π**
|
Dockerfile
CHANGED
|
@@ -1,33 +1,47 @@
|
|
| 1 |
-
# Use a lightweight Python image
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
# Set working directory
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Install system-level dependencies
|
| 11 |
RUN apt-get update && \
|
| 12 |
-
apt-get install -y
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# Copy requirements first to leverage Docker layer caching
|
| 16 |
-
COPY requirements.txt .
|
| 17 |
|
| 18 |
-
# Upgrade pip and install dependencies
|
| 19 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 20 |
-
pip install --no-cache-dir -r requirements.txt
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Copy the entire app source code
|
| 24 |
COPY . .
|
| 25 |
|
|
|
|
|
|
|
|
|
|
| 26 |
# Expose port 7860 (used by Hugging Face Spaces)
|
| 27 |
EXPOSE 7860
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
-
# Run the FastAPI app via Uvicorn
|
| 33 |
-
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
# Use a lightweight Python image optimized for ML workloads
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
# Set working directory
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
+
# Set environment variables for better performance
|
| 8 |
+
ENV PYTHONUNBUFFERED=1
|
| 9 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 10 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 11 |
|
| 12 |
# Install system-level dependencies
|
| 13 |
RUN apt-get update && \
|
| 14 |
+
apt-get install -y \
|
| 15 |
+
ffmpeg \
|
| 16 |
+
libsndfile1 \
|
| 17 |
+
wget \
|
| 18 |
+
curl \
|
| 19 |
+
git \
|
| 20 |
+
build-essential \
|
| 21 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 22 |
|
| 23 |
# Copy requirements first to leverage Docker layer caching
|
| 24 |
+
COPY requirements-hf.txt .
|
| 25 |
|
| 26 |
+
# Upgrade pip and install Python dependencies
|
| 27 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 28 |
+
pip install --no-cache-dir -r requirements-hf.txt
|
| 29 |
+
|
| 30 |
+
# Install PyTorch with CUDA support (will fall back to CPU if no GPU)
|
| 31 |
+
RUN pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
|
| 32 |
|
| 33 |
# Copy the entire app source code
|
| 34 |
COPY . .
|
| 35 |
|
| 36 |
+
# Create necessary directories
|
| 37 |
+
RUN mkdir -p vector_store logs
|
| 38 |
+
|
| 39 |
# Expose port 7860 (used by Hugging Face Spaces)
|
| 40 |
EXPOSE 7860
|
| 41 |
|
| 42 |
+
# Health check
|
| 43 |
+
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
| 44 |
+
CMD curl -f http://localhost:7860/docs || exit 1
|
| 45 |
|
| 46 |
+
# Run the FastAPI app via Uvicorn with optimized settings
|
| 47 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
|
HUGGINGFACE_DEPLOYMENT.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π Hugging Face Spaces Deployment Guide
|
| 2 |
+
|
| 3 |
+
This guide will help you deploy your Dubsway Video AI system to Hugging Face Spaces via GitHub.
|
| 4 |
+
|
| 5 |
+
## π Prerequisites
|
| 6 |
+
|
| 7 |
+
1. **GitHub Repository**: Your code should be pushed to a GitHub repository
|
| 8 |
+
2. **Hugging Face Account**: Create an account at [huggingface.co](https://huggingface.co)
|
| 9 |
+
3. **Environment Variables**: Set up your API keys and configuration
|
| 10 |
+
|
| 11 |
+
## π§ Step-by-Step Deployment
|
| 12 |
+
|
| 13 |
+
### 1. Prepare Your Repository
|
| 14 |
+
|
| 15 |
+
Your repository should already have the necessary files:
|
| 16 |
+
- `.huggingface.yaml` - Hugging Face Spaces configuration
|
| 17 |
+
- `Dockerfile` - Container configuration
|
| 18 |
+
- `requirements-hf.txt` - Optimized dependencies
|
| 19 |
+
- `app/main.py` - FastAPI application
|
| 20 |
+
|
| 21 |
+
### 2. Set Up Environment Variables
|
| 22 |
+
|
| 23 |
+
In your Hugging Face Space settings, add these environment variables:
|
| 24 |
+
|
| 25 |
+
```bash
|
| 26 |
+
# Required for Groq LLM
|
| 27 |
+
GROQ_API_KEY=your_groq_api_key_here
|
| 28 |
+
|
| 29 |
+
# Database (use SQLite for simplicity)
|
| 30 |
+
DATABASE_URL=sqlite+aiosqlite:///./dubsway_hf.db
|
| 31 |
+
|
| 32 |
+
# AWS S3 (optional - for file storage)
|
| 33 |
+
AWS_ACCESS_KEY_ID=your_aws_access_key
|
| 34 |
+
AWS_SECRET_ACCESS_KEY=your_aws_secret_key
|
| 35 |
+
AWS_REGION=us-east-1
|
| 36 |
+
S3_BUCKET_NAME=your_s3_bucket_name
|
| 37 |
+
|
| 38 |
+
# Application
|
| 39 |
+
SECRET_KEY=your_secret_key_here
|
| 40 |
+
ALGORITHM=HS256
|
| 41 |
+
ACCESS_TOKEN_EXPIRE_MINUTES=30
|
| 42 |
+
|
| 43 |
+
# Environment
|
| 44 |
+
ENVIRONMENT=production
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
### 3. Create Hugging Face Space
|
| 48 |
+
|
| 49 |
+
1. Go to [huggingface.co/spaces](https://huggingface.co/spaces)
|
| 50 |
+
2. Click "Create new Space"
|
| 51 |
+
3. Choose settings:
|
| 52 |
+
- **Owner**: Your username
|
| 53 |
+
- **Space name**: `dubsway-video-ai` (or your preferred name)
|
| 54 |
+
- **License**: MIT
|
| 55 |
+
- **SDK**: Docker
|
| 56 |
+
- **Visibility**: Public or Private
|
| 57 |
+
|
| 58 |
+
### 4. Connect GitHub Repository
|
| 59 |
+
|
| 60 |
+
1. In your Space settings, go to "Repository" tab
|
| 61 |
+
2. Select "Connect to existing repository"
|
| 62 |
+
3. Choose your GitHub repository
|
| 63 |
+
4. Set the branch (usually `main` or `master`)
|
| 64 |
+
|
| 65 |
+
### 5. Configure Build Settings
|
| 66 |
+
|
| 67 |
+
The Space will automatically use:
|
| 68 |
+
- `.huggingface.yaml` for configuration
|
| 69 |
+
- `Dockerfile` for container build
|
| 70 |
+
- `requirements-hf.txt` for dependencies
|
| 71 |
+
|
| 72 |
+
### 6. Deploy
|
| 73 |
+
|
| 74 |
+
1. Push your changes to GitHub
|
| 75 |
+
2. Hugging Face will automatically build and deploy
|
| 76 |
+
3. Monitor the build logs in your Space
|
| 77 |
+
|
| 78 |
+
## π Verification
|
| 79 |
+
|
| 80 |
+
Once deployed, you can:
|
| 81 |
+
|
| 82 |
+
1. **Check the API**: Visit `https://your-username-dubsway-video-ai.hf.space/`
|
| 83 |
+
2. **View Documentation**: Visit `https://your-username-dubsway-video-ai.hf.space/docs`
|
| 84 |
+
3. **Health Check**: Visit `https://your-username-dubsway-video-ai.hf.space/health`
|
| 85 |
+
|
| 86 |
+
## π οΈ API Endpoints
|
| 87 |
+
|
| 88 |
+
Your deployed API will have these endpoints:
|
| 89 |
+
|
| 90 |
+
- `GET /` - Root endpoint with API info
|
| 91 |
+
- `GET /health` - Health check
|
| 92 |
+
- `GET /docs` - Interactive API documentation
|
| 93 |
+
- `POST /api/auth/register` - User registration
|
| 94 |
+
- `POST /api/auth/login` - User login
|
| 95 |
+
- `POST /api/upload/video` - Video upload and analysis
|
| 96 |
+
- `GET /api/dashboard/videos` - Get user videos
|
| 97 |
+
- `POST /api/custom-chatbot/chat` - Chat with video content
|
| 98 |
+
|
| 99 |
+
## π§ Troubleshooting
|
| 100 |
+
|
| 101 |
+
### Common Issues
|
| 102 |
+
|
| 103 |
+
1. **Build Failures**:
|
| 104 |
+
- Check the build logs in your Space
|
| 105 |
+
- Ensure all dependencies are in `requirements-hf.txt`
|
| 106 |
+
- Verify Dockerfile syntax
|
| 107 |
+
|
| 108 |
+
2. **Environment Variables**:
|
| 109 |
+
- Make sure all required env vars are set in Space settings
|
| 110 |
+
- Check for typos in variable names
|
| 111 |
+
|
| 112 |
+
3. **Memory Issues**:
|
| 113 |
+
- The Space uses CPU-only PyTorch to save memory
|
| 114 |
+
- Consider using smaller models for production
|
| 115 |
+
|
| 116 |
+
4. **Database Issues**:
|
| 117 |
+
- Use SQLite for simplicity in Spaces
|
| 118 |
+
- Ensure database directory is writable
|
| 119 |
+
|
| 120 |
+
### Monitoring
|
| 121 |
+
|
| 122 |
+
- Check Space logs for errors
|
| 123 |
+
- Monitor resource usage
|
| 124 |
+
- Test API endpoints regularly
|
| 125 |
+
|
| 126 |
+
## π Continuous Deployment
|
| 127 |
+
|
| 128 |
+
Once connected to GitHub:
|
| 129 |
+
1. Push changes to your repository
|
| 130 |
+
2. Hugging Face automatically rebuilds and deploys
|
| 131 |
+
3. Monitor deployment status in your Space
|
| 132 |
+
|
| 133 |
+
## π Performance Optimization
|
| 134 |
+
|
| 135 |
+
For better performance in Hugging Face Spaces:
|
| 136 |
+
|
| 137 |
+
1. **Use CPU-only PyTorch**: Already configured in Dockerfile
|
| 138 |
+
2. **Optimize model loading**: Models are loaded on first request
|
| 139 |
+
3. **Use SQLite**: Lighter than PostgreSQL for Spaces
|
| 140 |
+
4. **Cache results**: Implement caching for repeated requests
|
| 141 |
+
|
| 142 |
+
## π Security Considerations
|
| 143 |
+
|
| 144 |
+
1. **API Keys**: Store sensitive keys in Space environment variables
|
| 145 |
+
2. **CORS**: Configure allowed origins for production
|
| 146 |
+
3. **Rate Limiting**: Implement rate limiting for public APIs
|
| 147 |
+
4. **Input Validation**: Validate all user inputs
|
| 148 |
+
|
| 149 |
+
## π Support
|
| 150 |
+
|
| 151 |
+
If you encounter issues:
|
| 152 |
+
1. Check the build logs in your Space
|
| 153 |
+
2. Review the troubleshooting section
|
| 154 |
+
3. Check Hugging Face Spaces documentation
|
| 155 |
+
4. Monitor your application logs
|
| 156 |
+
|
| 157 |
+
---
|
| 158 |
+
|
| 159 |
+
**Happy Deploying! π**
|
| 160 |
+
|
| 161 |
+
Your Dubsway Video AI system will be accessible at:
|
| 162 |
+
`https://your-username-dubsway-video-ai.hf.space/`
|
app/main.py
CHANGED
|
@@ -1,19 +1,25 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
import logging
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
from app.auth import router as auth_router
|
| 6 |
from app.upload import router as upload_router
|
| 7 |
from app.dashboard import router as dashboard_router
|
| 8 |
from app.agent.custom_chatbot import router as custom_chatbot_router
|
| 9 |
# from app.routes import pdf_ingestion
|
|
|
|
| 10 |
# Initialize logger
|
| 11 |
logging.basicConfig(level=logging.INFO)
|
| 12 |
logger = logging.getLogger(__name__)
|
| 13 |
|
| 14 |
app = FastAPI(
|
| 15 |
title="Dubsway Video AI",
|
| 16 |
-
description="Production-ready API for auth, video upload, and analysis",
|
| 17 |
version="1.0.0",
|
| 18 |
docs_url="/docs", # Optional: secure this in prod
|
| 19 |
redoc_url=None,
|
|
@@ -35,10 +41,26 @@ app.include_router(dashboard_router, prefix="/api", tags=["Dashboard"])
|
|
| 35 |
app.include_router(custom_chatbot_router, prefix="/api", tags=["Custom Chatbot"])
|
| 36 |
# app.include_router(pdf_ingestion.router, prefix="/api", tags=["PDF Ingestion"])
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
@app.on_event("startup")
|
| 39 |
async def startup_event():
|
| 40 |
logger.info("β
FastAPI app started")
|
| 41 |
-
|
|
|
|
| 42 |
|
| 43 |
@app.on_event("shutdown")
|
| 44 |
async def shutdown_event():
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
import logging
|
| 4 |
+
import os
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
|
| 7 |
+
# Load environment variables
|
| 8 |
+
load_dotenv()
|
| 9 |
|
| 10 |
from app.auth import router as auth_router
|
| 11 |
from app.upload import router as upload_router
|
| 12 |
from app.dashboard import router as dashboard_router
|
| 13 |
from app.agent.custom_chatbot import router as custom_chatbot_router
|
| 14 |
# from app.routes import pdf_ingestion
|
| 15 |
+
|
| 16 |
# Initialize logger
|
| 17 |
logging.basicConfig(level=logging.INFO)
|
| 18 |
logger = logging.getLogger(__name__)
|
| 19 |
|
| 20 |
app = FastAPI(
|
| 21 |
title="Dubsway Video AI",
|
| 22 |
+
description="Production-ready API for auth, video upload, and analysis with Groq LLM integration",
|
| 23 |
version="1.0.0",
|
| 24 |
docs_url="/docs", # Optional: secure this in prod
|
| 25 |
redoc_url=None,
|
|
|
|
| 41 |
app.include_router(custom_chatbot_router, prefix="/api", tags=["Custom Chatbot"])
|
| 42 |
# app.include_router(pdf_ingestion.router, prefix="/api", tags=["PDF Ingestion"])
|
| 43 |
|
| 44 |
+
@app.get("/")
|
| 45 |
+
async def root():
|
| 46 |
+
"""Root endpoint for Hugging Face Spaces"""
|
| 47 |
+
return {
|
| 48 |
+
"message": "π₯ Dubsway Video AI API",
|
| 49 |
+
"version": "1.0.0",
|
| 50 |
+
"docs": "/docs",
|
| 51 |
+
"status": "running"
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
@app.get("/health")
|
| 55 |
+
async def health_check():
|
| 56 |
+
"""Health check endpoint for Hugging Face Spaces"""
|
| 57 |
+
return {"status": "healthy", "service": "dubsway-video-ai"}
|
| 58 |
+
|
| 59 |
@app.on_event("startup")
|
| 60 |
async def startup_event():
|
| 61 |
logger.info("β
FastAPI app started")
|
| 62 |
+
logger.info(f"Environment: {os.getenv('ENVIRONMENT', 'development')}")
|
| 63 |
+
logger.info(f"Database URL configured: {'DATABASE_URL' in os.environ}")
|
| 64 |
|
| 65 |
@app.on_event("shutdown")
|
| 66 |
async def shutdown_event():
|
clean-for-deployment.bat
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
echo π§Ή Cleaning repository for Hugging Face deployment...
|
| 3 |
+
|
| 4 |
+
echo.
|
| 5 |
+
echo π Removing binary files and vector stores...
|
| 6 |
+
|
| 7 |
+
REM Remove vector store directory
|
| 8 |
+
if exist "vector_store" (
|
| 9 |
+
echo Removing vector_store directory...
|
| 10 |
+
rmdir /s /q "vector_store"
|
| 11 |
+
echo β
vector_store removed
|
| 12 |
+
) else (
|
| 13 |
+
echo βΉοΈ vector_store directory not found
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
REM Remove database files
|
| 17 |
+
for %%f in (*.db *.sqlite *.sqlite3) do (
|
| 18 |
+
if exist "%%f" (
|
| 19 |
+
echo Removing %%f...
|
| 20 |
+
del "%%f"
|
| 21 |
+
echo β
%%f removed
|
| 22 |
+
)
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
REM Remove FAISS files
|
| 26 |
+
for %%f in (*.faiss *.index *.bin) do (
|
| 27 |
+
if exist "%%f" (
|
| 28 |
+
echo Removing %%f...
|
| 29 |
+
del "%%f"
|
| 30 |
+
echo β
%%f removed
|
| 31 |
+
)
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
REM Remove log files
|
| 35 |
+
for %%f in (*.log) do (
|
| 36 |
+
if exist "%%f" (
|
| 37 |
+
echo Removing %%f...
|
| 38 |
+
del "%%f"
|
| 39 |
+
echo β
%%f removed
|
| 40 |
+
)
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
echo.
|
| 44 |
+
echo π Updating git...
|
| 45 |
+
|
| 46 |
+
REM Remove tracked files that should be ignored
|
| 47 |
+
git rm -r --cached vector_store/ 2>nul
|
| 48 |
+
git rm --cached *.db 2>nul
|
| 49 |
+
git rm --cached *.sqlite 2>nul
|
| 50 |
+
git rm --cached *.sqlite3 2>nul
|
| 51 |
+
git rm --cached *.faiss 2>nul
|
| 52 |
+
git rm --cached *.log 2>nul
|
| 53 |
+
|
| 54 |
+
echo.
|
| 55 |
+
echo π Committing changes...
|
| 56 |
+
git add .
|
| 57 |
+
git commit -m "Clean repository for Hugging Face deployment - remove binary files"
|
| 58 |
+
|
| 59 |
+
echo.
|
| 60 |
+
echo β
Repository cleaned! You can now push to Hugging Face:
|
| 61 |
+
echo.
|
| 62 |
+
echo git push space develop
|
| 63 |
+
echo.
|
| 64 |
+
echo Or create a new branch:
|
| 65 |
+
echo git checkout -b main
|
| 66 |
+
echo git push space main
|
| 67 |
+
echo.
|
| 68 |
+
|
| 69 |
+
pause
|
deploy-to-hf.bat
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
echo π Preparing Dubsway Video AI for Hugging Face Deployment...
|
| 3 |
+
|
| 4 |
+
echo.
|
| 5 |
+
echo π Checking prerequisites...
|
| 6 |
+
|
| 7 |
+
REM Check if git is available
|
| 8 |
+
git --version >nul 2>&1
|
| 9 |
+
if errorlevel 1 (
|
| 10 |
+
echo β Git is not installed or not in PATH
|
| 11 |
+
pause
|
| 12 |
+
exit /b 1
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
REM Check if we're in a git repository
|
| 16 |
+
git status >nul 2>&1
|
| 17 |
+
if errorlevel 1 (
|
| 18 |
+
echo β Not in a git repository. Please run this from your project root.
|
| 19 |
+
pause
|
| 20 |
+
exit /b 1
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
echo β
Git repository found
|
| 24 |
+
|
| 25 |
+
REM Check for required files
|
| 26 |
+
if not exist ".huggingface.yaml" (
|
| 27 |
+
echo β .huggingface.yaml not found
|
| 28 |
+
pause
|
| 29 |
+
exit /b 1
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
if not exist "Dockerfile" (
|
| 33 |
+
echo β Dockerfile not found
|
| 34 |
+
pause
|
| 35 |
+
exit /b 1
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
if not exist "requirements-hf.txt" (
|
| 39 |
+
echo β requirements-hf.txt not found
|
| 40 |
+
pause
|
| 41 |
+
exit /b 1
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
echo β
All required files found
|
| 45 |
+
|
| 46 |
+
echo.
|
| 47 |
+
echo π Checking git status...
|
| 48 |
+
git status --porcelain
|
| 49 |
+
|
| 50 |
+
echo.
|
| 51 |
+
echo π Current branch:
|
| 52 |
+
git branch --show-current
|
| 53 |
+
|
| 54 |
+
echo.
|
| 55 |
+
echo π Ready to deploy! Follow these steps:
|
| 56 |
+
echo.
|
| 57 |
+
echo 1. Push your changes to GitHub:
|
| 58 |
+
echo git add .
|
| 59 |
+
echo git commit -m "Deploy to Hugging Face Spaces"
|
| 60 |
+
echo git push origin main
|
| 61 |
+
echo.
|
| 62 |
+
echo 2. Go to https://huggingface.co/spaces
|
| 63 |
+
echo.
|
| 64 |
+
echo 3. Create a new Space with these settings:
|
| 65 |
+
echo - SDK: Docker
|
| 66 |
+
echo - License: MIT
|
| 67 |
+
echo - Connect to your GitHub repository
|
| 68 |
+
echo.
|
| 69 |
+
echo 4. Set environment variables in your Space settings:
|
| 70 |
+
echo - GROQ_API_KEY
|
| 71 |
+
echo - DATABASE_URL=sqlite+aiosqlite:///./dubsway_hf.db
|
| 72 |
+
echo - SECRET_KEY
|
| 73 |
+
echo - AWS_ACCESS_KEY_ID (if using S3)
|
| 74 |
+
echo - AWS_SECRET_ACCESS_KEY (if using S3)
|
| 75 |
+
echo - S3_BUCKET_NAME (if using S3)
|
| 76 |
+
echo.
|
| 77 |
+
echo 5. Monitor deployment in your Space
|
| 78 |
+
echo.
|
| 79 |
+
echo π See HUGGINGFACE_DEPLOYMENT.md for detailed instructions
|
| 80 |
+
echo.
|
| 81 |
+
|
| 82 |
+
pause
|
push-to-hf.bat
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
echo π Pushing to Hugging Face Spaces...
|
| 3 |
+
|
| 4 |
+
echo.
|
| 5 |
+
echo π§Ή Cleaning binary files...
|
| 6 |
+
|
| 7 |
+
REM Remove vector store from git tracking
|
| 8 |
+
git rm -r --cached vector_store/ 2>nul
|
| 9 |
+
git rm --cached *.db 2>nul
|
| 10 |
+
git rm --cached *.log 2>nul
|
| 11 |
+
|
| 12 |
+
echo.
|
| 13 |
+
echo π Committing changes...
|
| 14 |
+
git add .
|
| 15 |
+
git commit -m "Clean repository for Hugging Face deployment"
|
| 16 |
+
|
| 17 |
+
echo.
|
| 18 |
+
echo π Pushing to Hugging Face...
|
| 19 |
+
echo Choose your branch:
|
| 20 |
+
echo 1. Push to develop branch
|
| 21 |
+
echo 2. Create and push to main branch
|
| 22 |
+
echo 3. Cancel
|
| 23 |
+
echo.
|
| 24 |
+
set /p choice="Enter choice (1-3): "
|
| 25 |
+
|
| 26 |
+
if "%choice%"=="1" (
|
| 27 |
+
echo Pushing to develop branch...
|
| 28 |
+
git push space develop
|
| 29 |
+
) else if "%choice%"=="2" (
|
| 30 |
+
echo Creating main branch...
|
| 31 |
+
git checkout -b main
|
| 32 |
+
echo Pushing to main branch...
|
| 33 |
+
git push space main
|
| 34 |
+
) else (
|
| 35 |
+
echo Cancelled.
|
| 36 |
+
pause
|
| 37 |
+
exit /b 0
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
echo.
|
| 41 |
+
echo β
Push completed!
|
| 42 |
+
echo.
|
| 43 |
+
echo π Your Space URL will be:
|
| 44 |
+
echo https://huggingface.co/spaces/peace2024/DubswayAgenticAI
|
| 45 |
+
echo.
|
| 46 |
+
echo π Monitor the build logs in your Space settings.
|
| 47 |
+
echo.
|
| 48 |
+
|
| 49 |
+
pause
|
requirements-hf.txt
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Core FastAPI dependencies
|
| 2 |
+
fastapi==0.104.1
|
| 3 |
+
uvicorn[standard]==0.24.0
|
| 4 |
+
python-dotenv==1.0.0
|
| 5 |
+
python-multipart==0.0.6
|
| 6 |
+
pydantic[email]==1.10.13
|
| 7 |
+
|
| 8 |
+
# Database
|
| 9 |
+
asyncpg==0.29.0
|
| 10 |
+
sqlalchemy==2.0.23
|
| 11 |
+
aiosqlite==0.19.0
|
| 12 |
+
|
| 13 |
+
# Auth
|
| 14 |
+
passlib[bcrypt]==1.7.4
|
| 15 |
+
python-jose[cryptography]==3.3.0
|
| 16 |
+
|
| 17 |
+
# LLM & RAG
|
| 18 |
+
langchain==0.1.13
|
| 19 |
+
langchain-openai==0.1.7
|
| 20 |
+
langchain-community==0.0.38
|
| 21 |
+
langchain-core==0.1.53
|
| 22 |
+
langchain-groq==0.0.1
|
| 23 |
+
|
| 24 |
+
# Embedding & vector DB
|
| 25 |
+
sentence-transformers==2.2.2
|
| 26 |
+
faiss-cpu==1.7.4
|
| 27 |
+
|
| 28 |
+
# Transcription
|
| 29 |
+
faster-whisper==1.0.1
|
| 30 |
+
ctranslate2==4.0.0
|
| 31 |
+
|
| 32 |
+
# Enhanced Analysis
|
| 33 |
+
transformers==4.35.2
|
| 34 |
+
duckduckgo-search==4.1.1
|
| 35 |
+
wikipedia-api==0.6.0
|
| 36 |
+
timm==0.9.12
|
| 37 |
+
|
| 38 |
+
# PDF & Reports
|
| 39 |
+
PyPDF2==3.0.1
|
| 40 |
+
reportlab==4.0.7
|
| 41 |
+
beautifulsoup4==4.12.2
|
| 42 |
+
|
| 43 |
+
# AWS
|
| 44 |
+
boto3==1.34.0
|
| 45 |
+
|
| 46 |
+
# Utilities
|
| 47 |
+
requests==2.31.0
|