Skip to content

Thayaa21/Citation_aware

Repository files navigation

πŸ“š Knowledge Document Creation System

A comprehensive AI-powered system for extracting, analyzing, and synthesizing knowledge from PDF documents using Ollama's local AI models.

🌟 Features

  • πŸ“„ PDF Processing: Extract text, tables, and images from PDF documents
  • πŸ€– AI-Powered Analysis: Uses Ollama with Llama 3.1 for intelligent content analysis
  • πŸ“Š Table Extraction: Automatically detects and extracts tables from PDFs
  • 🎨 Flowchart Analysis: Analyzes flowcharts and diagrams using AI vision capabilities
  • πŸ”— Citation Mapping: Maps citations to reference documents
  • πŸ” Similarity Search: Finds relevant content across documents using FAISS
  • πŸ“ Knowledge Synthesis: Creates comprehensive knowledge documents
  • πŸ’» Streamlit Interface: User-friendly web interface for document processing

πŸš€ Quick Start

Prerequisites

  • Python 3.8 or higher
  • Ollama installed locally
  • Git

Installation

  1. Clone the repository

    git clone <repository-url>
    cd knowledge-document-creation
  2. Create and activate virtual environment

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Download NLTK data

    python -c "import nltk; nltk.download('punkt_tab'); nltk.download('punkt'); nltk.download('averaged_perceptron_tagger'); nltk.download('stopwords')"
  5. Setup Ollama

    # Install Ollama from https://ollama.ai/
    ollama serve
    ollama pull llama3.1:8b
  6. Run the application

    streamlit run main.py
  7. Open your browser to http://localhost:8501

πŸ“– Usage

Basic Workflow

  1. Upload Main PDF: Upload the primary document you want to analyze
  2. Upload Reference PDFs: Upload reference documents for comparison and citation mapping
  3. Generate Knowledge Document: Click "Generate" to process all documents
  4. View Results: Review the generated knowledge document with statistics and organized content
  5. Download: Download the document in Word or text format

Document Processing Pipeline

PDF Input β†’ Text Extraction β†’ Table Detection β†’ Flowchart Analysis β†’ AI Processing β†’ Knowledge Synthesis β†’ Output

πŸ—οΈ Project Structure

knowledge-document-creation/
β”œβ”€β”€ main.py                          # Main Streamlit application
β”œβ”€β”€ requirements.txt                 # Python dependencies
β”œβ”€β”€ setup_environment.py            # Environment setup script
β”œβ”€β”€ .gitignore                      # Git ignore file
β”œβ”€β”€ README.md                       # This file
β”œβ”€β”€ Paragraph_extraction_from_pdf.py # Text extraction module
β”œβ”€β”€ Table_to_text/                  # Table extraction module
β”‚   └── Detect_table_redact.py
β”œβ”€β”€ Flowchart_to_text/              # Flowchart analysis module
β”‚   β”œβ”€β”€ flowchart_to_text.py
β”‚   └── Detect_flowchart_redact.py
└── csv/                           # Generated CSV files (ignored by git)

πŸ”§ Configuration

Environment Variables

The application uses the following environment variables:

  • LLM_PROVIDER=ollama
  • OLLAMA_MODEL=llama3.1:8b

These are automatically set by the setup script.

Ollama Models

The system is configured to use llama3.1:8b by default. You can use other models by:

  1. Pulling the desired model: ollama pull <model-name>
  2. Setting the environment variable: export OLLAMA_MODEL=<model-name>

πŸ“Š Features in Detail

Text Extraction

  • Extracts text from PDFs using multiple libraries (PyMuPDF, pdfplumber)
  • Handles various PDF formats and layouts
  • Preserves text structure and formatting

Table Detection

  • Automatically identifies tables in PDF documents
  • Extracts table content to Excel format
  • Maps table references in the main document

Flowchart Analysis

  • Extracts images and diagrams from PDFs
  • Uses Ollama's vision capabilities to analyze flowcharts
  • Generates textual descriptions of visual content

Citation Mapping

  • Identifies citation patterns in academic documents
  • Maps citations to corresponding reference documents
  • Performs similarity search to find relevant content

Knowledge Synthesis

  • Combines extracted content from all sources
  • Creates organized knowledge documents
  • Provides download options in multiple formats

πŸ› οΈ Development

Adding New Features

  1. New Document Types: Extend the extraction modules in Table_to_text/ or Flowchart_to_text/
  2. AI Models: Modify the Ollama integration in flowchart_to_text.py
  3. UI Components: Add new Streamlit components in main.py

Testing

# Test imports
python -c "from main import *; print('βœ… All imports successful')"

# Test specific modules
python -c "from Paragraph_extraction_from_pdf import create_csv; print('βœ… Text extraction works')"

πŸ› Troubleshooting

Common Issues

  1. Ollama Connection Error

    # Check if Ollama is running
    ollama list
    # Start Ollama service
    ollama serve
  2. NLTK Data Missing

    python -c "import nltk; nltk.download('punkt_tab')"
  3. PyMuPDF Import Error

    pip uninstall PyMuPDF
    pip install pymupdf
  4. Permission Errors

    • Ensure write permissions in the project directory
    • Check if antivirus software is blocking file operations

Getting Help

  • Check the Issues page
  • Review the troubleshooting section above
  • Ensure all dependencies are properly installed

πŸ“ License

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

🀝 Contributing

  1. Fork the repository
  2. Create a 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

πŸ™ Acknowledgments

πŸ“ž Support

For support, email your-email@example.com or create an issue in the repository.


Made with ❀️ for knowledge discovery and document analysis

About

No description, website, or topics provided.

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages