Render is a cloud-based Platform as a Service (PaaS) that enables seamless deployment, management and scaling of machine learning models and applications. With built-in support for web services and APIs, Render provides an efficient way to host and run ML models online.
Render provides free plans for deploying small projects and prototypes.
Deployment is simple and requires minimal setup.
It supports integrations with databases, APIs and other services for fully functional applications.
Before deployment, the machine learning code should be organized and the trained model should be saved so it can be loaded in your web app. This ensures that Render can run your app without retraining the model every time.
Save the trained model using libraries like pickle, joblib or torch.save depending on your framework.
Organize your code so the app can easily load the model, handle inputs and return predictions.
A Flask app serves as the interface between your saved machine learning model and the web. It handles user inputs, loads the trained model, and returns predictions to the client or browser.
Create a Python script (e.g., app.py) and import Flask along with your ML libraries.
Load the saved model (pickle, joblib, or torch) at the start of the app.
Define routes (e.g., /predict) that accept input data, pass it to the model, and return the prediction.
Add a HTML form with CSS styling or a JSON API endpoint to allow users to interact with the model through a web interface.
Run the application using python app.py to test it locally.
We build a Flask application that loads the trained model, processes user input and returns predictions. It shows how the model is integrated with a web interface for real-time interaction.
Step 4: Create requirements.txt File
A requirements.txt file is needed to list all the dependencies used in the project so that Render can install them during deployment. This ensures the application runs correctly in the cloud environment. Generate the file using the command:
pip freeze > requirements.txt
After generating the file, add this line as well in requirements.txt file:
gunicorn==21.2.0
Make sure all required libraries are included and unnecessary packages are removed if needed.
Step 5: Push Code to GitHub
Your project needs to be uploaded to a GitHub repository so Render can access and deploy it. This also helps in version control and managing updates easily. Initialize Git and push your code using:
Output:
Step 6: Connect GitHub and Deploy on Render
Here we connect GitHub repository to Render and configuring the service for deployment. Once the setup is complete, Render builds and hosts the application, making it ready to go live.
In Render, click on βNew +β and select βWeb Serviceβ to start the deployment process. This allows you to connect your GitHub repository and configure your application for deployment.
After selecting Web Service, connect your GitHub repository to Render. This allows Render to access your project files and prepare them for deployment.
Step 7: Configure New Web Service
After connecting the repository, configure the settings in the βNew Web Serviceβ section. These options define how your application will be built and run on Render.
Name: Enter a unique name for your web service.
Environment: Select the runtime (e.g., Python).
Region: Choose the server location for deployment.
Branch: Select the branch to deploy (e.g., main).
Build Command: pip install -r requirements.txt to install dependencies.
Start Command: gunicorn app:app to run the Flask app.
Instance Type: Choose free or paid plan based on your needs.
After configuring all settings, choose the instance type and deploy your application. This step starts the build process and makes your app live on Render.
Select the Free instance for basic projects or a paid plan for better performance.
Click on Deploy Web Service to start the deployment process.
After clicking deploy, Render automatically installs all dependencies and sets up the environment for your project. This process prepares your application to run smoothly in the cloud.
Render runs the build command to install all libraries from requirements.txt.
The platform sets up the runtime environment and initializes your application.
Deployment logs can be checked to ensure all dependencies are installed correctly.
Once the deployment process is complete, your application is successfully hosted on Render. It can now be accessed from anywhere using the generated URL.
Open the provided URL from the Render dashboard to view your application.