AI-powered DSA question solver with video explanations using Manim animations
Project description
Pragyan 🚀
AI-Powered DSA Question Solver with Video Explanations
Pragyan is a powerful Python package that helps you understand and solve Data Structures and Algorithms (DSA) problems. It can:
- 📝 Scrape problems from LeetCode, GeeksforGeeks, and other platforms
- 🤖 Analyze and generate solutions using AI (Gemini or Groq)
- 💻 Generate code in 11+ programming languages
- 🎥 Create animated explanation videos using Manim
- 📚 Provide step-by-step explanations with examples
Features
- Multi-Platform Support: Scrape problems from LeetCode, GeeksforGeeks, Codeforces, HackerRank, and more
- AI-Powered Solutions: Uses Google Gemini or Groq (free tier) for intelligent solution generation
- Multiple Languages: Generate solutions in Python, Java, C++, JavaScript, Go, Rust, and more
- Video Explanations: Automatic video generation with Manim animations
- Concept Explanations: Learn the underlying concepts and approaches
- Test Cases: Auto-generate test cases for validation
Installation
pip install pragyan
Additional Requirements
For video generation, you'll need to install Manim dependencies:
Windows:
# Install Manim
pip install manim
# Install additional dependencies (FFmpeg, etc.)
choco install ffmpeg
macOS:
pip install manim
brew install ffmpeg
Linux:
pip install manim
sudo apt-get install ffmpeg
Quick Start
Command Line Interface
# Interactive mode (recommended for first-time users)
pragyan interactive
# Solve from URL
pragyan solve -u https://leetcode.com/problems/two-sum -p gemini -k YOUR_API_KEY
# Solve from text
pragyan solve -t "Given an array of integers, find two numbers that add up to a target" -l python
# Analyze a problem without solving
pragyan analyze https://leetcode.com/problems/two-sum -p gemini -k YOUR_KEY
# List supported languages
pragyan languages
Python API
from pragyan import Pragyan
# Initialize with your API key
pragyan = Pragyan(
provider="gemini", # or "groq"
api_key="YOUR_API_KEY"
)
# Solve from URL
result = pragyan.process(
"https://leetcode.com/problems/two-sum",
language="python",
generate_video=True
)
# Access results
print(result["solution"].code)
print(result["solution"].explanation)
print(f"Video saved to: {result['video_path']}")
Detailed Usage
from pragyan import Pragyan, ProgrammingLanguage, VideoConfig
# Custom configuration
video_config = VideoConfig(
output_dir="./videos",
video_quality="high_quality",
resolution="1080p"
)
pragyan = Pragyan(
provider="gemini",
api_key="YOUR_API_KEY",
video_config=video_config
)
# Scrape a question
question = pragyan.scrape_question("https://leetcode.com/problems/binary-search")
# Analyze the question
analysis = pragyan.analyze(question)
print(f"Topics: {analysis['topics']}")
print(f"Concept: {analysis['main_concept']}")
# Generate solution
solution = pragyan.solve(question, ProgrammingLanguage.JAVA, analysis)
# Print solution details
print(f"Code:\n{solution.code}")
print(f"\nApproach: {solution.approach}")
print(f"Time Complexity: {solution.time_complexity}")
print(f"Space Complexity: {solution.space_complexity}")
# Generate explanation video
video_path = pragyan.generate_video(question, solution, analysis)
print(f"Video saved to: {video_path}")
# Generate test cases
test_cases = pragyan.generate_test_cases(question)
for tc in test_cases:
print(f"Input: {tc['input']}, Expected: {tc['expected_output']}")
API Keys
Pragyan supports two AI providers (both have free tiers):
Google Gemini (Recommended)
- Go to Google AI Studio
- Create a new API key
- Use with
provider="gemini"
Groq
- Go to Groq Console
- Create a new API key
- Use with
provider="groq"
You can also set the API key as an environment variable:
export PRAGYAN_API_KEY="your_api_key_here"
Supported Languages
| Language | Aliases |
|---|---|
| Python | python, py |
| Java | java |
| C++ | cpp, c++ |
| C | c |
| JavaScript | javascript, js |
| TypeScript | typescript, ts |
| Go | go, golang |
| Rust | rust, rs |
| Kotlin | kotlin, kt |
| Swift | swift |
| C# | csharp, c#, cs |
Video Generation
The package uses Manim (Community Edition) to generate animated explanation videos. Videos include:
- Introduction: Problem title and topics
- Problem Overview: Description and key points
- Concept Explanation: Main algorithm/technique used
- Step-by-Step Approach: Detailed walkthrough
- Code Walkthrough: Syntax-highlighted code with explanations
- Example Walkthrough: Working through an example
- Complexity Analysis: Time and space complexity
- Summary: Key takeaways
Video Quality Options
low_quality: 480p, faster renderingmedium_quality: 720p, balancedhigh_quality: 1080p, best quality
Project Structure
pragyan/
├── src/
│ └── pragyan/
│ ├── __init__.py # Package entry point
│ ├── main.py # Main orchestration
│ ├── cli.py # Command-line interface
│ ├── models.py # Data models
│ ├── llm_client.py # AI integrations
│ ├── scraper.py # Web scraping
│ ├── solver.py # Solution generation
│ └── video_generator.py # Video creation
├── pyproject.toml # Package configuration
└── README.md # This file
Examples
Example 1: Two Sum Problem
from pragyan import Pragyan
pragyan = Pragyan(provider="gemini", api_key="YOUR_KEY")
result = pragyan.process(
"https://leetcode.com/problems/two-sum",
language="python"
)
print(result["solution"].code)
# Output:
# def twoSum(nums, target):
# seen = {}
# for i, num in enumerate(nums):
# complement = target - num
# if complement in seen:
# return [seen[complement], i]
# seen[num] = i
# return []
Example 2: Custom Problem Text
from pragyan import Pragyan
pragyan = Pragyan(provider="groq", api_key="YOUR_KEY")
problem_text = """
Given an array of integers, find the maximum subarray sum.
Example:
Input: [-2, 1, -3, 4, -1, 2, 1, -5, 4]
Output: 6
Explanation: The subarray [4, -1, 2, 1] has the maximum sum 6.
Constraints:
- 1 <= array length <= 10^5
- -10^4 <= array[i] <= 10^4
"""
question = pragyan.parse_question(problem_text)
solution = pragyan.solve(question, "cpp")
print(solution.code)
Example 3: Compare Approaches
from pragyan import Pragyan
pragyan = Pragyan(provider="gemini", api_key="YOUR_KEY")
question = pragyan.scrape_question("https://leetcode.com/problems/longest-substring-without-repeating-characters")
comparison = pragyan.compare_approaches(question)
for approach in comparison["approaches"]:
print(f"\n{approach['name']}")
print(f" Time: {approach['time_complexity']}")
print(f" Space: {approach['space_complexity']}")
print(f" Description: {approach['description']}")
print(f"\nRecommended: {comparison['recommended']}")
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Manim Community for the animation library
- Google Gemini and Groq for AI capabilities
- LangChain for web scraping utilities
Made with ❤️ by Kamal
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pragyan-1.0.2.tar.gz.
File metadata
- Download URL: pragyan-1.0.2.tar.gz
- Upload date:
- Size: 41.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a9a702bd13f0a9a744147cd833c75e454d4f2e06e6083a5833b876eb387cf15
|
|
| MD5 |
4cd6206b747a7cc484a9251c17e922c5
|
|
| BLAKE2b-256 |
ae6aadf277425ca821afe8bb8e3ae2d5537ac6d1c8597773ed394393985660ad
|
File details
Details for the file pragyan-1.0.2-py3-none-any.whl.
File metadata
- Download URL: pragyan-1.0.2-py3-none-any.whl
- Upload date:
- Size: 37.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ca679c8ca129b7773511619cecfc56dfe15791fad243af3dc3400bf1f821566
|
|
| MD5 |
368bf631aff342808b1f8cab3a951015
|
|
| BLAKE2b-256 |
239712a1114d0780c8ea509d0a4c774f3c583ed8706533ac11796fcd3ca543ca
|