File size: 4,019 Bytes
1623af6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# πŸš€ 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
```bash
# 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:

```bash
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
```bash
python test_connection.py
```

### 5. Run Locally
```bash
python app.py
```

Access the interface at: `http://localhost:7860`

## 🌐 Hugging Face Deployment

### 1. Push to Repository
```bash
# 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.co`
- `DB_PORT`: `5432`
- `DB_NAME`: `postgres`
- `DB_USER`: `postgres`
- `DB_PASSWORD`: `your_actual_supabase_password`
- `HF_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
1. Your Space will automatically rebuild when you push changes
2. The app will be available at: `https://huggingface.co/spaces/Babajaan/testDB`
3. 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

1. **View Tables**: Select a table from the dropdown and view its data
2. **Create Sample Table**: Use the "Create Sample Table" button to set up test data
3. **Add Records**: Fill in the form to add new sample records
4. **Custom Queries**: Execute SELECT queries to explore your data

## πŸ†˜ Troubleshooting

### Common Issues:

1. **Connection Failed**: Check your database credentials and network connectivity
2. **Table Not Found**: Ensure the table exists and you have proper permissions
3. **Deployment Issues**: Check Hugging Face Space logs for specific errors

### Debug Steps:
1. Run `python test_connection.py` locally first
2. Verify all environment variables are set correctly
3. Check database firewall settings allow connections from Hugging Face
4. 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

- [Supabase Documentation](https://supabase.com/docs)
- [Gradio Documentation](https://gradio.app/docs)
- [Hugging Face Spaces](https://huggingface.co/docs/hub/spaces)

---

**⚠️ Important**: Remember to replace `[YOUR-PASSWORD]` with your actual Supabase database password!