https://github.com/saba-gul/gcp-dental-caries-detection-cloud-deployment
Deploy Containerized ML model on GCP
https://github.com/saba-gul/gcp-dental-caries-detection-cloud-deployment
Last synced: 7 months ago
JSON representation
Deploy Containerized ML model on GCP
- Host: GitHub
- URL: https://github.com/saba-gul/gcp-dental-caries-detection-cloud-deployment
- Owner: Saba-Gul
- Created: 2024-10-02T03:36:51.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-27T02:22:06.000Z (12 months ago)
- Last Synced: 2025-01-13T16:28:17.155Z (9 months ago)
- Language: Python
- Size: 19.3 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Here’s a step-by-step guide to deploying your Gradio application on Google Cloud Platform (GCP) using Cloud Run, including all necessary steps, configurations, and commands.
### Step-by-Step Guide to Deploy a Gradio App on GCP
#### Prerequisites
- A Google Cloud account.
- Google Cloud SDK installed (if deploying from local).
- Docker installed (if building the image locally).
- Your Gradio app code ready.### 1. Set Up Your GCP Project
1. **Create a New Project**:
- Go to the [Google Cloud Console](https://console.cloud.google.com/).
- Click on the project dropdown at the top and select **New Project**.
- Enter a project name and click **Create**.2. **Set the Project ID**:
- After creating the project, take note of your Project ID. You’ll use it in commands.3. **Enable Billing**:
- Ensure that billing is enabled for your project. You can set this up in the **Billing** section of the Cloud Console.4. **Enable Required APIs**:
- Go to the **APIs & Services > Library**.
- Enable the **Cloud Run API** and the **Cloud Build API**.### 2. Prepare Your Application
1. **Organize Your Files**:
- Structure your application with the following files:
```
/app
├── gradio-app.py
└── requirements.txt
Dockerfile
```2. **Create `requirements.txt`**:
- List all necessary Python packages in `requirements.txt`, including Gradio and any other dependencies.3. **Create Dockerfile**:
- Use the following Dockerfile:
```dockerfile
# Use an official Python runtime as a parent image
FROM python:3.10-slim# Set the working directory in the container
WORKDIR /app# Install system dependencies required by OpenCV and other libraries
RUN apt-get update && apt-get install -y \
libgl1-mesa-glx \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender1# Upgrade pip and setuptools to avoid dependency issues
RUN pip install --upgrade pip setuptools# Copy requirements.txt first
COPY requirements.txt /app# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt# Copy the application code incrementally
COPY app/ /app# Expose the port defined by the PORT environment variable
EXPOSE 8080# Define environment variable for Gradio app
ENV GRADIO_SERVER_NAME="0.0.0.0"# Set the PORT environment variable to 8080 (default for Cloud Run)
ENV PORT=8080# Run the application
CMD ["python", "gradio-app.py"]
```### 3. Build and Push Your Docker Image
1. **Open Cloud Shell** (or your terminal if you have the SDK installed):
- Click the **Activate Cloud Shell** button in the Google Cloud Console or open your terminal.2. **Authenticate with GCP** (if using local terminal):
```bash
gcloud auth login
```3. **Set the Project**:
```bash
gcloud config set project YOUR_PROJECT_ID
```4. **Build the Docker Image**:
- If using Cloud Shell, you can use the built-in Docker, or if using local Docker:
```bash
gcloud builds submit --tag gcr.io/YOUR_PROJECT_ID/gradio-app
```
- This command builds the Docker image and uploads it to Google Container Registry.### 4. Deploy the Docker Image to Cloud Run
1. **Deploy to Cloud Run**:
```bash
gcloud run deploy gradio-app \
--image gcr.io/YOUR_PROJECT_ID/gradio-app \
--platform managed \
--region YOUR_REGION \
--allow-unauthenticated
```
- Replace `YOUR_REGION` with the preferred region (e.g., `us-central1`).2. **Confirm Deployment**:
- Once the deployment is complete, you’ll see a URL where your Gradio app is hosted.### 5. Access Your Gradio App
- Open the URL provided in the deployment confirmation to access your Gradio app.
### 6. Clean Up Resources
- To avoid incurring charges, remember to delete your Cloud Run service and any other associated resources when you’re done testing.
#### Delete Cloud Run Service:
1. Navigate to **Cloud Run** in the Google Cloud Console.
2. Select your service and click **Delete**.### Additional Considerations
- **Memory and Scaling**: Adjust the memory limit and scaling settings during deployment if your app needs more resources.
- **Environment Variables**: Set any environment variables your app requires using the `--set-env-vars` flag during deployment.By following these steps, you should be able to successfully deploy your Gradio application on Google Cloud Platform using Cloud Run. If you encounter any issues, consult the [GCP documentation](https://cloud.google.com/docs) for further assistance.