Skip to content

Commit

Permalink
Merge pull request #42 from animeshchaudhri/main
Browse files Browse the repository at this point in the history
Docs: Rust backend
  • Loading branch information
Pranav0-0Aggarwal authored Aug 21, 2024
2 parents 1966c18 + cd3a815 commit c0d8f40
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 60 deletions.
129 changes: 98 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,110 @@
# Contents
1. [`Backend`](#Backend)
2. [`Project Description (PictoPy)`](#PictoPy)
# PictoPy

# Backend
## Steps to run backend
PictoPy is an advanced desktop gallery application that combines the power of Tauri, React, and Rust for the frontend with a Python backend for sophisticated image analysis and management.

1. Head over to `/backend` after cloning
2. Create a virtual env by running: `python3 -m venv venv`
3. Activate the env by running `source venv/bin/activate` and install dependancies via `pip install requirments.txt`
4. Start the server via `./run.sh` (for development mode add the flag `--test` [RECOMMENDED])
5. The server should now be hosted on port `8000` on localhost.
## Architecture

## Some pointers for the backend
### Frontend
- **Tauri**: Enables building the desktop application
- **React**: Used for creating the user interface
- **Rust**: Powers the backend, which the frontend communicates with through Tauri's API

- Entry point is `main.py` which calls the routes, currently there is a `/test` route for developing, to test an image, send a request to the backend (`localhost:8000/test/return`) with the following Body format:
```
{
"path": "<Path to image>"
}
### Backend (Python)
- **FastAPI**: Serves as the API framework
- **SQLite**: Database for storing metadata and embeddings
- **YOLO**: Used for object detection
- **FaceNet**: Generates face embeddings
- **ONNX Runtime**: Runs the models efficiently
- **DBSCAN**: Performs clustering for face embeddings

### Backend (Rust via Tauri)
Handles file system operations and provides a secure bridge between the frontend and local system.

## Features

- Smart tagging of photos based on detected objects, faces, and their recognition
- Traditional gallery features of album management
- Advanced image analysis with object detection and facial recognition
- Privacy-focused design with offline functionality
- Efficient data handling and parallel processing
- Smart search and retrieval
- Cross-platform compatibility

## Technical Stack

| Component | Technology |
| --------- | ---------- |
| Frontend | React |
| Desktop Framework | Tauri |
| Rust Backend | Rust |
| Python Backend | Python |
| Database | SQLite |
| Image Processing | OpenCV, ONNX Runtime |
| Object Detection | YOLOv8 |
| Face Recognition | FaceNet |
| API Framework | FastAPI |
| State Management | React Hooks |
| Styling | Tailwind CSS |
| Routing | React Router |
| UI Components | Radix UI |
| Build Tool | Vite |
| Type Checking | TypeScript |

## Setup

### Frontend Setup

#### Prerequisites
- Node.js (LTS version recommended)
- npm (comes with Node.js)
- Rust (latest stable version)
- Tauri CLI

#### Installation
1. Navigate to the frontend directory:
```bash
cd frontend
```
2. Install dependencies:
```bash
npm install
```

#### Running the Application
```bash
npm run tauri dev
```
Eg: try it out with path as`backend/tests/inputs/zidane.jpg`
- A window should pop up showing the highlighted detections, simply press `q` to exit, or comment out the `cv2` lines in `test.py`
- Change the type of inference by changing `model_path` variable in `app/test` route, by default there are two models available in the `app/models` directory (face and object deteciton).
# PictoPy

An open source image sorting tool designed to organize your image collection efficiently.
#### Building for Production
```bash
npm run tauri build
```

## Features to be Implemented
### Python Backend Setup

1. **A dedicated Local Database:**
- A dedicated local database for caching tags, significantly improving the speed and efficiency of image sorting.
#### Installation
1. Navigate to the backend directory:
```bash
cd backend
```
2. Set up a virtual environment (recommended)
3. Install requirements:
```bash
pip install -r requirements.txt
```

2. **Image Recognition Library:**
- Uses an advanced image recognition library for evaluating objects in images along with faces, ensuring a smoother and more accurate sorting process.
#### Running the Backend
For UNIX-based systems:
```bash
./run.sh --test
```

3. **Improved UI/UX:**
- A smooth user interface for a more intuitive and pleasant experience.
The backend should now be running on port 8000 by default.

4. **Multiprocessing Support:**
- Pictopy should supports multiprocessing, optimizing the sorting process and improving overall performance.
## Additional Resources
- [Tauri Documentation](https://tauri.app/v1/guides/)
- [React Documentation](https://reactjs.org/docs/getting-started.html)
- [FastAPI Documentation](https://fastapi.tiangolo.com/)


## Troubleshooting
If you encounter any issues, please check the respective documentation for Tauri, React, and FastAPI. For persistent problems, feel free to open an issue in the project repository.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 7 additions & 6 deletions docs/backend/setup.md → docs/backend/backend_python/setup.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Backend Setup

# Python Backend Setup

## Setup Directory

!!! note "Base Directory"
All commands executed below are with respect to the `backend/` directory
All commands executed below are with respect to the `backend/` directory

### Installing requirments

We suggest setting up a virtual environment and run the following command

```bash
pip install -r requirements.txt
```
Expand All @@ -16,8 +17,8 @@ The entry point for backend is `main.py` , since PictoPy is built on top of Fast
`.bat` and `.sh` formats.

!!! note "UNIX Development"
For UNIX based systems, to run in development mode run
```bash
For UNIX based systems, to run in development mode run
`bash
./run.sh --test
```
`
The backend should now be successfully running on port 8000 by default. To change this modify the start-up scripts.
54 changes: 54 additions & 0 deletions docs/backend/backend_rust/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## API Documentation

The Rust backend provides the following commands that can be invoked from the frontend:

### 1. get_folders_with_images
- **Description**: Retrieves folders containing images from a specified directory.
- **Parameters**:
- `directory`: String
- **Returns**: `Vec<PathBuf>`

### 2. get_images_in_folder
- **Description**: Gets all images in a specific folder.
- **Parameters**:
- `folder_path`: String
- **Returns**: `Vec<PathBuf>`

### 3. get_all_images_with_cache
- **Description**: Retrieves all images, organized by year and month, with caching.
- **Parameters**:
- `directory`: String
- **Returns**: `Result<HashMap<u32, HashMap<u32, Vec<String>>>, String>`

### 4. get_all_videos_with_cache
- **Description**: Retrieves all videos, organized by year and month, with caching.
- **Parameters**:
- `directory`: String
- **Returns**: `Result<HashMap<u32, HashMap<u32, Vec<String>>>, String>`

### 5. delete_cache
- **Description**: Deletes all cached data.
- **Parameters**: None
- **Returns**: `bool`

## Usage Example

```javascript
// In your frontend JavaScript/TypeScript code:
import { invoke } from '@tauri-apps/api/tauri';

// Example: Get all images with cache
const imagesData = await invoke('get_all_images_with_cache', { directory: '/path/to/images' });

// Example: Delete cache
const cacheDeleted = await invoke('delete_cache');
```

## Key Components

- **FileService**: Handles file system operations for images and videos.
- **CacheService**: Manages caching of folders, images, and videos.
- **FileRepository**: Interacts directly with the file system to retrieve file information.
- **CacheRepository**: Handles reading from and writing to cache files.

This backend architecture provides efficient file management and caching capabilities, enhancing the performance of image and video retrieval operations in the Tauri application.
49 changes: 49 additions & 0 deletions docs/backend/backend_rust/setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Rust Backend Setup

## Prerequisites

Before setting up the frontend, ensure you have the following installed:

- [Node.js](https://nodejs.org/) (LTS version recommended)
- npm (comes with Node.js)
- [Rust](https://www.rust-lang.org/tools/install) (latest stable version)
- [Tauri CLI](https://v2.tauri.app/start/prerequisites/)

For a comprehensive guide on prerequisites, refer to the [Tauri Prerequisites](https://v2.tauri.app/start/prerequisites/) documentation.

## Setup Directory

!!! note "Base Directory"
All commands executed below are with respect to the `frontend/` directory

### Installing Dependencies

1. Navigate to the frontend directory:
```bash
cd frontend
```

2. Install the project dependencies:
```bash
npm install
```

For more information on npm commands, see the [npm documentation](https://docs.npmjs.com/).

## Running the Application

To start the Tauri application in development mode, run:

```bash
npm run tauri dev
```

This command will:
- Start the [Vite](https://vitejs.dev/) development server for the frontend
- Compile the Rust backend
- Launch the Tauri application window

For more details on Tauri commands, check the [Tauri CLI documentation](https://tauri.app/v1/api/cli).

!!! note "First Run"
The first run might take longer as it needs to compile the Rust code.
38 changes: 26 additions & 12 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ PictoPy is a modern desktop app designed to transform the handling of digital ph
<img src="assets/AOSSIE-logo.png" alt="AOSSIE Logo" style="display:flex; margin:0 auto; justify-content: center;">
</div>

This project was announced by [AOSSIE](https://aossie.org/), an umbrella organization and was to be implemented from scratch. It provides features such as object detection and face similarity,
offering smart tagging capabilities for photos based on objects, faces.
This project was announced by [AOSSIE](https://aossie.org/), an umbrella organization and was to be implemented from scratch. It provides features such as object detection and face similarity, offering smart tagging capabilities for photos based on objects, faces.

<div style="display:flex; margin:0 auto; justify-content: center;">
<div style="width:33%">
<div style="width:25%">
<h2>Overview</h2>
<ul>
<li><a href='./overview/features'>
Expand All @@ -24,37 +23,52 @@ offering smart tagging capabilities for photos based on objects, faces.
</li>
</ul>
</div>
<div style="width:33%">
<h2>Backend</h2>
<div style="width:25%">
<h2>Backend Python</h2>
<ul>
<li>
<a href="./backend/setup">
<a href="./backend/backend_python/setup">
Setup
</a>
</li>
<li>
<a href="./backend/database">
<a href="./backend/backend_python/database">
Database
</a>
</li>
<li>
<a href="./backend/directory-structure">
<a href="./backend/backend_python/directory-structure">
Directory Structure
</a>
</li>
<li>
<a href="./backend/api">
<a href="./backend/backend_python/api">
API
</a>
</li>
<li>
<a href="./backend/image-processing">
<a href="./backend/backend_python/image-processing">
Image Processing
</a>
</li>
</ul>
</div>
<div style="width:33%">
<div style="width:25%">
<h2>Backend Rust</h2>
<ul>
<li>
<a href="./backend/backend_rust/setup">
Setup
</a>
</li>
<li>
<a href="./backend/backend_rust/api">
API
</a>
</li>
</ul>
</div>
<div style="width:25%">
<h2>Frontend</h2>
<ul>
<li>
Expand All @@ -79,4 +93,4 @@ offering smart tagging capabilities for photos based on objects, faces.
</li>
</ul>
</div>
</div>
</div>
Loading

0 comments on commit c0d8f40

Please sign in to comment.