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


๐Ÿš€ Quick Install

pip install pragyan

โšก Quick Start

In Your Python Script

from pragyan import Pragyan

# Initialize with your API key
solver = Pragyan(api_key="your-gemini-api-key")

# Solve from LeetCode URL
result = solver.solve("https://leetcode.com/problems/two-sum/", language="python")
print(result.solution.code)

From Terminal

# Interactive mode (recommended)
pragyan interactive

# Quick solve from URL
pragyan solve "https://leetcode.com/problems/two-sum/" --video

Pragyan is a Python package that helps developers understand and solve Data Structures and Algorithms (DSA) problems. It leverages AI to analyze problems, generate optimized solutions, and create animated explanation videos.


Table of Contents


Features

Feature Description
Multi-Platform Scraping Extract problems from LeetCode, GeeksforGeeks, Codeforces, HackerRank
AI-Powered Analysis Identify patterns, data structures, and optimal approaches
Multi-Language Solutions Generate code in 11+ programming languages
Video Explanations Animated visualizations using Manim
Step-by-Step Breakdown Detailed algorithm walkthroughs
Test Case Generation Auto-generate test cases for validation
Verbose Logging Real-time progress updates during execution

Architecture

System Overview

+------------------------------------------------------------------+
|                         PRAGYAN SYSTEM                            |
+------------------------------------------------------------------+
|                                                                   |
|  +-------------+     +-------------+     +------------------+     |
|  |   INPUT     |     |   CORE      |     |    OUTPUT        |     |
|  +-------------+     +-------------+     +------------------+     |
|  | - URL       |     | - Scraper   |     | - Solution Code  |     |
|  | - Text      |---->| - Analyzer  |---->| - Explanation    |     |
|  | - API Key   |     | - Solver    |     | - Video (MP4)    |     |
|  +-------------+     | - Generator |     | - Test Cases     |     |
|                      +-------------+     +------------------+     |
|                                                                   |
+------------------------------------------------------------------+

Component Architecture

pragyan/
|
+-- cli.py              Command Line Interface (Click + Rich)
|      |
|      +-- Interactive prompts
|      +-- Progress logging
|      +-- Result display
|
+-- main.py             Orchestration Layer
|      |
|      +-- Pragyan class (main entry point)
|      +-- Component coordination
|      +-- Pipeline management
|
+-- scraper.py          Web Scraping Module
|      |
|      +-- LeetCode adapter
|      +-- GFG adapter
|      +-- Generic HTML parser
|      +-- Selenium for dynamic content
|
+-- llm_client.py       AI Integration Layer
|      |
|      +-- Gemini client (Google AI)
|      +-- Groq client (open models)
|      +-- Response parsing
|      +-- Error handling
|
+-- solver.py           Solution Generation
|      |
|      +-- Problem analysis
|      +-- Code generation
|      +-- Complexity analysis
|      +-- Test case creation
|
+-- video_generator.py  Video Creation Module
|      |
|      +-- Manim scene generation
|      +-- Animation templates
|      +-- Rendering pipeline
|
+-- models.py           Data Models (Pydantic)
|      |
|      +-- Question, Solution
|      +-- VideoConfig, LLMConfig
|      +-- ProgrammingLanguage enum
|
+-- logger.py           Logging System
       |
       +-- Rich console output
       +-- Progress tracking
       +-- User engagement

Processing Pipeline

+--------+    +----------+    +----------+    +--------+    +-------+
| INPUT  |--->| SCRAPE   |--->| ANALYZE  |--->| SOLVE  |--->| VIDEO |
+--------+    +----------+    +----------+    +--------+    +-------+
    |              |               |              |             |
    v              v               v              v             v
  URL or       Question        Analysis       Solution      MP4 File
  Text         Object          Dict           Object        
                 |               |              |
                 v               v              v
            - Title         - Topics       - Code
            - Description   - Concept      - Explanation
            - Examples      - Approach     - Complexity
            - Constraints   - Edge Cases   - Steps

