This is a translation API written in Python that integrates with "immersive translation" plugin in browser, using the Google Gemini API, which is powered by Google's generative AI technology.
To use the GeminiTranslate, follow the steps below:
-
Obtain a free API key from Google. You can configure the API key by replacing
os.getenv('GOOGLE_API_KEY')
with your actual API key inmain.py
:genai.configure(api_key="YOUR_API_KEY")
-
Install the required dependencies:
pip install -r requirements.txt
-
Run the Flask application on the local server, default API address is
http://127.0.0.1/translate
:python ./main.py
-
Configure immersive translation plugin.
- In developer settings, turn on
Beta features
. - Basic settings -> Translate service -> Custom API
- Set
API URL
to your API address, default ishttp://127.0.0.1/translate
.
- In developer settings, turn on
-
Enjoy!
- You can adjust the
safety_settings
andgeneration_config
parameters according to your requirements, default is none. - Make sure you can access the Google API, otherwise you may need to use a proxy.
- The API is limited to 60 times per minute, you can apply for a higher limit here, or set the maximum number of requests per second to 1 in the immersive translation custom options.
- Prompt injection may exist in the translation result.
- Gemini API is not allow to talk about OpenAI😑
- Recommended to use the maximum number of requests per second in the custom options: 1, the maximum number of paragraphs per request: 20, to avoid exceeding the limit.