Spaces:
Running
Hugging Face Spaces Secrets Setup Guide
This guide explains how to configure and deploy your Telugu Dialect Map to Hugging Face Spaces with secure secrets management.
Overview
Your application requires two secret files:
config.json: Configuration for Google Sheets sync and automationcredentials.json: Google Cloud service account credentials
These files contain sensitive information and should NEVER be committed to git. Instead, we'll use Hugging Face Spaces secrets (environment variables) to store them securely.
Step 1: Obtain Google Service Account Credentials
1.1 Create a Google Cloud Project
- Go to Google Cloud Console
- Create a new project or select an existing one
- Note your project ID
1.2 Enable Google Sheets API
- In your project, go to APIs & Services β Library
- Search for "Google Sheets API"
- Click Enable
1.3 Create a Service Account
- Go to APIs & Services β Credentials
- Click Create Credentials β Service Account
- Fill in the details:
- Service account name:
dialect-map-automation - Service account ID: (auto-generated)
- Description: "Service account for dialect map Google Sheets automation"
- Service account name:
- Click Create and Continue
- Skip the optional steps (roles and user access)
- Click Done
1.4 Create and Download Service Account Key
- Click on the service account you just created
- Go to the Keys tab
- Click Add Key β Create new key
- Select JSON format
- Click Create
- A JSON file will be downloaded - this is your
credentials.json - Keep this file secure! It provides full access to your Google Sheets
1.5 Share Your Google Sheets with the Service Account
- Open your
credentials.jsonfile - Find the
client_emailfield (e.g.,dialect-map-automation@your-project.iam.gserviceaccount.com) - Copy this email address
- Open each Google Sheet you want to sync
- Click Share button
- Paste the service account email
- Give it Editor or Viewer access (Editor if you want to write data back)
- Click Send
Step 2: Configure config.json
Create your config.json file with your specific settings:
{
"google_sheets": {
"enabled": true,
"sync_interval_minutes": 5,
"credentials_file": "credentials.json",
"spreadsheets": [
{
"id": "YOUR_ACTUAL_SPREADSHEET_ID_HERE",
"sheet_name": "processed_dialects",
"output_file": "sheets_output/processed_dialects.csv"
},
{
"id": "YOUR_ACTUAL_SPREADSHEET_ID_HERE",
"sheet_name": "digiwords_grouped",
"output_file": "sheets_output/digiwords_grouped.csv"
}
]
},
"file_watcher": {
"enabled": true,
"watch_directory": "sheets_output",
"file_patterns": ["*.csv"]
},
"output": {
"json_directory": "data/processed"
}
}
Finding Your Spreadsheet ID
Your Google Sheets URL looks like:
https://docs.google.com/spreadsheets/d/1AbC123XyZ456_Example_ID/edit#gid=0
^^^^^^^^^^^^^^^^^^^^^^^^^
This is your spreadsheet ID
Copy the ID from your URL and replace YOUR_ACTUAL_SPREADSHEET_ID_HERE in the config.
Step 3: Deploy to Hugging Face Spaces
3.1 Create a New Space
- Go to Hugging Face
- Click your profile β New Space
- Fill in the details:
- Space name:
telugu-dialect-map(or your choice) - License: Choose appropriate license
- Space SDK: Select Static (we'll use a custom Python app)
- Visibility: Public or Private
- Space name:
- Click Create Space
3.2 Push Your Code to the Space
You can either:
Option A: Use Git
# Clone the Space repository
git clone https://huggingface.co/spaces/YOUR_USERNAME/telugu-dialect-map
cd telugu-dialect-map
# Copy your project files (excluding secrets!)
cp -r /path/to/dialect-map/* .
# Make sure .gitignore is in place
cat .gitignore # Should include config.json and credentials.json
# Commit and push
git add .
git commit -m "Initial commit"
git push
Option B: Upload via Web Interface
- In your Space, click Files tab
- Click Add file β Upload files
- Select all your project files (EXCEPT
config.jsonandcredentials.json) - Click Commit changes
3.3 Add Secrets to Your Space
This is the critical step - we'll add your sensitive credentials as secrets.
- In your Space, click the Settings tab
- Scroll down to Repository secrets
- Add the following secrets:
Secret 1: HF_CONFIG_JSON
Name:
HF_CONFIG_JSONValue: Paste the entire contents of your
config.jsonfileExample (all on one line):
{"google_sheets":{"enabled":true,"sync_interval_minutes":5,"credentials_file":"credentials.json","spreadsheets":[{"id":"1AbC123XyZ456_Example","sheet_name":"processed_dialects","output_file":"sheets_output/processed_dialects.csv"}]},"file_watcher":{"enabled":true,"watch_directory":"sheets_output","file_patterns":["*.csv"]},"output":{"json_directory":"data/processed"}}
Secret 2: HF_CREDENTIALS_JSON
Name:
HF_CREDENTIALS_JSONValue: Paste the entire contents of your
credentials.jsonfileExample (all on one line, with escaped newlines in private key):
{"type":"service_account","project_id":"your-project","private_key_id":"abc123...","private_key":"-----BEGIN PRIVATE KEY-----\\nMIIEvQIB...\\n-----END PRIVATE KEY-----\\n","client_email":"name@project.iam.gserviceaccount.com",...}
- Click Add secret for each one
Important Notes:
- The entire JSON must be on one line (no newlines except in the
private_keyfield where\nshould be\\n) - Make sure to escape special characters if needed
- You can use a JSON minifier tool to compact your JSON
3.4 Rebuild Your Space
After adding secrets:
- Your Space should automatically rebuild
- Watch the Logs tab for any errors
- Once built, click App tab to view your running application
Step 4: Verify Deployment
4.1 Check Space Logs
Go to your Space's Logs tab
You should see:
π Loading secrets from environment variables... β Created config.json from HF_CONFIG_JSON secret β Created credentials.json from HF_CREDENTIALS_JSON secret π Starting automation runner... β Automation runner started π Starting web server on port 7860...If you see errors, check:
- JSON formatting in your secrets
- Spreadsheet IDs are correct
- Service account has access to sheets
4.2 Access Your Application
- Click the App tab
- You should see your Telugu Dialect Map interface
- The map should load with data from your Google Sheets
4.3 Verify Automation
- Edit your Google Sheet (add/modify some dialect data)
- Wait 5 minutes (or your configured interval)
- Check the Space logs - you should see sync messages
- Refresh your app - changes should appear
Troubleshooting
"HF_CONFIG_JSON not found in environment"
Problem: The secret wasn't added or has the wrong name.
Solution:
- Go to Space Settings β Repository secrets
- Verify the secret name is exactly
HF_CONFIG_JSON(case-sensitive) - Add it if missing
- Rebuild the Space
"Error parsing HF_CONFIG_JSON"
Problem: The JSON is malformed.
Solution:
- Copy your
config.jsoncontent - Use a JSON validator (e.g., jsonlint.com)
- Make sure it's valid JSON
- Remove all newlines (except
\nin strings should become\\n) - Update the secret with the corrected value
"Connection refused" or "Credentials invalid"
Problem: Google service account credentials are wrong or not shared.
Solution:
- Verify
credentials.jsoncontent is correct - Check that you shared your Google Sheets with the service account email
- Verify the Sheets API is enabled in Google Cloud Console
- Regenerate service account key if needed
"Automation not syncing"
Problem: Automation runner isn't working.
Solution:
- Check Space logs for error messages
- Verify
spreadsheets.idvalues in config.json match your actual sheet IDs - Verify
sheet_namevalues match the tab names in your spreadsheets - Check that service account has Editor access (not just Viewer)
Space keeps crashing or restarting
Problem: HF Spaces free tier may have resource limits.
Solution:
- Consider upgrading to a paid Space for guaranteed uptime
- Reduce sync interval (e.g., 15-30 minutes instead of 5)
- Check logs for memory/CPU issues
Local Testing (Before Deploying)
Before deploying to HF Spaces, test locally:
1. Create actual config files
cd /home/kashikuldeep/Desktop/dialect-map
# Copy examples and fill in real values
cp config.json.example config.json
cp credentials.json.example credentials.json
# Edit with your actual values
nano config.json
nano credentials.json
2. Test the app
# Run the app locally
python app.py
# Should see:
# β
Created config.json from HF_CONFIG_JSON secret (if using .env)
# π Starting automation runner...
# π Starting web server on port 7860...
# Open browser to http://localhost:7860
3. Test with environment variables (simulating HF Spaces)
# Create .env file
cp .env.example .env
# Edit .env with your actual JSON (minified)
nano .env
# Load environment and run
python -c "from dotenv import load_dotenv; load_dotenv()" && python app.py
Security Best Practices
Never commit secrets to git
- Keep
config.jsonandcredentials.jsonin.gitignore - Double-check before pushing code
- Keep
Rotate credentials regularly
- Generate new service account keys periodically
- Update HF Spaces secrets
Use minimal permissions
- Service account should only have access to necessary sheets
- Use Viewer access if you don't need to write back
Monitor usage
- Check Google Cloud Console for API usage
- Set up billing alerts
- Review Space logs regularly
Need Help?
- Google Cloud Issues: Google Cloud Support
- Hugging Face Spaces: HF Documentation
- Project Issues: Check the Space logs first, then review this guide
Happy Mapping! πΊοΈ