Skip to main content

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)

  1. Go to Google AI Studio
  2. Create a new API key
  3. Use with provider="gemini"

Groq

  1. Go to Groq Console
  2. Create a new API key
  3. 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:

  1. Introduction: Problem title and topics
  2. Problem Overview: Description and key points
  3. Concept Explanation: Main algorithm/technique used
  4. Step-by-Step Approach: Detailed walkthrough
  5. Code Walkthrough: Syntax-highlighted code with explanations
  6. Example Walkthrough: Working through an example
  7. Complexity Analysis: Time and space complexity
  8. Summary: Key takeaways

Video Quality Options

  • low_quality: 480p, faster rendering
  • medium_quality: 720p, balanced
  • high_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pragyan-1.0.0.tar.gz (40.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pragyan-1.0.0-py3-none-any.whl (36.7 kB view details)

Uploaded Python 3

File details

Details for the file pragyan-1.0.0.tar.gz.

File metadata

  • Download URL: pragyan-1.0.0.tar.gz
  • Upload date:
  • Size: 40.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for pragyan-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4cc30eaaa41df86641e06817d30ecee9512301bc091bb93b79e1dc8ddb24cea8
MD5 0afae9320194fe9dc69b7174a9c9dd11
BLAKE2b-256 5a1e37418ad3ac7d14a695a9bfced9b52bbf15678f6161b0a975f8e4a7c2f890

See more details on using hashes here.

File details

Details for the file pragyan-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pragyan-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 36.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for pragyan-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 88a4b94ac038c8359e733e81118076a02865e2d664c9b7228bc810cba309ed4c
MD5 e7eeddc0004f8dbebe74948b18a6687e
BLAKE2b-256 33c563fbe4dd771cf3a108dac92945189c737233c58bf272adace0a13d6d1fc2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page