Skip to content

Commit 75cc74a

Browse files
committed
fix: replace PDFMinerLoader which has vulnerability with PyPDFLoader (#849)
1 parent 128abf4 commit 75cc74a

File tree

20 files changed

+1287
-18
lines changed

20 files changed

+1287
-18
lines changed

usecases/ai/edge-ai-demo-studio/workers/embedding/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies = [
3434
"langchainhub==0.1.21",
3535
# Document Processing
3636
"unstructured==0.18.3",
37-
"pdfminer.six==20251107",
37+
"pypdf>=6.3.0",
3838
# Database and Modeling
3939
"sqlmodel>=0.0.24",
4040
]

usecases/ai/edge-ai-demo-studio/workers/embedding/utils/rag_engine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from langchain_community.document_loaders import (
1616
CSVLoader,
1717
EverNoteLoader,
18-
PDFMinerLoader,
18+
PyPDFLoader,
1919
TextLoader,
2020
UnstructuredEPubLoader,
2121
UnstructuredHTMLLoader,
@@ -45,7 +45,7 @@
4545
".html": (UnstructuredHTMLLoader, {}),
4646
".md": (UnstructuredMarkdownLoader, {}),
4747
".odt": (UnstructuredODTLoader, {}),
48-
".pdf": (PDFMinerLoader, {}),
48+
".pdf": (PyPDFLoader, {}),
4949
".ppt": (UnstructuredPowerPointLoader, {}),
5050
".pptx": (UnstructuredPowerPointLoader, {}),
5151
".txt": (TextLoader, {"encoding": "utf8"}),

usecases/ai/edge-ai-demo-studio/workers/embedding/utils/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def validate_and_sanitize_cache_dir(cache_dir: str) -> str:
5151
"/tmp", # Temporary directory
5252
"/var/cache", # System cache directory
5353
"/opt", # Optional software directory
54+
"/mnt", # Mounted drives
5455
]
5556

5657
# Check if the resolved path is within allowed directories

usecases/ai/edge-ai-demo-studio/workers/embedding/uv.lock

Lines changed: 2 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

usecases/ai/edge-ai-demo-studio/workers/image-generation/utils/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def validate_and_sanitize_cache_dir(cache_dir: str) -> str:
5151
"/tmp", # Temporary directory
5252
"/var/cache", # System cache directory
5353
"/opt", # Optional software directory
54+
"/mnt", # Mounted drives
5455
]
5556

5657
# Check if the resolved path is within allowed directories

usecases/ai/edge-ai-demo-studio/workers/speech-to-text/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def validate_and_sanitize_cache_dir(cache_dir: str) -> str:
7070
"/tmp", # Temporary directory
7171
"/var/cache", # System cache directory
7272
"/opt", # Optional software directory
73+
"/mnt", # Mounted drives
7374
]
7475

7576
# Check if the resolved path is within allowed directories

usecases/ai/edge-ai-demo-studio/workers/text-generation/utils/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def validate_and_sanitize_cache_dir(cache_dir: str) -> str:
5151
"/tmp", # Temporary directory
5252
"/var/cache", # System cache directory
5353
"/opt", # Optional software directory
54+
"/mnt", # Mounted drives
5455
]
5556

5657
# Check if the resolved path is within allowed directories

usecases/ai/edge-ai-demo-studio/workers/text-to-speech/kokoro/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def validate_and_sanitize_cache_dir(cache_dir: str) -> str:
6868
"/tmp", # Temporary directory
6969
"/var/cache", # System cache directory
7070
"/opt", # Optional software directory
71+
"/mnt", # Mounted drives
7172
]
7273

