Spaces:
Running
Running
File size: 5,739 Bytes
e4e7a94 d7ed1ea 8db4a08 d7ed1ea |
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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
---
title: Unified Assistant - AI-Powered Document Creation Platform
emoji: π€
colorFrom: blue
colorTo: purple
sdk: docker
sdk_version: 20.10.23
app_file: app.py
pinned: false
---
# Unified Assistant - AI-Powered Document Creation Platform
## π Quick Deploy to Hugging Face Spaces
This project is configured for easy deployment to Hugging Face Spaces with Supabase database integration.
## π Prerequisites
1. **Hugging Face Account**: Create an account at [huggingface.co](https://huggingface.co)
2. **Supabase Project**: Create a project at [supabase.com](https://supabase.com)
3. **OpenAI API Key**: Get your API key from [platform.openai.com](https://platform.openai.com/api-keys)
## π Deploy to Hugging Face Spaces
### Option 1: Deploy via Hugging Face Web Interface
1. **Go to [Hugging Face Spaces](https://huggingface.co/spaces)**
2. **Click "Create new Space"**
3. **Choose settings:**
- **Owner**: Your username
- **Space name**: `unified-assistant` (or your preferred name)
- **Space SDK**: `Docker`
- **License**: Choose appropriate license
- **Visibility**: Public or Private
4. **Upload your code:**
- Clone this repository
- Upload all files to your new Space
5. **Configure Environment Variables:**
- Go to your Space β Settings β Repository secrets
- Add the following secrets:
```
SUPABASE_DB_URL=postgresql+asyncpg://postgres:WiHcl5UgLmP1rLGZ@nqdhdqdtpvqfecbsjaar.supabase.co:5432/postgres
ENVIRONMENT=production
OPENAI_API_KEY=your_openai_api_key_here
SECRET_KEY=Qee7sf39ipUhe_1pKCnsMLPU-aanOt-xs0gx3bsBuFo
DEBUG=false
HOST=0.0.0.0
PORT=7860
```
### Option 2: Deploy via Git
1. **Fork this repository** to your GitHub account
2. **Create a new Space** on Hugging Face
3. **Connect your GitHub repository**
4. **Configure environment variables** as shown above
## π§ Environment Variables
| Variable | Description | Required | Example |
|----------|-------------|----------|---------|
| `SUPABASE_DB_URL` | PostgreSQL connection string | β
Yes | `postgresql+asyncpg://postgres:password@host:5432/postgres` |
| `ENVIRONMENT` | Set to "production" | β
Yes | `production` |
| `OPENAI_API_KEY` | Your OpenAI API key | β
Yes | `sk-...` |
| `SECRET_KEY` | Secret key for JWT tokens | β
Yes | `your-secret-key` |
| `DEBUG` | Debug mode | Optional | `false` |
| `HOST` | Host binding | Optional | `0.0.0.0` |
| `PORT` | Port number | Optional | `7860` |
## π³ Docker Configuration
The project includes a `Dockerfile` optimized for Hugging Face Spaces:
- **Base Image**: Python 3.11-slim
- **Port**: 7860 (Hugging Face Spaces standard)
- **Health Check**: Automatic health monitoring
- **Environment**: Production-ready configuration
## π Monitoring Your Deployment
### Check Deployment Status
1. **Visit your Space URL**: `https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME`
2. **Check logs**: Go to your Space β Settings β Logs
3. **Health endpoint**: Visit `/health` on your deployed app
### Expected Logs on Startup
```
π§ Database Configuration:
Environment: production
Is Production: True
Is Hugging Face Deployment: True
Supabase DB URL set: Yes
Effective Database URL: postgresql+asyncpg://postgres:***@nqdhdqdtpvqfecbsjaar.supabase.co:5432/postgres
Database Type: PostgreSQL/Supabase
β
Using PostgreSQL/Supabase configuration
β
Database tables created successfully
π Application startup complete
```
## π Testing Your Deployment
### 1. Health Check
```bash
curl https://YOUR_SPACE_NAME.hf.space/health
```
### 2. API Documentation
Visit: `https://YOUR_SPACE_NAME.hf.space/docs`
### 3. Root Endpoint
Visit: `https://YOUR_SPACE_NAME.hf.space/`
## π οΈ Troubleshooting
### Common Issues
1. **Database Connection Failed**
- Check your `SUPABASE_DB_URL` is correct
- Verify your Supabase project is active
- Check Hugging Face Space logs for errors
2. **Environment Variables Not Set**
- Go to Space Settings β Repository secrets
- Add all required environment variables
- Redeploy your Space
3. **Port Issues**
- Hugging Face Spaces uses port 7860 by default
- The Dockerfile is already configured correctly
4. **Build Failures**
- Check the `requirements.txt` file is present
- Verify all dependencies are compatible
- Check build logs in your Space
### Debug Commands
```bash
# Check environment variables
python debug_env.py
# Test database connection
python test_database_config.py
# Quick connection test
python quick_test.py
```
## π Performance Optimization
### For Production Deployment
1. **Database Connection Pooling**: Already configured for Supabase
2. **Async Operations**: All database operations are async
3. **Caching**: Consider adding Redis for session caching
4. **Monitoring**: Use Hugging Face Space logs for monitoring
## π Security Notes
- β
Never commit `.env` files to version control
- β
Use Hugging Face secrets for all sensitive data
- β
Supabase automatically handles SSL connections
- β
Database credentials are encrypted in transit
- β
JWT tokens are properly secured
## π Support
If you encounter issues:
1. **Check Hugging Face Space logs**
2. **Verify environment variables**
3. **Test database connection locally first**
4. **Review the troubleshooting section above**
## π Success!
Once deployed, your Unified Assistant will be available at:
`https://YOUR_SPACE_NAME.hf.space`
The application will automatically:
- β
Connect to your Supabase database
- β
Create all necessary tables
- β
Start the FastAPI server
- β
Provide API documentation at `/docs`
- β
Handle authentication and user management
- β
Support all AI assistant features
---
**Happy Deploying! π** |