Spaces:
Running
A newer version of the Streamlit SDK is available:
1.44.1
Deployment Guide for Ontology-Enhanced RAG System
This guide will help you deploy the Ontology-Enhanced RAG demonstration to Hugging Face Spaces.
Prerequisites
- Hugging Face Account: You need a Hugging Face account.
- OpenAI API Key: You need a valid OpenAI API key.
Deployment Steps
1. Prepare Your Repository
Ensure your repository contains the following files and directories:
app.py
: Main Streamlit applicationsrc/
: Directory containing all source codedata/
: Directory containing the ontology JSON and other data.streamlit/
: Directory containing Streamlit configurationstatic/
: Directory containing CSS and other static assetsrequirements.txt
: List of all dependencieshuggingface.yml
: Hugging Face Space configuration
2. Set Up Hugging Face Space
Visit Hugging Face and log in
Click "New" → "Space" in the top right corner
Fill in the Space settings:
- Owner: Select your username or organization
- Space name: Choose a name for your demo, e.g., "ontology-rag-demo"
- License: Choose MIT or your preferred license
- SDK: Select Streamlit
- Space hardware: Choose according to your needs (minimum requirement: CPU + 4GB RAM)
Click "Create Space"
3. Configure Space Secrets
You need to add your OpenAI API key as a Secret:
- In your Space page, go to the "Settings" tab
- Scroll down to the "Repository secrets" section
- Click "New secret"
- Add the following secret:
- Name:
OPENAI_API_KEY
- Value: Your OpenAI API key
- Name:
- Click "Add secret"
4. Upload Your Code
There are two ways to upload your code:
Option A: Upload via Web Interface
- In your Space page, go to the "Files" tab
- Use the upload button to upload all necessary files and directories
- Ensure you maintain the correct directory structure
Option B: Upload via Git (Recommended)
Clone your Space repository:
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
Copy all your files into the cloned repository
Add, commit, and push the changes:
git add . git commit -m "Initial commit" git push
5. Verify Deployment
- Visit your Space URL (in the format
https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
) - Confirm that the application loads and runs correctly
- Test all features
Hardware Recommendations
For optimal performance, consider the following hardware configurations:
- Minimal: CPU + 4GB RAM (suitable for demos with limited users)
- Recommended: CPU + 16GB RAM (for better performance with knowledge graph visualizations)
Troubleshooting
If you encounter issues:
Application fails to start:
- Check if the Streamlit version is compatible
- Verify all dependencies are correctly installed
- Check the Space logs for error messages
OpenAI API errors:
- Confirm the API key is correctly set as a Secret
- Verify the API key is valid and has sufficient quota
Display issues:
- Try simplifying visualizations, as they might be memory-intensive
- Check logs for any warnings or errors
NetworkX or Visualization Issues:
- Ensure pygraphviz is properly installed
- For simpler deployment, you can modify the code to use alternative layout algorithms that don't depend on Graphviz
Deployment Optimizations
For production deployments, consider these optimizations:
Resource Management:
- Choose appropriate hardware (CPU+RAM) to meet your application's needs
- Consider optimizing large visualizations to reduce memory usage
Performance:
- Implement result caching for common queries
- Consider pre-computing common graph layouts
Security:
- Ensure no sensitive data is stored in the codebase
- Store all credentials using environment variables or Secrets
Memory Optimization Tips
If you encounter memory issues with large ontologies:
- Limit the maximum number of nodes in visualization
- Implement pagination for large result sets
- Use streaming responses for large text outputs
- Optimize NetworkX operations for large graphs