Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker support and Windows installation script #65

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Use an official Python runtime as a parent image
FROM python:3.8-slim

# Set the working directory in the container
WORKDIR /usr/src/app

# Install ffmpeg and git
RUN apt-get update && apt-get install -y ffmpeg git

# Install ffmpeg-python library
RUN pip install ffmpeg-python

# Clone the repository and install its dependencies
RUN pip install git+https://github.com/m1guelpf/auto-subtitle.git

# Copy the local code to the container
COPY . .

# Define environment variable
ENV NAME AutoSubtitle

# Set the default command for the container
CMD ["auto_subtitle"]
46 changes: 46 additions & 0 deletions autosub.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
param (
[string]$model = "tiny",
[string]$output_dir = "output",
[bool]$srt_only = $false,
[Parameter(Position=0, Mandatory=$false)]
[string]$videoPath
)

function Show-Help {
@"
Usage: autosub [-model <string>] [-output_dir <string>] [-srt_only <bool>] <videoPath>
autosub --help

-model <string>: The model to use for subtitling. Available models are {tiny.en,tiny,base.en,base,small.en,small,medium.en,medium,large-v1,large-v2,large-v3,large}. Default is 'tiny'.
-output_dir <string>: The directory where the output file will be stored. Default is 'output'.
-srt_only <bool>: If set to $true, only generates SRT file. Default is $false.
-videoPath <string>: Full path to the video file to be processed.
--help: Shows this help message.

Example:
autosub "C:\path\to\video.mp4" -model tiny -output_dir output_autosub -srt_only $true
Runs the auto-subtitle container on 'video.mp4' using the 'tiny' model, outputs to 'output_autosub', and generates only the SRT file.
"@
}

if ($videoPath -eq "--help") {
Show-Help
exit
}

# Extract the directory path and video file name from the provided path
$videoDirectory = Split-Path -Parent $videoPath
$videoFile = Split-Path -Leaf $videoPath

# Construct the Docker command
# $dockerCommand = "docker run -it --rm -v ${videoDirectory}:/usr/src/app/data --name my-running-app auto-subtitle auto_subtitle '/usr/src/app/data/$videoFile' --model $model --output_dir /usr/src/app/data/$output_dir"
$dockerCommand = "docker run -it --rm -v ${videoDirectory}:/usr/src/app/data -v my_downloaded_packages:/root/.cache/ --name my-running-app auto-subtitle auto_subtitle '/usr/src/app/data/$videoFile' --model $model --output_dir /usr/src/app/data/$output_dir"

# Add the srt_only flag if it's true
if ($srt_only -eq $true) {
$dockerCommand += " --srt_only True"
}

# Run the Docker command
Invoke-Expression $dockerCommand

6 changes: 6 additions & 0 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
docker build -t auto-subtitle .
New-Item -Path "C:\autosub" -ItemType Directory -Force
Copy-Item -Path "autosub.ps1" -Destination "C:\autosub"
$UserPath = [System.Environment]::GetEnvironmentVariable("PATH", [System.EnvironmentVariableTarget]::User)
$NewPath = "$UserPath;C:\autosub"
[System.Environment]::SetEnvironmentVariable("PATH", $NewPath, [System.EnvironmentVariableTarget]::User)