Data Flow Diagram

                    +------------------+
                    |    User Input    |
                    | (URL/Text/API)   |
                    +--------+---------+
                             |
                             v
                    +------------------+
                    |  QuestionScraper |
                    |  - Fetch HTML    |
                    |  - Parse content |
                    |  - Extract data  |
                    +--------+---------+
                             |
                             v
                    +------------------+
                    |   LLM Client     |
                    |  - Gemini API    |
                    |  - Groq API      |
                    +--------+---------+
                             |
              +--------------+--------------+
              |                             |
              v                             v
     +----------------+            +----------------+
     |   Analyzer     |            |    Solver      |
     | - Identify     |            | - Generate     |
     |   patterns     |            |   code         |
     | - Find concept |            | - Explain      |
     | - Edge cases   |            |   steps        |
     +-------+--------+            +-------+--------+
              |                             |
              +-------------+---------------+
                            |
                            v
                   +------------------+
                   | Video Generator  |
                   | - Build scenes   |
                   | - Render Manim   |
                   | - Export MP4     |
                   +--------+---------+
                            |
                            v
                   +------------------+
                   |     Output       |
                   | - Code + Explain |
                   | - Video file     |
                   +------------------+

Installation

Basic Installation

pip install pragyan

Video Generation Dependencies

For video generation with Manim:

Windows:

pip install manim
choco install ffmpeg

macOS:

pip install manim
brew install ffmpeg

Linux (Ubuntu/Debian):

pip install manim
sudo apt-get install ffmpeg

Verify Installation

pragyan version

Quick Start

Interactive Mode (Recommended)

pragyan interactive

This launches a guided session that:

  1. Prompts for problem URL or text
  2. Selects programming language
  3. Configures API provider
  4. Displays real-time progress
  5. Generates solution and video

Command Line

# Solve from URL
pragyan solve -u https://leetcode.com/problems/two-sum -p gemini -k YOUR_API_KEY

# Solve from text
pragyan solve -t "Find two numbers that add up to target" -l python -p gemini -k KEY

# Analyze only (no solution)
pragyan analyze https://leetcode.com/problems/two-sum -p gemini -k KEY

CLI Reference

Command Description
pragyan interactive Interactive mode with prompts
pragyan solve Solve a problem
pragyan analyze Analyze without solving
pragyan languages List supported languages
pragyan version Show version

Solve Options

Option Short Description
--url -u Problem URL
--text -t Problem text
--language -l Programming language
--provider -p AI provider (gemini/groq)
--api-key -k API key
--no-video Skip video generation
--output-dir -o Video output directory
--quality -q Video quality (low/medium/high)

Python API

Basic Usage

from pragyan import Pragyan

# Initialize
pragyan = Pragyan(
    provider="gemini",
    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"].time_complexity)
print(f"Video: {result['video_path']}")

Advanced 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
)

# Step-by-step control
question = pragyan.scrape_question("https://leetcode.com/problems/binary-search")
analysis = pragyan.analyze(question)
solution = pragyan.solve(question, ProgrammingLanguage.JAVA, analysis)
video_path = pragyan.generate_video(question, solution, analysis)

# Print details
print(f"Title: {question.title}")
print(f"Topics: {analysis['topics']}")
print(f"Concept: {analysis['main_concept']}")
print(f"Approach: {solution.approach}")
print(f"Time: {solution.time_complexity}")
print(f"Space: {solution.space_complexity}")

Class Reference

Pragyan

Method Description Returns
scrape_question(url) Fetch problem from URL Question
parse_question(text) Parse problem from text Question
analyze(question) Analyze problem Dict
solve(question, lang, analysis) Generate solution Solution
generate_video(question, solution, analysis) Create video Path
process(input, lang, video) Complete pipeline Dict
generate_test_cases(question, n) Generate test cases List

Configuration

Environment Variables

export PRAGYAN_API_KEY="your_api_key"

API Keys

Google Gemini (Recommended):

  1. Visit Google AI Studio
  2. Create API key
  3. Use with provider="gemini"

Groq:

  1. Visit Groq Console
  2. Create API key
  3. Use with provider="groq"

VideoConfig Options

Parameter Type Default Description
output_dir Path ~/Downloads Video output directory
video_quality str medium_quality low/medium/high_quality
fps int 30 Frames per second
pixel_width int 1920 Video width
pixel_height int 1080 Video height
background_color str #1e1e1e Background hex color

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

