Sign inSign up

grctest/fastapi_gemma_translate

By grctest

Updated 6 months ago

A docker container hosting a FastAPI for Google's Gemma Translate AI models.

Image
Machine learning & AI
Web servers
0

878

grctest/fastapi_gemma_translate repository overview

fastapi-gemma-translate

This project provides a robust REST API built with FastAPI and Docker to manage and interact with Google's Gemma Translate AI Models for AI string translations on-device.

Key Features

  • Translation services
  • Support for multiple models
  • Automatic API Docs: Interactive API documentation powered by Swagger UI and ReDoc.

Technology Stack


Getting Started

Prerequisites
1. Set Up the Python Environment

Create and activate a Conda environment:

conda create -n translate python=3.11
conda activate translate

Install the hf tool to download the models:

pip install "fastapi[standard]" "uvicorn[standard]" httpx llama-cpp-python huggingface_hub

We're going to fetch the GGUF model fromats from these repositories:

https://huggingface.co/bullerwins/translategemma-27b-it-GGUF
https://huggingface.co/bullerwins/translategemma-12b-it-GGUF
https://huggingface.co/bullerwins/translategemma-4b-it-GGUF

For comparison, here's a table of all above GGUF models and their quantitizations:

Model FamilyQuantization LevelFile NameFile SizeQuality Level
Gemma 4BQ3_K_Ltranslategemma-4b-it-Q3_K_L.gguf2.24 GBLow-Medium
Q4_K_Stranslategemma-4b-it-Q4_K_S.gguf2.38 GBMedium
Q4_K_Mtranslategemma-4b-it-Q4_K_M.gguf2.49 GBBalanced
Q5_K_Stranslategemma-4b-it-Q5_K_S.gguf2.76 GBHigh
Q5_K_Mtranslategemma-4b-it-Q5_K_M.gguf2.83 GBHigh+
Q6_Ktranslategemma-4b-it-Q6_K.gguf3.19 GBNear Lossless
Q8_0translategemma-4b-it-Q8_0.gguf4.13 GBReference
Gemma 12BQ3_K_Ltranslategemma-12b-it-Q3_K_L.gguf6.48 GBMedium
Q4_K_Stranslategemma-12b-it-Q4_K_S.gguf6.94 GBHigh
Q4_K_Mtranslategemma-12b-it-Q4_K_M.gguf7.30 GBHigh (Recommended)
Q5_K_Stranslategemma-12b-it-Q5_K_S.gguf8.23 GBVery High
Q5_K_Mtranslategemma-12b-it-Q5_K_M.gguf8.45 GBVery High
Q6_Ktranslategemma-12b-it-Q6_K.gguf9.66 GBNear Lossless
Q8_0translategemma-12b-it-Q8_0.gguf12.5 GBReference
Gemma 27BQ3_K_Ltranslategemma-27b-it-Q3_K_L.gguf14.5 GBHigh
Q4_K_Stranslategemma-27b-it-Q4_K_S.gguf15.7 GBVery High
Q4_K_Mtranslategemma-27b-it-Q4_K_M.gguf16.5 GBVery High (Recommended)
Q5_K_Stranslategemma-27b-it-Q5_K_S.gguf18.8 GBExcellent
Q5_K_Mtranslategemma-27b-it-Q5_K_M.gguf19.3 GBExcellent
Q6_Ktranslategemma-27b-it-Q6_K.gguf22.2 GBNear Lossless
Q8_0translategemma-27b-it-Q8_0.gguf28.7 GBReference

Download one of the following Gemma Translate models:

Gemma 4B:

hf download bullerwins/translategemma-4b-it-GGUF translategemma-4b-it-Q8_0.gguf --local-dir app/models/translategemma-4b-it-Q8_0
hf download bullerwins/translategemma-4b-it-GGUF translategemma-4b-it-Q6_K.gguf --local-dir app/models/translategemma-4b-it-Q6_K
hf download bullerwins/translategemma-4b-it-GGUF translategemma-4b-it-Q5_K_S.gguf --local-dir app/models/translategemma-4b-it-Q5_K_S
hf download bullerwins/translategemma-4b-it-GGUF translategemma-4b-it-Q5_K_M.gguf --local-dir app/models/translategemma-4b-it-Q5_K_M
hf download bullerwins/translategemma-4b-it-GGUF translategemma-4b-it-Q4_K_S.gguf --local-dir app/models/translategemma-4b-it-Q4_K_S
hf download bullerwins/translategemma-4b-it-GGUF translategemma-4b-it-Q4_K_M.gguf --local-dir app/models/translategemma-4b-it-Q4_K_M
hf download bullerwins/translategemma-4b-it-GGUF translategemma-4b-it-Q3_K_L.gguf --local-dir app/models/translategemma-4b-it-Q3_K_L

