Skip to content

SlideSpeak/pdf-to-slides-ai-generator-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI PDF to Slide Generator

A scalable Python backend service that automatically generates slides from PDF documents or structured JSON data using AI.

architecture-pdf-ai-slides-tool

πŸš€ Features

  • FastAPI built with FastAPI for presentation generation
  • PDF Text Extraction to analyze uploaded documents
  • AI-Powered Content Generation using OpenAI to create slides from PDFs
  • Asynchronous Processing with Celery for improved scalability
  • Multiple Slide Types including title slides, content, bullet points, two-column, and image layouts
  • Task Tracking to monitor the status of your presentation generation
  • Containerized with Docker and Docker Compose for easy deployment

πŸ“‹ Requirements

  • Python 3.12+
  • Redis (for Celery message broker)
  • Docker and Docker Compose (for containerized deployment)
  • OpenAI API key (for AI-powered content generation)

πŸ› οΈ Installation

Using Docker (Recommended)

  1. Clone the repository:

    git clone https://github.com/yourusername/ai-presentation-generator.git
    cd ai-presentation-generator
  2. Create a .env file with your OpenAI API key:

    APP_NAME=Presentation Generator
    REDIS_URL=redis://redis:6379/0
    RESULT_BACKEND=redis://redis:6379/0
    STORAGE_PATH=/app/storage
    OPENAI_API_KEY=your_openai_api_key_here
    
  3. Build and run the containers:

    docker-compose up --build

The service will be available at http://localhost:8000.

Manual Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/ai-presentation-generator.git
    cd ai-presentation-generator
  2. Create a virtual environment and install dependencies:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    pip install -r requirements.txt
  3. Set up your environment variables (create a .env file):

    APP_NAME=Presentation Generator
    REDIS_URL=redis://localhost:6379/0
    RESULT_BACKEND=redis://localhost:6379/0
    STORAGE_PATH=./storage
    OPENAI_API_KEY=your_openai_api_key_here
    
  4. Make sure Redis is running locally or update the configuration in app/config.py.

  5. Run the FastAPI application:

    uvicorn app.main:app --reload
  6. In a separate terminal, start the Celery worker:

    celery -A celery_app worker --loglevel=info

πŸ“Š API Usage

Generate a Presentation from Structured Data

curl -X POST http://localhost:8000/api/presentations \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Quarterly Report",
    "author": "Your Team",
    "slides": [
      {
        "type": "title",
        "title": "Q2 Performance Review",
        "content": "Finance Department"
      },
      {
        "type": "bullet_points",
        "title": "Key Achievements",
        "bullet_points": [
          "Revenue increased by 15%",
          "New client acquisition up 22%",
          "Operational costs reduced by 8%"
        ]
      }
    ]
  }'

Response:

{
  "task_id": "b8f5e56a-915b-4c44-a784-2f86c1f0e3e9",
  "status": "pending"
}

Generate a Presentation from PDF

curl -X POST http://localhost:8000/api/presentations/from-pdf \
  -F "pdf_file=@/path/to/your/document.pdf" \
  -F "title=AI Generated Presentation" \
  -F "author=Your Name" \
  -F "num_slides=7"

Response:

{
  "task_id": "c7e4f45b-826a-4b33-a991-4f75d2f7e4a8",
  "status": "pending"
}

Check Presentation Status

curl http://localhost:8000/api/presentations/{task_id}

Response:

{
  "task_id": "c7e4f45b-826a-4b33-a991-4f75d2f7e4a8",
  "status": "completed",
  "file_url": "/download/f6e8d971-3841-4b2a-9e39-3e5fc3c8340b.pptx",
  "message": "Presentation generated successfully"
}

Download the Presentation

curl -O http://localhost:8000/api/download/{file_id}

🧩 Supported Slide Types

Type Description
title Title slide with subtitle
content Standard content slide with title and body text
bullet_points Slide with title and bulleted points
two_column Two-column layout for comparing content
image Image slide with a title

πŸ“‚ Project Structure

presentation_generator/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ main.py              # FastAPI application
β”‚   β”œβ”€β”€ models.py            # Pydantic models
β”‚   β”œβ”€β”€ config.py            # Configuration
β”‚   β”œβ”€β”€ ppt_generator.py     # PowerPoint generation logic
β”‚   └── pdf_processor.py     # PDF processing and OpenAI integration
β”œβ”€β”€ celery_app/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ tasks.py             # Celery tasks
β”‚   └── celery_config.py     # Celery configuration
β”œβ”€β”€ requirements.txt
└── docker-compose.yml

πŸ”§ Configuration

Configuration is managed through environment variables and defaults:

Variable Default Description
APP_NAME "Presentation Generator" Application name
REDIS_URL "redis://redis:6379/0" Redis URL for Celery broker
RESULT_BACKEND "redis://redis:6379/0" Result backend for Celery
STORAGE_PATH "/app/storage" Path for storing generated presentations
OPENAI_API_KEY "" Your OpenAI API key

How It Works

PDF Processing Workflow

  1. Upload PDF: User uploads a PDF file via the API
  2. Text Extraction: System extracts text content using PyPDF2
  3. AI Analysis: OpenAI processes the text and identifies key points
  4. Content Generation: AI generates slide content based on the analysis
  5. Presentation Creation: System creates PowerPoint slides using python-pptx
  6. Notification: User can check task status and download the presentation

πŸ›£οΈ Roadmap

  • Add authentication for API endpoints
  • Support for custom PowerPoint templates
  • Chart generation from data in PDFs
  • Image extraction and inclusion from PDFs
  • Web interface for easier usage
  • Cloud storage integration (S3, GCS)
  • Support for more file formats (Word, HTML, Markdown)

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“š Documentation

For more detailed documentation, see the API Documentation when the service is running.

Releases

No releases published

Packages

No packages published