Video Structure

  1. Introduction - Problem title and topics
  2. Problem Overview - Description and key points
  3. Concept Explanation - Core algorithm/technique
  4. Step-by-Step Approach - Algorithm walkthrough
  5. Code Display - Syntax-highlighted solution
  6. Example Walkthrough - Trace through example
  7. Complexity Analysis - Time and space complexity
  8. Summary - Key takeaways

Quality Settings

Quality Resolution Render Time
low 480p Fast
medium 720p Moderate
high 1080p Slow

Examples

Two Sum Problem

from pragyan import Pragyan

pragyan = Pragyan(provider="gemini", api_key="KEY")
result = pragyan.process("https://leetcode.com/problems/two-sum")

print(result["solution"].code)
# 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 []

Custom Problem Text

from pragyan import Pragyan

pragyan = Pragyan(provider="groq", api_key="KEY")

problem = """
Given an array of integers, find the maximum subarray sum.

Example:
Input: [-2, 1, -3, 4, -1, 2, 1, -5, 4]
Output: 6 (subarray [4, -1, 2, 1])

Constraints:
- 1 <= length <= 10^5
- -10^4 <= array[i] <= 10^4
"""

question = pragyan.parse_question(problem)
solution = pragyan.solve(question, "cpp")
print(solution.code)

Multiple Languages

from pragyan import Pragyan, ProgrammingLanguage

pragyan = Pragyan(provider="gemini", api_key="KEY")
question = pragyan.scrape_question("https://leetcode.com/problems/binary-search")
analysis = pragyan.analyze(question)

for lang in [ProgrammingLanguage.PYTHON, ProgrammingLanguage.JAVA, ProgrammingLanguage.CPP]:
    solution = pragyan.solve(question, lang, analysis)
    print(f"\n--- {lang.value} ---")
    print(solution.code)

Troubleshooting

Common Issues

API Key Error:

Error: Invalid API key

Solution: Verify your API key is correct and active.

Video Generation Fails:

Error: Manim not found

Solution: Install Manim and FFmpeg:

pip install manim
# Windows: choco install ffmpeg
# macOS: brew install ffmpeg
# Linux: sudo apt install ffmpeg

Scraping Fails:

Error: Could not fetch URL

Solution: Some sites require Selenium. Install Chrome/ChromeDriver:

pip install selenium webdriver-manager

Project Structure

pragyan/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ pragyan/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ main.py
โ”‚       โ”œโ”€โ”€ cli.py
โ”‚       โ”œโ”€โ”€ models.py
โ”‚       โ”œโ”€โ”€ llm_client.py
โ”‚       โ”œโ”€โ”€ scraper.py
โ”‚       โ”œโ”€โ”€ solver.py
โ”‚       โ”œโ”€โ”€ video_generator.py
โ”‚       โ”œโ”€โ”€ animations.py
โ”‚       โ”œโ”€โ”€ logger.py
โ”‚       โ””โ”€โ”€ utils.py
โ”œโ”€โ”€ tests/
โ”œโ”€โ”€ examples/
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ LICENSE

Contributing

Contributions are welcome. Please submit a Pull Request.

  1. Fork the repository
  2. Create a feature branch
  3. Make changes
  4. Submit PR

License

MIT License - see LICENSE file.


Links


Built 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.1.2.tar.gz (72.5 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.1.2-py3-none-any.whl (65.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pragyan-1.1.2.tar.gz
Algorithm Hash digest
SHA256 f9a6c22f3bbcf867f9f678b1e2bbb8c10eea21752142bae53d25299bd4f360ee
MD5 0b67a3faf1a0e8670612f246158bc2de
BLAKE2b-256 7ae384d9d63fdaa5137a67949c040d94295a544c7c53efb9e20616629da8f4ab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pragyan-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 65.4 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.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 825c86fd95b43bd5ac0a95e8f4328eebcd8bc9e5ba548b5cb2f0c4d048f20422
MD5 78f04cdf7f83eee0a12385173a698677
BLAKE2b-256 90534c5f6cd323eae3df32fe8afbf20d0adf784bb7bc743584e3afc5d8e1d7a8

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