From afb20b113d5d97c763617c90319d750d41fa5375 Mon Sep 17 00:00:00 2001 From: killkli Date: Thu, 26 Sep 2024 09:45:05 +0800 Subject: [PATCH] feat: Add Dockerfile and update README.md for Docker usage --- .gitignore | 5 +++++ Dockerfile | 33 +++++++++++++++++++++++++++++++++ README.md | 20 +++++++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 Dockerfile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f82593 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +__pycache__ +*.pyc +*.pyo +*.swp +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0713cba --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# Use the official Python 3.9 slim image as the base +FROM python:3.9-slim + +# Set environment variables to prevent Python from writing .pyc files and to buffer outputs +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 + +# Set the working directory in the container +WORKDIR /app + +# Install system dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + && rm -rf /var/lib/apt/lists/* + +# Copy the requirements file into the container +COPY requirements.txt . + +# Upgrade pip and install Python dependencies +RUN pip install --upgrade pip && \ + pip install --no-cache-dir -r requirements.txt + +# Copy the rest of the application code into the container +COPY . . + +# Expose the port that Gradio uses +EXPOSE 7860 + +# Define environment variable for OpenAI API Key (to be provided at runtime) +ENV OPENAI_API_KEY="" + +# Specify the command to run the application +CMD ["python", "app.py"] diff --git a/README.md b/README.md index 121a4f8..c11a4a2 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ To run the PDF2Audio app: 1. Ensure you're in the project directory and your Conda environment is activated: ``` - conda activate pdf2audio +conda activate pdf2audio ``` 2. Run the Python script that launches the Gradio interface: @@ -73,6 +73,24 @@ To run the PDF2Audio app: 4. Use the Gradio interface to upload a PDF file and convert it to audio. +## Using Docker + +1. **Build the Docker image:** + ```bash + docker build -t pdf2audio . + ``` + +2. **Run the Docker container:** + ```bash + docker run -p 7860:7860 -e OPENAI_API_KEY=your_api_key_here pdf2audio + ``` + + - Replace `your_api_key_here` with your actual OpenAI API key. + - The `-p 7860:7860` mapping exposes port 7860 of the container to your host machine, allowing you to access the Gradio interface. + +3. **Access the Gradio interface:** + Open your web browser and go to `http://localhost:7860`. + ## How to Use 1. Upload one or more PDF files