A newer version of the Gradio SDK is available: 6.14.0
π Supabase Gradio Database Interface - Deployment Guide
This project creates a Gradio web interface for interacting with your Supabase PostgreSQL database.
π Features
- π View Tables: Browse and display data from your database tables
- β Add Data: Insert new records into sample tables
- π Custom Queries: Execute custom SQL queries
- π Real-time Updates: Refresh table lists and data
- π‘οΈ Secure Connection: Uses environment variables for credentials
π οΈ Local Development Setup
1. Prerequisites
- Python 3.9+
- Conda (recommended)
2. Environment Setup
# Create conda environment
conda create -n superbase_gradio python=3.9 -y
conda activate superbase_gradio
# Install dependencies
pip install -r requirements.txt
3. Database Configuration
Set up your environment variables with your Supabase credentials:
export DB_HOST="db.bnjblzcqaumctpehgoid.supabase.co"
export DB_PORT="5432"
export DB_NAME="postgres"
export DB_USER="postgres"
export DB_PASSWORD="your_actual_password_here"
export HF_TOKEN="your_hf_token_here"
4. Test Connection
python test_connection.py
5. Run Locally
python app.py
Access the interface at: http://localhost:7860
π Hugging Face Deployment
1. Push to Repository
# Add and commit all files
git add .
git commit -m "Initial Supabase Gradio interface"
git push origin main
2. Set Environment Variables
In your Hugging Face Space settings, add these secrets:
DB_HOST:db.bnjblzcqaumctpehgoid.supabase.coDB_PORT:5432DB_NAME:postgresDB_USER:postgresDB_PASSWORD:your_actual_supabase_passwordHF_TOKEN:your_hf_token_here
3. Repository Structure
testDB_full/
βββ app.py # Main Gradio application
βββ requirements.txt # Python dependencies
βββ config.py # Configuration helper
βββ test_connection.py # Connection test script
βββ README.md # Hugging Face Space README
βββ DEPLOYMENT.md # This deployment guide
4. Deployment Process
- Your Space will automatically rebuild when you push changes
- The app will be available at:
https://huggingface.co/spaces/Babajaan/testDB - Check the logs for any deployment issues
π Security Notes
- Never commit passwords or sensitive credentials to the repository
- Always use environment variables for database credentials
- For production use, consider implementing authentication
- Limit database permissions for the connection user
π§ͺ Testing the Interface
- View Tables: Select a table from the dropdown and view its data
- Create Sample Table: Use the "Create Sample Table" button to set up test data
- Add Records: Fill in the form to add new sample records
- Custom Queries: Execute SELECT queries to explore your data
π Troubleshooting
Common Issues:
- Connection Failed: Check your database credentials and network connectivity
- Table Not Found: Ensure the table exists and you have proper permissions
- Deployment Issues: Check Hugging Face Space logs for specific errors
Debug Steps:
- Run
python test_connection.pylocally first - Verify all environment variables are set correctly
- Check database firewall settings allow connections from Hugging Face
- Review application logs in Hugging Face Space settings
π Database Operations
The interface supports:
- SELECT: View and query data
- INSERT: Add new records (via forms)
- CREATE TABLE: Create sample tables for testing
- Custom SQL: Execute any SQL query (use with caution)
π Useful Links
β οΈ Important: Remember to replace [YOUR-PASSWORD] with your actual Supabase database password!