Spaces:
Sleeping
A newer version of the Gradio SDK is available:
6.2.0
Deployment Guide
Deploying to HuggingFace Spaces
Prerequisites
- HuggingFace account
- API token from your LLM provider (or use HF Inference API)
Step-by-Step Deployment
1. Create a New Space
- Go to https://huggingface.co/spaces
- Click "Create new Space"
- Choose a name (e.g., "conversai-research-assistant")
- Select SDK: Gradio
- Choose visibility (Public or Private)
- Click "Create Space"
2. Upload Files
Upload these files to your Space:
Required Files:
app.py- Main applicationllm_backend.py- LLM interfacesurvey_generator.py- Survey generationsurvey_translator.py- Translation moduledata_analyzer.py- Analysis moduleexport_utils.py- Export utilitiesrequirements.txt- DependenciesREADME.md- Space description
Optional Files:
.env.example- Configuration templateUSAGE_GUIDE.md- User guidetest_app.py- Testing script
3. Configure Environment Variables (Optional)
Default Configuration (Recommended for Quick Start):
No configuration needed! The app automatically uses HuggingFace Inference API with the built-in HF_TOKEN.
Optional: Use Premium Providers
For better performance, you can add these environment variables in Space Settings:
For OpenAI:
LLM_PROVIDER=openai
OPENAI_API_KEY=sk-your-key-here
For Anthropic:
LLM_PROVIDER=anthropic
ANTHROPIC_API_KEY=your-key-here
For Custom HuggingFace Model:
LLM_MODEL=mistralai/Mistral-7B-Instruct-v0.2
# LLM_PROVIDER defaults to huggingface
4. Space Will Auto-Deploy
- HuggingFace will automatically build and deploy
- Check the "Logs" tab for build status
- First build may take 2-3 minutes
5. Test Your Deployment
- Wait for "Running" status
- Open the Space URL
- Test survey generation
- Test translation
- Test analysis with example data
Using HuggingFace Inference API
The easiest option for deployment is to use HuggingFace's free Inference API:
Pros:
- No API key needed (uses HF_TOKEN automatically)
- Free tier available
- Easy setup
Cons:
- May have rate limits on free tier
- Slower than paid providers
- May queue during high usage
Configuration:
Just set LLM_PROVIDER=huggingface in your environment variables.
Using Other Providers
OpenAI (Recommended for Production)
Pros:
- Fast and reliable
- High quality outputs
- Good API documentation
Cons:
- Requires paid API key
- Usage costs
Cost Estimate:
- Survey generation: ~$0.01-0.05 per survey
- Translation: ~$0.01-0.03 per language
- Analysis: ~$0.05-0.15 per batch
Anthropic Claude
Pros:
- Excellent for nuanced text
- Strong reasoning capabilities
- Good safety features
Cons:
- Requires API key
- Usage costs
Cost Estimate: Similar to OpenAI pricing
Deploying Locally
For Development
# 1. Clone/download repository
git clone <your-repo-url>
cd ConversAI
# 2. Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Set environment variables
export LLM_PROVIDER="openai"
export OPENAI_API_KEY="your-key"
# 5. Run
python app.py
Access at http://localhost:7860
For Production (Self-Hosted)
Use Docker for production deployment:
Create Dockerfile:
FROM python:3.10-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY *.py .
COPY *.md .
ENV GRADIO_SERVER_NAME="0.0.0.0"
ENV GRADIO_SERVER_PORT=7860
EXPOSE 7860
CMD ["python", "app.py"]
Build and run:
docker build -t conversai .
docker run -p 7860:7860 \
-e LLM_PROVIDER=openai \
-e OPENAI_API_KEY=your-key \
conversai
Post-Deployment Checklist
- App loads without errors
- Can generate a survey
- Can translate a survey
- Can analyze sample data
- Downloads work correctly
- Error messages are clear
- All tabs are accessible
- Mobile view works (if public)
Monitoring and Maintenance
Check Usage
Monitor your LLM API usage:
- OpenAI: https://platform.openai.com/usage
- Anthropic: Check your console
- HuggingFace: Monitor rate limits
Update Dependencies
Regularly update to get security fixes:
pip install --upgrade gradio requests pandas
Backup
Regularly backup:
- Generated surveys
- Analysis results
- User feedback
- Configuration
Troubleshooting Deployment
Space Build Fails
Check:
requirements.txtis validREADME.mdhas correct frontmatter- No syntax errors in Python files
Space Runs But Errors
Check:
- Environment variables are set
- API keys are valid
- Provider quotas aren't exceeded
Slow Performance
Solutions:
- Upgrade to paid LLM tier
- Use faster models (e.g., GPT-4o-mini)
- Add caching for common requests
- Optimize prompts for shorter responses
Scaling Considerations
For Heavy Usage
- Use faster models: GPT-4o-mini instead of GPT-4
- Implement caching: Cache common survey patterns
- Add rate limiting: Prevent abuse
- Load balancing: Use multiple API keys
- Queue system: Handle concurrent requests
Cost Optimization
- Optimize prompts: Shorter prompts = lower costs
- Batch operations: Process multiple items together
- Use cheaper models: For simpler tasks
- Set token limits: Prevent runaway costs
- Monitor usage: Set up alerts
Security Best Practices
- Never commit API keys to version control
- Use environment variables for secrets
- Rotate keys regularly
- Set spending limits with providers
- Monitor for unusual activity
- Use private Spaces for sensitive research
Support and Resources
- HuggingFace Docs: https://huggingface.co/docs/hub/spaces
- Gradio Docs: https://gradio.app/docs
- OpenAI API: https://platform.openai.com/docs
- Anthropic API: https://docs.anthropic.com
Need help? Check the USAGE_GUIDE.md or open an issue!