Closed Maitresinh closed 7 months ago
If using Whisper the app requires asr-webservice to hook into, https://wiki.bazarr.media/Additional-Configuration/Whisper-Provider/ or you might be able to use web hooks.
And here's the provider's code that communicate with Whisper: https://github.com/morpheus65535/bazarr/blob/development/custom_libs/subliminal_patch/providers/whisperai.py
No news, good news!
i've tried to build it with the help of ChatGPT. Nothing working until now
Here is a detailed step-by-step guide for installing GPT-Subtrans with Bazarr, including configuration for automatic subtitle translation and manual subtitle selection using a GUI or frontend.
Step 1: Setting up the Environment Ensure Docker is installed on your unRAID server if it’s not already set up. Install Bazarr on unRAID: Configure Bazarr to manage your media library's subtitles by linking it to your downloaders (Transmission, etc.) and media managers (Sonarr, Radarr). Step 2: Create the Docker Container for GPT-Subtrans
bash Copier le code mkdir -p /mnt/user/appdata/gpt-subtrans-gui cd /mnt/user/appdata/gpt-subtrans-gui Create a Dockerfile in this directory:
bash Copier le code nano Dockerfile Add the following content to the Dockerfile:
dockerfile Copier le code FROM python:3.10-slim
RUN apt-get update && apt-get install -y git fluxbox x11vnc xvfb
RUN git clone https://github.com/machinewrapped/gpt-subtrans.git /app/gpt-subtrans
WORKDIR /app/gpt-subtrans RUN bash install.sh
RUN pip install flask
RUN pip install openai google.generativeai anthropic
CMD ["bash", "-c", "xvfb-run -s '-screen 0 1024x768x16' python3 gui-subtrans.py"] Save and exit (CTRL + X, then Y, then Enter).
bash Copier le code cd /mnt/user/appdata/gpt-subtrans-gui Build the Docker image from the Dockerfile:
bash Copier le code docker build -t gpt-subtrans-gui:latest .
Option 1: Use a .env File for the API Key Create a .env file in the GPT-Subtrans directory:
bash Copier le code nano /mnt/user/appdata/gpt-subtrans-gui/.env Add your OpenAI API key to the file:
bash Copier le code OPENAI_API_KEY=your_openai_api_key Save and exit (CTRL + X, then Y, then Enter).
Option 2: Pass the API Key as an Environment Variable If you prefer not to use a .env file, you can pass the API key as a Docker environment variable during container creation.
If you used the .env file for the API key:
bash Copier le code docker create \ --name=gpt-subtrans \ -v /mnt/user/data/media:/media \ -p 5900:5900 \ gpt-subtrans-gui:latest OR, if you pass the API key as an environment variable:
bash Copier le code docker create \ --name=gpt-subtrans \ -v /mnt/user/data/media:/media \ -e OPENAI_API_KEY="your_openai_api_key" \ -p 5900:5900 \ gpt-subtrans-gui:latest -p 5900:5900: Exposes the port for accessing the GUI via VNC. OPENAI_API_KEY="your_openai_api_key": Replace with your actual OpenAI API key if passing it directly. Start the container:
bash Copier le code docker start gpt-subtrans Access the GUI (Optional):
Use a VNC client (e.g., RealVNC or TightVNC) to connect to your unRAID server at
bash Copier le code nano /mnt/user/appdata/bazarr/gpt_subtrans_postprocess.sh Add the following code to the script:
bash Copier le code
SUBTITLE_PATH="${SUBTITLE_PATH}" SUBTITLE_LANGUAGE_CODE3="${SUBTITLE_LANGUAGE_CODE3}"
echo "Subtitle file path: $SUBTITLE_PATH" echo "Subtitle language: $SUBTITLE_LANGUAGE_CODE3"
if [[ "$SUBTITLE_LANGUAGE_CODE3" == "fre" ]]; then echo "Subtitles are already in French. No translation needed." else echo "Translating subtitles $SUBTITLE_PATH to French." docker exec gpt-subtrans python3 /app/gpt-subtrans/batch_process.py "$SUBTITLE_PATH" --target-lang fr fi Make the script executable:
bash Copier le code chmod +x /mnt/user/appdata/bazarr/gpt_subtrans_postprocess.sh
Go to Settings > Processing > Post-Processing Scripts.
Add the path to the post-processing script:
bash Copier le code /mnt/user/appdata/bazarr/gpt_subtrans_postprocess.sh Bazarr will now trigger GPT-Subtrans to translate the subtitles after downloading them.
Optional: Set Up a Frontend for Subtitle Selection If you want a more visual way to choose which subtitles to translate, you can set up a Flask-based frontend.
bash Copier le code mkdir /mnt/user/appdata/gpt-subtrans-gui/app cd /mnt/user/appdata/gpt-subtrans-gui/app Create a Python file for the Flask app:
bash Copier le code nano app.py Add the following code:
python Copier le code from flask import Flask, render_template, request import os import subprocess
app = Flask(name)
@app.route('/') def index():
subtitles = []
for root, dirs, files in os.walk("/media"):
for file in files:
if file.endswith(".srt"):
subtitles.append(os.path.join(root, file))
return render_template('index.html', subtitles=subtitles)
@app.route('/translate', methods=['POST']) def translate(): subtitle_file = request.form['subtitle']
subprocess.call(['docker', 'exec', 'gpt-subtrans', 'python3', '/app/gpt-subtrans/batch_process.py', subtitle_file, '--target-lang', 'fr'])
return f"Translating {subtitle_file} to French"
if name == 'main': app.run(debug=True, host='0.0.0.0', port=5000) Create the HTML template in the templates/ directory:
bash Copier le code mkdir templates nano templates/index.html Add the following HTML:
html Copier le code <!DOCTYPE html>
Rebuild the Docker image with Flask:
bash Copier le code docker build -t gpt-subtrans-gui:latest . Start the Flask frontend:
The Flask app will be available at http://
Someone (IlmariKu) on the GPT subtrans Github is willing to adapt it to bazarr for unraid, and he's asking if there is an API to to so (or any other way). GPT subrans would be a great improvemnt for translation...