Spaces:
Sleeping
Download GDRIVE_SETUP.md from mistral-hackaton-2026/TB-Guard-XAI: direct link, hf CLI and curl.
- Browser
- Download file 9.25 kB
-
https://huggingface.co/spaces/mistral-hackaton-2026/TB-Guard-XAI/resolve/main/GDRIVE_SETUP.md
- Command line
-
hf download hf://spaces/mistral-hackaton-2026/TB-Guard-XAI/GDRIVE_SETUP.md
-
curl -L -o GDRIVE_SETUP.md https://huggingface.co/spaces/mistral-hackaton-2026/TB-Guard-XAI/resolve/main/GDRIVE_SETUP.md
Google Drive Batch Processor Setup Guide
๐ฏ What This Does
Automatically processes chest X-rays uploaded to Google Drive using your live Hugging Face Space:
- Upload X-rays to "TB_XRay_Inbox" folder in Google Drive
- System detects new files and sends them to your HF Space API
- HF Space analyzes with full pipeline (CNN โ Gemini โ Mistral โ RAG)
- PDF reports generated and saved to "TB_Reports" folder
- Original X-rays moved to "TB_Processed" folder
Key Advantage: Uses your deployed HF Space - no local model needed! ๐
๐ Prerequisites
- Python 3.10+
- Google Account
- Your Hugging Face Space must be running (https://huggingface.co/spaces/mistral-hackaton-2026/TB-Guard-XAI)
- Internet connection (for API calls)
๐ Setup Instructions (15 minutes)
Step 1: Enable Google Drive API
- Go to Google Cloud Console
- Create a new project or select existing one
- Click "Enable APIs and Services"
- Search for "Google Drive API"
- Click "Enable"
Step 2: Create OAuth Credentials
- In Google Cloud Console, go to "Credentials"
- Click "Create Credentials" โ "OAuth client ID"
- If prompted, configure OAuth consent screen:
- User Type: External
- App name: TB-Guard-XAI
- User support email: your email
- Developer contact: your email
- Save and continue through all steps
- Back to "Create OAuth client ID":
- Application type: Desktop app
- Name: TB-Guard-XAI Desktop
- Click "Create"
- Download the credentials JSON file
- Rename it to
credentials.json - Move it to your TB-Guard-XAI project folder
Step 3: Install Dependencies
pip install google-auth-oauthlib google-auth-httplib2 google-api-python-client fpdf requests
Note: No need to install PyTorch or model dependencies - we use the HF Space API!
Step 4: Configure Hugging Face Space URL (Optional)
The script uses your deployed HF Space by default. If you need to change it:
# Set environment variable
export HF_SPACE_URL="https://your-username-tb-guard-xai.hf.space"
# Or pass as argument
python gdrive_batch_processor.py https://your-username-tb-guard-xai.hf.space
Default URL: https://mistral-hackaton-2026-tb-guard-xai.hf.space
Step 5: First Run (Authentication)
python gdrive_batch_processor.py
This will:
- Open your browser for Google authentication
- Ask you to allow TB-Guard-XAI to access your Google Drive
- Click "Allow"
- Browser will show "Authentication successful"
- Close browser and return to terminal
A token.pickle file will be created (stores your authentication).
Step 6: Verify Setup
The script will:
- Test connection to your Hugging Face Space
- Create 3 folders in your Google Drive:
TB_XRay_Inbox- Upload X-rays hereTB_Reports- PDF reports saved hereTB_Processed- Processed X-rays moved here
You should see:
๐ Testing connection to Hugging Face Space...
URL: https://mistral-hackaton-2026-tb-guard-xai.hf.space
โ
API is online and ready!
โ
Google Drive folders ready:
๐ฅ Inbox: TB_XRay_Inbox
๐ Reports: TB_Reports
โ
Processed: TB_Processed
๐ฎ Usage
Watch Mode (Continuous)
python gdrive_batch_processor.py
Runs continuously, checking for new files every 30 seconds. Press Ctrl+C to stop.
Process Once (Single Run)
python gdrive_batch_processor.py once
Processes all files in inbox and exits.
Custom HF Space URL
# Use custom Hugging Face Space
python gdrive_batch_processor.py https://your-space.hf.space
# Or set environment variable
export HF_SPACE_URL="https://your-space.hf.space"
python gdrive_batch_processor.py
๐ Folder Structure in Google Drive
My Drive/
โโโ TB_XRay_Inbox/ # Upload X-rays here
โ โโโ (empty after processing)
โโโ TB_Reports/ # PDF reports appear here
โ โโโ patient001_report.pdf
โ โโโ patient002_report.pdf
โ โโโ ...
โโโ TB_Processed/ # Processed X-rays moved here
โโโ patient001.png
โโโ patient002.png
โโโ ...
๐ฌ Demo Workflow
Upload X-rays:
- Go to Google Drive
- Open "TB_XRay_Inbox" folder
- Upload chest X-ray images (PNG or JPEG)
Automatic Processing:
- Script detects new files
- Downloads X-ray temporarily
- Sends to Hugging Face Space API for analysis
- HF Space runs full pipeline: CNN โ Gemini โ Mistral โ RAG
- Receives results and generates PDF report
- Uploads report to "TB_Reports"
- Moves original to "TB_Processed"
- Cleans up temporary files
Processing Time per X-ray:
- Offline mode (high confidence): ~5-10 seconds
- Online mode (Gemini validation): ~15-20 seconds
- Full pipeline (Mistral synthesis): ~20-30 seconds
- Access Reports:
- Open "TB_Reports" folder
- Download or share PDF reports
- Reports include: prediction, probability, uncertainty, clinical synthesis
๐ง Configuration
Change Check Interval
Edit gdrive_batch_processor.py:
processor.watch_and_process(interval=60) # Check every 60 seconds
Change Folder Names
Edit at top of gdrive_batch_processor.py:
INBOX_FOLDER = "Your_Inbox_Name"
REPORTS_FOLDER = "Your_Reports_Name"
PROCESSED_FOLDER = "Your_Processed_Name"
๐ Troubleshooting
Error: "credentials.json not found"
- Download OAuth credentials from Google Cloud Console
- Rename to
credentials.json - Place in project root folder
Error: "Access denied"
- Delete
token.pickle - Run script again to re-authenticate
- Make sure you clicked "Allow" during authentication
Error: "API not enabled"
- Go to Google Cloud Console
- Enable Google Drive API
- Wait 1-2 minutes for activation
Files not processing
- Check if files are in correct folder ("TB_XRay_Inbox")
- Check file format (PNG or JPEG only)
- Check script is running (should show "Watching folder...")
- Check Hugging Face Space is running (visit URL in browser)
- Check internet connection
- Check API timeout (default 60 seconds)
Error: "API timeout"
- Your HF Space might be cold-starting (first request takes longer)
- Wait 1-2 minutes and try again
- Check HF Space logs for errors
- Increase timeout in code if needed
Error: "API error: 500"
- Check HF Space logs for errors
- Verify API keys are set in HF Space (MISTRAL_API_KEY, GEMINI_API_KEY)
- Try analyzing directly on HF Space web interface first
๐ Security Notes
credentials.json- OAuth client credentials (safe to commit if public app)token.pickle- Your personal access token (DO NOT commit to git)- Add to
.gitignore:token.pickle credentials.json temp_gdrive/
๐ Production Deployment
Run as Background Service (Linux)
Create /etc/systemd/system/tb-gdrive-processor.service:
[Unit]
Description=TB-Guard-XAI Google Drive Processor
After=network.target
[Service]
Type=simple
User=your_username
WorkingDirectory=/path/to/TB-Guard-XAI
ExecStart=/path/to/python gdrive_batch_processor.py
Restart=always
[Install]
WantedBy=multi-user.target
Enable and start:
sudo systemctl enable tb-gdrive-processor
sudo systemctl start tb-gdrive-processor
Run as Windows Service
Use NSSM (Non-Sucking Service Manager):
nssm install TB-Guard-XAI-GDrive "C:\path\to\python.exe" "C:\path\to\gdrive_batch_processor.py"
nssm start TB-Guard-XAI-GDrive
๐ Monitoring
Check Status
# Linux
sudo systemctl status tb-gdrive-processor
# Windows
nssm status TB-Guard-XAI-GDrive
View Logs
# Linux
journalctl -u tb-gdrive-processor -f
# Windows
# Check Windows Event Viewer
๐ฏ Use Cases
Rural Clinic Batch Processing
- Clinic staff upload day's X-rays at 5pm
- System processes overnight
- Reports ready by morning
Mobile Health Unit
- Field workers upload X-rays via mobile
- Cloud processing while traveling
- Reports available immediately
Telemedicine
- Remote clinics upload to shared Drive
- Central AI processes all cases
- Radiologists review flagged cases
๐ก Tips
- Upload files in batches for efficiency
- Use descriptive filenames (patient ID, date)
- Reports have same name as X-ray + "_report.pdf"
- System handles multiple files simultaneously
- Processed X-rays kept for audit trail
๐ Support
If you encounter issues:
- Check this guide's troubleshooting section
- Verify Google Drive API is enabled
- Check credentials.json is valid
- Ensure internet connection is stable
- Check Python dependencies are installed
Built for TB-Guard-XAI Mistral AI Worldwide Hackathon 2026