A newer version of the Gradio SDK is available:
6.1.0
Setup Guide for Lineage Graph Extractor Space
This guide will help you deploy the Lineage Graph Extractor as a Hugging Face Space.
Prerequisites
- A Hugging Face account (create one at https://huggingface.co/join)
- API credentials for the services you want to integrate:
- Anthropic API key (for Claude AI)
- Google Cloud credentials (for BigQuery, optional)
- Other service credentials as needed
Step 1: Create a New Space
- Go to https://huggingface.co/spaces
- Click "Create new Space"
- Fill in the details:
- Name:
lineage-graph-extractor(or your preferred name) - License: MIT (or your choice)
- SDK: Gradio
- Hardware: CPU Basic (free tier) or upgrade for better performance
- Visibility: Public or Private (your choice)
- Name:
Step 2: Upload Files
You need to upload these files to your Space repository:
Required Files
app.py- Main application filerequirements.txt- Python dependenciesREADME.md- Space description and documentation
Optional Files
.env.example- Example environment variablesSETUP_GUIDE.md- This setup guide
Upload Methods
Option A: Web Interface
- Click "Files and versions" in your Space
- Click "Add file" → "Upload files"
- Upload all the files from
/hf_space/directory
Option B: Git
# Clone your Space repository
git clone https://huggingface.co/spaces/YOUR_USERNAME/lineage-graph-extractor
cd lineage-graph-extractor
# Copy files
cp /path/to/hf_space/* .
# Commit and push
git add .
git commit -m "Initial commit: Lineage Graph Extractor"
git push
Step 3: Configure Secrets
For security, store sensitive credentials as Space secrets:
- Go to your Space settings
- Click "Repository secrets"
- Add the following secrets:
Required Secrets
ANTHROPIC_API_KEY: Your Claude API key from https://console.anthropic.com/
Optional Secrets (based on features you need)
GOOGLE_CLOUD_PROJECT: Your GCP project IDGOOGLE_APPLICATION_CREDENTIALS_JSON: Service account JSON (as a string)MCP_SERVER_URL: MCP server endpoint (if using MCP)MCP_API_KEY: MCP authentication key
Accessing Secrets in Code
Update app.py to read from environment variables:
import os
ANTHROPIC_API_KEY = os.environ.get("ANTHROPIC_API_KEY")
GOOGLE_CLOUD_PROJECT = os.environ.get("GOOGLE_CLOUD_PROJECT")
Step 4: Integrate the Agent Backend
The current app.py is a template. You need to connect it to your actual agent:
Option A: Use Anthropic SDK
import anthropic
client = anthropic.Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
def extract_lineage_from_text(metadata_text, source_type, viz_format):
# Call your agent with metadata_parser and graph_visualizer workers
response = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=4000,
messages=[{
"role": "user",
"content": f"Extract lineage from this {source_type} metadata and visualize as {viz_format}: {metadata_text}"
}]
)
return response.content[0].text, "Processed successfully"
Option B: Use Agent API Endpoint
If you have your agent deployed as an API:
import requests
def extract_lineage_from_text(metadata_text, source_type, viz_format):
response = requests.post(
"https://your-agent-api.com/extract",
json={
"metadata": metadata_text,
"source_type": source_type,
"format": viz_format
}
)
return response.json()["visualization"], response.json()["summary"]
Option C: Bundle Agent Files
Include your agent configuration directly in the Space:
- Copy
/memories/directory to Space - Copy
/subagents/if needed - Import and use agent logic in
app.py
Step 5: Test Your Space
- Once deployed, Hugging Face will automatically build and run your Space
- Check the "Logs" tab for any errors
- Test each feature:
- Text/File metadata extraction
- BigQuery integration (if configured)
- URL/API fetching
Step 6: Customize and Enhance
Add Authentication
For production use, add authentication:
demo.launch(auth=("username", "password"))
Or integrate with Hugging Face authentication:
demo.launch(auth_required=True)
Improve Error Handling
Add try-catch blocks and user-friendly error messages:
try:
result = extract_lineage_from_text(metadata_text, source_type, viz_format)
return result
except Exception as e:
return "", f"Error: {str(e)}"
Add More Features
- File upload support
- Export visualizations as images
- History/session management
- Batch processing
Troubleshooting
Space won't start
- Check logs for error messages
- Verify all dependencies in
requirements.txt - Ensure Python version compatibility
API errors
- Verify secrets are correctly set
- Check API key validity and permissions
- Review rate limits
Slow performance
- Upgrade to better hardware (CPU or GPU)
- Optimize metadata parsing logic
- Add caching for repeated queries
Security Best Practices
- Never commit API keys to the repository
- Use Space secrets for all credentials
- Validate user input to prevent injection attacks
- Use read-only credentials when possible
- Add rate limiting to prevent abuse
- Enable authentication for production use
Getting Help
- Hugging Face Spaces docs: https://huggingface.co/docs/hub/spaces
- Gradio documentation: https://gradio.app/docs
- Anthropic API docs: https://docs.anthropic.com/
Next Steps
- Test the Space thoroughly
- Share with your team or community
- Collect feedback and iterate
- Consider upgrading hardware for production workloads
- Add analytics to track usage
Need help? Check the Hugging Face community forums or reach out to support.