Gemma 12B:

hf download bullerwins/translategemma-12b-it-GGUF translategemma-12b-it-Q8_0.gguf --local-dir app/models/translategemma-12b-it-Q8_0
hf download bullerwins/translategemma-12b-it-GGUF translategemma-12b-it-Q6_K.gguf --local-dir app/models/translategemma-12b-it-Q6_K
hf download bullerwins/translategemma-12b-it-GGUF translategemma-12b-it-Q5_K_S.gguf --local-dir app/models/translategemma-12b-it-Q5_K_S
hf download bullerwins/translategemma-12b-it-GGUF translategemma-12b-it-Q5_K_M.gguf --local-dir app/models/translategemma-12b-it-Q5_K_M
hf download bullerwins/translategemma-12b-it-GGUF translategemma-12b-it-Q4_K_S.gguf --local-dir app/models/translategemma-12b-it-Q4_K_S
hf download bullerwins/translategemma-12b-it-GGUF translategemma-12b-it-Q4_K_M.gguf --local-dir app/models/translategemma-12b-it-Q4_K_M
hf download bullerwins/translategemma-12b-it-GGUF translategemma-12b-it-Q3_K_L.gguf --local-dir app/models/translategemma-12b-it-Q3_K_L

Gemma 27B:

hf download bullerwins/translategemma-27b-it-GGUF translategemma-27b-it-Q8_0.gguf --local-dir app/models/translategemma-27b-it-Q8_0
hf download bullerwins/translategemma-27b-it-GGUF translategemma-27b-it-Q6_K.gguf --local-dir app/models/translategemma-27b-it-Q6_K
hf download bullerwins/translategemma-27b-it-GGUF translategemma-27b-it-Q5_K_S.gguf --local-dir app/models/translategemma-27b-it-Q5_K_S
hf download bullerwins/translategemma-27b-it-GGUF translategemma-27b-it-Q5_K_M.gguf --local-dir app/models/translategemma-27b-it-Q5_K_M
hf download bullerwins/translategemma-27b-it-GGUF translategemma-27b-it-Q4_K_S.gguf --local-dir app/models/translategemma-27b-it-Q4_K_S
hf download bullerwins/translategemma-27b-it-GGUF translategemma-27b-it-Q4_K_M.gguf --local-dir app/models/translategemma-27b-it-Q4_K_M
hf download bullerwins/translategemma-27b-it-GGUF translategemma-27b-it-Q3_K_L.gguf --local-dir app/models/translategemma-27b-it-Q3_K_L

Running the Application

This is the easiest and recommended way to run the application.

  1. Build the Docker image:

    docker build -t fastapi_gemma_translate .
    
  2. Run the Docker container: This command runs the container in detached mode (-d) and maps port 8080 on your host to port 8080 in the container.

    docker run -d --name ai_container_cpu -p 127.0.0.1:8080:8080 -v C:/Users/username/Desktop/git/fastapi-gemma-translate/_models:/code/models fastapi_gemma_translate
    

Alternatively you can pull and run my docker image:

  1. Pull the Docker image:

    docker image pull grctest/fastapi_gemma_translate
    
  2. Run the Docker container: This command runs the container in detached mode (-d) and maps port 8080 on your host to port 8080 in the container.

    docker run -d --name ai_container_cpu -p 127.0.0.1:8080:8080 -v C:/Users/username/Desktop/git/fastapi-gemma-translate/_models:/code/models grctest/fastapi_gemma_translate
    
Local Development

For development, you can run the application directly with Uvicorn, which enables auto-reloading.

uvicorn app.main:app --host 0.0.0.0 --port 8080 --reload

API Usage

Once the server is running, you can access the interactive API documentation:


Project showcase

MetalGlot

MetalGlot is a private, local-first AI translation desktop app for developers and creators who desire a secure translation workflow without relying on cloud services. Built primarily for software localization and structured i18n content, MetalGlot helps users translate text, locale files, markdown, subtitles, and image-based content on their own hardware while avoiding telemetry, protecting intellectual property, and eliminating recurring per-token costs.


License

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

Tag summary

Content type

Image

Digest

sha256:3177635d5

Size

582.9 MB

Last updated

6 months ago

docker pull grctest/fastapi_gemma_translate