diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..dec6100 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,29 @@ +# Ignore Python cache files +__pycache__/ +*.pyc +*.pyo +*.pyd + +# Ignore Python virtual environment +venv/ + +# Ignore pipenv files +Pipfile +Pipfile.lock + +# Ignore other Python specific files +*.pyc +*.pyo +*.pyd +*.egg-info/ +dist/ +build/ + +# Ignore environment files +*.env* + +# Ignore git files +.git/ + +# Ignore mp3 files +*.mp3 diff --git a/.gitignore b/.gitignore index 7b93963..87005ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea .env venv -__pycache__ \ No newline at end of file +__pycache__ +docker-compose.yml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7764a42 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +# Use an official Python runtime as a parent image +FROM python:3.8 + +# Set the working directory in the container +WORKDIR /usr/src/app + +# Copy the current directory contents into the container at /usr/src/app +COPY . . + +# Install dependencies +RUN pip install -r requirements.txt + +# Make port 7860 available to the world outside this container +EXPOSE 7860 + +# Run app.py when the container launches +CMD ["python", "app.py"] diff --git a/README.md b/README.md index d9d01fe..91e0365 100644 --- a/README.md +++ b/README.md @@ -12,5 +12,23 @@ 8. open your browser and type [http://127.0.0.1:7860](http://127.0.0.1:7860) 9. the api docs in [http://127.0.0.1:7860/?view=api](http://127.0.0.1:7860/?view=api) +## Docker Container Build + +To build a Docker container for the OpenAI Text To Speech API with Gradio, follow these steps: + +1. Make sure you have Docker installed on your system. +2. Open a terminal and navigate to the project directory. +3. Run the following command to build the Docker image: + ``` + docker build -t openai-tts-gradio . + ``` +4. Wait for the build process to complete. +5. Once the build is finished, you can run the Docker container using the following command: + ``` + docker run -d --name openai-tts-gradio -p 7860:7860 -e OPENAI_KEY= -e SERVER_NAME=0.0.0.0 openai-tts-gradio + ``` +6. Open your browser and navigate to [http://127.0.0.1:7860](http://127.0.0.1:7860) to access the API. + + interface like this ![Screen](assets/screen.png "Screen") \ No newline at end of file diff --git a/app.py b/app.py index b7868a2..390fee0 100644 --- a/app.py +++ b/app.py @@ -10,6 +10,7 @@ load_dotenv() +server_name = os.getenv("SERVER_NAME", "127.0.0.1") openai_key = os.getenv("OPENAI_KEY") if openai_key == "": @@ -71,7 +72,7 @@ def tts( text.submit(fn=tts, inputs=[text, model, voice, output_file_format, speed], outputs=output_audio, api_name="tts") btn.click(fn=tts, inputs=[text, model, voice, output_file_format, speed], outputs=output_audio, api_name=False) -demo.launch() +demo.launch(server_name=server_name) # curl --location "http://127.0.0.1:7860/api/tts" \ # --header "Content-Type: application/json" \