assitantchatbot / README.md
aghaai's picture
Initial deployment
e4e7a94
metadata
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
  2. Supabase Project: Create a project at supabase.com
  3. OpenAI API Key: Get your API key from platform.openai.com

πŸš€ Deploy to Hugging Face Spaces

Option 1: Deploy via Hugging Face Web Interface

  1. Go to Hugging Face 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

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

# 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! πŸš€