tauri-tensorflow-template Svelte Themes

Tauri Tensorflow Template

A template project combining Tauri, Python (TensorFlow), FastAPI, and Svelte to create lightweight desktop applications with integrated machine learning capabilities.

Tauri TensorFlow Starter

A template project combining Tauri, Python (TensorFlow), FastAPI, and Svelte to create lightweight desktop applications with integrated machine learning capabilities.

Features

  • šŸ– Tauri: Lightweight desktop application framework.
  • šŸ§  TensorFlow: Use Python to handle machine learning and AI tasks.
  • šŸ“” TensorFlow-GPU: Using a version of TensorFlow with GPU capabilities for Windows.
  • šŸš€ FastAPI: High-performance API for backend communication.
  • šŸ“¦ PyInstaller: Package Python applications into standalone executables.
  • šŸŒŸ Svelte: Build reactive and user-friendly UIs.
  • šŸ”› TypeScript Client: Auto-generated frontend client using hey-api.

Project Structure

šŸ—‚ tauri-tensorflow-template
ā”œā”€ā”€ šŸ— server          # Python TensorFlow + FastAPI backend
ā”œā”€ā”€ šŸ— src             # Svelte frontend
ā”œā”€ā”€ šŸ— src-tauri       # Rust-based Tauri application
ā””ā”€ā”€ šŸ“„ README.md       # Documentation

Installation

1. Prerequisites: GPU Capabilities

To enable GPU capabilities for TensorFlow, you must install the following NVIDIA components and add their paths to the system environment variables: Maybe try with only 12.6 and cudnn 9.6 first and if it doesn't work try with 11.8 and cudnn 8.9

Install CUDA and cuDNN

Add to PATH

After installation, ensure the following directories are added to your system's PATH environment variable:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\8.9.7\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4\bin
C:\Program Files\NVIDIA\CUDNN\v9.6\bin

2. Clone the Repository

git clone https://github.com/ydubrana/tauri-tensorflow-template.git
cd tauri-tensorflow-template

3. Set Up the Backend

Install Python Dependencies:

Use Conda to create the required environment from the environment.yml file:

cd server
conda create --file environment.yml
conda activate tauri-tensorflow

Verify Installation

To confirm the installation:

  1. Open a terminal and run:

    nvcc --version
    

    This will display the version of CUDA installed.

  2. Check that TensorFlow detects the GPU:

    python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
    

Package the Backend:

Use the provided PowerShell script to bundle the server into an executable using PyInstaller:

pnpm run build-server

This will generate the server executable along with the required Python runtime.


4. Set Up the Frontend

Install Node.js Dependencies:

Navigate to the frontend directory and install the required packages:

cd frontend
pnpm install

Generate the TypeScript Client:

Start the backend server and build the API client for the frontend:

pnpm run launch-server
pnpm run build-server-client

5. Run the Application

  1. Start the Tauri application in development mode:

    pnpm run tauri dev
    
  2. The backend server will automatically start and stop with the Tauri application.

  3. Interact with the TensorFlow model via the Svelte-based UI.


6. Package the Application

To package the application for distribution, i have created a github actions that will build the application for windows. This is compatible with Tauri updater and public realease in private repository. Feel free to open an issue if you want to know more about it.

Notes:

  • Ensure all required dependencies are installed correctly for both the backend and frontend.
  • I'll be more than happy if someone can help me to make this project work on WSL, Linux, MacOS.
  • On windows, WSL we'll be a great addition to use more modern tensorflow versions.
  • Contributions are welcome! Feel free to open issues and submit pull requests.

License

This project is licensed under the MIT License.

Top categories

Loading Svelte Themes