Spaces:
Sleeping
Sleeping
A newer version of the Gradio SDK is available:
5.46.0
π Theorem Explanation Agent - Hugging Face Spaces
This is a Gradio web interface for generating educational videos that explain mathematical theorems and scientific concepts using AI.
π Features
- AI-Powered Video Generation: Uses Gemini 2.0 Flash to create educational content
- Automatic API Key Rotation: Supports multiple Gemini API keys with fallback mechanism
- Educational Focus: Specializes in mathematical and scientific explanations
- Interactive Interface: Clean, user-friendly Gradio interface
- Demo Mode: Works without API keys for demonstration purposes
π Setting Up API Keys on Hugging Face Spaces
Step 1: Get Your Gemini API Keys
- Go to Google AI Studio
- Create one or more API keys
- Copy the keys (they look like:
AIzaSyA...
)
Step 2: Configure Secrets on Hugging Face Spaces
- Go to your Space's Settings tab
- Click on Repository secrets
- Add the following secrets:
For Multiple API Keys (Recommended)
Name: GEMINI_API_KEY
Value: AIzaSyA...,AIzaSyB...,AIzaSyC...,AIzaSyD...
For Single API Key
Name: GEMINI_API_KEY
Value: AIzaSyA...
Optional: Text-to-Speech
Name: ELEVENLABS_API_KEY
Value: your_elevenlabs_api_key
Enable Full Mode
Name: DEMO_MODE
Value: false
Step 3: How the Fallback System Works
The app automatically handles multiple API keys:
- Comma-Separated Keys: When you provide multiple keys separated by commas, the system randomly selects one for each request
- Automatic Rotation: This helps avoid rate limits and distributes load
- Error Handling: If one key fails, the system continues working
- Usage Tracking: Each key selection is logged for monitoring
π Example Usage
Basic Topics
- "Velocity" - Physics concepts with examples
- "Pythagorean Theorem" - Mathematical proofs
- "Derivatives" - Calculus with geometric interpretation
Advanced Topics
- "Newton's Laws" - Physics with demonstrations
- "Chemical Bonding" - Chemistry with molecular examples
- "Probability" - Statistics with practical examples
π οΈ Configuration Options
Environment Variables
Variable | Description | Example |
---|---|---|
GEMINI_API_KEY |
Gemini API key(s) - supports comma-separated multiple keys | key1,key2,key3 |
ELEVENLABS_API_KEY |
Optional: ElevenLabs API key for TTS | your_elevenlabs_key |
DEMO_MODE |
Set to "false" to enable full functionality | false |
Video Generation Settings
- Max Scenes: 1-6 scenes per video (more scenes = longer videos, higher cost)
- Context: Optional additional requirements or focus areas
- Topic: Any mathematical or scientific concept
π‘ Tips for Best Results
- Use Clear Topics: "velocity in physics" works better than just "motion"
- Provide Context: Specify difficulty level, target audience, or focus areas
- Start Simple: Try basic concepts first, then move to advanced topics
- Multiple Keys: Use 3-4 API keys for better rate limit handling
π§ Troubleshooting
Common Issues
- "No API keys found": Check that
GEMINI_API_KEY
is set in Secrets - Rate limit errors: Add more API keys separated by commas
- Generation fails: Try simpler topics or shorter context
- Slow response: Normal for complex topics, progress bar shows status
Error Messages
- "Demo mode active": API keys not configured properly
- "Generation failed": Check topic validity and API key status
- "Rate limit exceeded": Add more API keys for rotation
π Cost Considerations
- Each scene costs approximately $0.001-0.01 in API calls
- Multiple API keys help distribute costs
- Demo mode is completely free but only simulates generation
- Monitor usage through Google Cloud Console
π Deployment Checklist
- Fork/clone the repository
- Set up Gemini API key(s) in Secrets
- Set
DEMO_MODE=false
if you want full functionality - Test with simple topics first
- Monitor API usage and costs
π Support
For issues with:
- API Keys: Check Google AI Studio documentation
- Rate Limits: Add more API keys or wait before retrying
- Video Generation: Verify topic is educational/mathematical
- Hugging Face: Check Spaces documentation
Note: This app is designed for educational content generation. The AI models work best with mathematical, scientific, and educational topics.