7374
# Check if the resolved path is within allowed directories
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Python virtual environment
2+
.venv
3+
4+
# PyTorch model files
5+
*.pt
6+
7+
# Python cache files
8+
__pycache__/
9+
10+
# Test files and folders
11+
test/
12+
test*
13+
14+
# Embeddings folder
15+
embeddings
16+
17+
#Error logs
18+
*errors.txt
19+
20+
#VLM Models
21+
models
22+
23+
# VS Code cache
24+
.vscode
25+
26+
# Config file
27+
config.py
28+
29+
# History
30+
history
31+
history.json
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<!-- Copyright (C) 2025 Intel Corporation -->
2+
<!-- SPDX-License-Identifier: Apache-2.0 -->
3+
# Visual Textual Query-driven Document Reasoning Engine
4+
5+
## Overview
6+
7+
The Visual Textual Query-driven Document Reasoning Engine is an AI-powered tool that combines Vision-Language Models (VLMs) with document retrieval capabilities to enable intelligent, context-aware querying of technical documentation. This engine allows users to ask natural language questions about complex visual and textual content within PDF documents, with support for component identification through image uploads.
8+
9+
![Architecture Diagram](assets/architecture_diagram.png)
10+
11+
### Key Features
12+
13+
- **Multi-modal Document Retrieval**: Indexes PDF documents using advanced vision-language embeddings for semantic search
14+
- **Component-based Querying**: Upload images of specific components to retrieve relevant documentation pages
15+
- **Intelligent Visual Understanding**: Automatically identifies components from images and matches them against predefined taxonomies
16+
- **Agentic Response Generation**: Provides contextual, page-specific answers based on retrieved documentation
17+
- **Hardware Acceleration**: Optimized for Intel hardware (iGPU/dGPU) using OpenVINO and PyTorch XPU
18+
- **Interactive Web Interface**: User-friendly Gradio-based UI with query history and visual feedback
19+
- **Configurable Use Cases**: Easily adaptable to different domains (e.g., robotics manuals, IPC regulations, safety documentation)
20+
21+
### Use Cases
22+
23+
The engine is designed to be domain-agnostic and can be configured for various applications:
24+
- **Industrial Equipment Manuals**: Query robotic arm operation guides, safety procedures, and maintenance instructions
25+
- **Electronic Standards Compliance**: Navigate IPC regulations and component specifications
26+
- **Technical Documentation**: Search through complex visual-heavy manuals with natural language
27+
- **Training and Support**: Enable field technicians to quickly find relevant information using component photos
28+
29+
30+
## Verified Configurations
31+
The following hardware and OS configurations have been tested and verified:
32+
33+
- **Arrow Lake - H (iGPU)**
34+
- Intel(R) Core(TM) Ultra 9 285H
35+
- 64 GB RAM
36+
- 1 TB storage
37+
- Ubuntu 24.02
38+
- Python 3.12
39+
40+
- **Arrow Lake - S (dGPU)**
41+
- Intel(R) Core(TM) Ultra 9 285
42+
- 64 GB RAM
43+
- 1 TB storage
44+
- Ubuntu 24.02
45+
- Python 3.12
46+
- Arc A770 (16GB)
47+
48+
## Prerequisites
49+
Ensure the GPU drivers are installed using the [`gpu_installer.sh`](https://github.com/open-edge-platform/edge-developer-kit-reference-scripts/blob/main/gpu_installer.sh)
50+
51+
## Installation
52+
1. **Install the necessary dependencies.**
53+
```bash
54+
apt-get update
55+
apt-get install -y python3-venv poppler-utils
56+
```
57+
58+
2. **Create and activate a Python virtual environment:**
59+
```bash
60+
python3 -m venv .venv
61+
source .venv/bin/activate
62+
```
63+
64+
3. **Install remaining Python dependencies:**
65+
```bash
66+
pip install -r requirements.txt
67+
```
68+
69+
4. **Install PyTorch and Intel Extension for XPU support first:**
70+
```bash
71+
pip install -U --force-reinstall --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/xpu
72+
```
73+
74+
5. **Create the config file:**
75+
Create the `config.py` file by copying the content from `config.py.template` and modify the values to experiment with the tool. Few examples are available in the `./assets/usecases`.
76+
77+
## Usage
78+
1. **Activate the Python virtual environment created earlier (if not activated yet):**
79+
```bash
80+
source .venv/bin/activate
81+
```
82+
83+
2. **Run the app using following command:**
84+
- On Arrow Lake systems without a dGPU:
85+
```bash
86+
unset ONEAPI_DEVICE_SELECTOR && unset OPENVINO_DEVICE && python main.py
87+
```
88+
- On Arrow Lake systems with an A770:
89+
- to run fully on dGPU:
90+
```bash
91+
ONEAPI_DEVICE_SELECTOR=level_zero:0 OPENVINO_DEVICE=GPU.1 python main.py
92+
```
93+
- to run fully on iGPU:
94+
```bash
95+
ONEAPI_DEVICE_SELECTOR=level_zero:1 OPENVINO_DEVICE=GPU.0 python main.py
96+
```
97+
98+
Then open the provided local URL in your browser.

0 commit comments

Comments
 (0)