Skip to content

Commit

Permalink
Merge pull request #3 from michealch/feature/dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
leokwsw committed Jan 19, 2024
2 parents 99ed665 + 2344109 commit 035d615
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
29 changes: 29 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
.env
venv
__pycache__
__pycache__
docker-compose.yml
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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

# 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"]
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<YOUR_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")
3 changes: 2 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "<YOUR_OPENAI_KEY>":
Expand Down Expand Up @@ -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" \
Expand Down

0 comments on commit 035d615

Please sign in to comment.