This backend service integrates Google's Gemini AI to analyze user onboarding data and generate personalized learning resources by scraping information across the internet.
- 🤖 Gemini AI Integration: Uses Google's Gemini API to analyze user profiles and generate search queries
- 🌐 Web Scraping: Intelligently searches for learning resources across the web
- 📚 Resource Categorization: Automatically categorizes resources based on user needs
- 🔥 Firebase Integration: Stores generated resources in Firestore
- 🚀 FastAPI: RESTful API endpoints for easy integration
- 📊 Personalized Learning: Tailored resources based on user's weak areas, target companies, and learning preferences
pip install -r requirements.txt- Visit Google AI Studio
- Create a new API key
- Set the environment variable:
# On Windows
set GEMINI_API_KEY=your_api_key_here
# On Linux/Mac
export GEMINI_API_KEY=your_api_key_hereOr create a .env file (copy from .env.example):
GEMINI_API_KEY=your_actual_api_key_here
Make sure your firebase-credentials.json file is properly configured with your Firebase service account credentials.
python main.pyThe server will start on http://localhost:8000
Generate personalized learning resources for a user:
By User ID:
POST /generate-resources/{user_id}By Email:
POST /generate-resources-by-email/{email}Retrieve generated resources for a user:
By User ID:
GET /home/{user_id}By Email:
GET /home-by-email/{email}- User Analysis: The Gemini agent analyzes the user's onboarding answers to create a learning profile
- Query Generation: Gemini generates targeted search queries based on:
- Weak areas to improve
- Target companies for interview prep
- Preferred technologies and roles
- Learning timeline and preferences
- Resource Discovery: The system searches for high-quality resources from:
- YouTube tutorials
- Technical blogs (Medium, Dev.to)
- GitHub repositories
- Coding practice platforms (LeetCode, HackerRank)
- Course platforms (Coursera, Udemy)
- Categorization: Resources are automatically categorized:
- 📈 Weak Areas Improvement
- 💼 Interview Preparation
- 🛠️ Skill Development
- 💻 Practice Problems
- 📖 Technology Tutorials
- 🎓 General Learning
- Storage: All resources are saved to Firebase under the
homecollection
{
"name": "User Name",
"status": "College Student",
"education": "B.Tech",
"graduation_year": "2027",
"primary_language": "Python",
"tech_stack": ["React", "Node.js", "FastAPI"],
"familiar_topics": ["Web Development"],
"weak_areas": ["DSA", "System Design"],
"target_companies": ["Google", "Microsoft"],
"preferred_role": "Software Developer",
"target_timeline": "6 months",
"preferred_resources": ["Video", "Interactive Coding"]
}{
"user_id": "user123",
"user_profile": { /* user profile data */ },
"search_queries": [
"DSA tutorial Python beginner",
"Google software engineer interview preparation",
"System design basics course"
],
"total_resources": 25,
"resources": {
"weak_areas_improvement": [
{
"title": "Data Structures and Algorithms in Python",
"url": "https://example.com/dsa-python",
"description": "Comprehensive DSA course for beginners",
"resource_type": "course",
"difficulty": "beginner",
"estimated_time": 120,
"tags": ["DSA", "Python", "Algorithms"]
}
],
"interview_preparation": [ /* ... */ ],
/* ... other categories ... */
},
"generated_at": "2025-10-31T00:04:08Z"
}Run the test script to verify the integration:
python test_gemini_integration.pyThis will:
- Store sample user answers
- Generate personalized resources
- Retrieve and display the results
GEMINI_API_KEY: Required for Gemini AI integrationHOST: Server host (default: 0.0.0.0)PORT: Server port (default: 8000)
users: User profiles and basic informationusers/{uid}/question_answers: User onboarding responseshome: Generated personalized resources for each user
The system includes comprehensive error handling:
- Fallback queries if Gemini API fails
- Graceful degradation for resource categorization
- Detailed error messages in API responses
The system includes built-in delays to respect API rate limits:
- 0.5 second delay between search queries
- Configurable batch sizes for resource generation
- Never commit API keys to version control
- Use environment variables or secure key management
- Restrict CORS origins in production
- Validate all user inputs
- Set up proper environment variables
- Configure CORS origins for your frontend
- Use a production WSGI server (gunicorn, uvicorn)
- Set up proper Firebase security rules
- Monitor API usage and costs