Ai Coding Tools

How to Build a Simple Web App Using Machine Learning in Under 2 Hours

By BTW Team4 min read

How to Build a Simple Web App Using Machine Learning in Under 2 Hours

Building a web app with machine learning might sound daunting, but it doesn't have to be. If you’re an indie hacker or a solo founder, you might be thinking, “I don’t have time for this!” Well, I’m here to tell you that you can actually build a simple web app in under 2 hours using the right tools. In this guide, I’ll walk you through the entire process, share the tools we use, and highlight some of the trade-offs involved.

Prerequisites: What You Need Before You Start

Before diving into the development, make sure you have the following:

  • Basic knowledge of Python: This is crucial as most ML libraries are Python-based.
  • A code editor: I recommend Visual Studio Code or PyCharm.
  • An account on a cloud platform: Google Cloud, AWS, or Heroku are solid choices for hosting.
  • Familiarity with Git: Version control will save you headaches.

Step 1: Choose Your Machine Learning Model

First, you need to decide on a simple machine learning model that fits your web app idea. For instance, if you're building a sentiment analysis tool, a pre-trained model like TextBlob for NLP can be a great start.

Tool Recommendations for ML Models

| Tool | What It Does | Pricing | Best For | Limitations | Our Take | |---------------|------------------------------------------------|-----------------------------|---------------------------|-----------------------------------------|--------------------------------| | TensorFlow | Open-source ML framework for building models | Free | Custom models | Steep learning curve | We use this for custom models. | | scikit-learn | Simple tools for data mining and analysis | Free | Basic ML applications | Limited complex model support | Great for quick prototypes. | | TextBlob | NLP library for processing textual data | Free | Sentiment analysis | Not suitable for large datasets | Perfect for quick sentiment apps. | | Hugging Face | Pre-trained NLP models for various tasks | Free (with paid API limits) | Advanced NLP applications | Requires more setup for fine-tuning | We leverage it for advanced NLP. | | OpenCV | Computer vision library for image processing | Free | Image-based applications | Needs extensive knowledge for complex tasks | We don’t use it for web apps. |

Step 2: Set Up Your Web Framework

Next, you’ll need to pick a web framework to connect your ML model with a user interface. Flask is lightweight and easy to set up, making it ideal for quick projects.

Quick Setup Steps for Flask

  1. Install Flask: pip install Flask
  2. Create a new Python file (e.g., app.py).
  3. Set up a basic Flask app with the following code:
from flask import Flask, request, jsonify
app = Flask(__name__)

@app.route('/predict', methods=['POST'])
def predict():
    data = request.get_json()
    # Call your ML model here
    return jsonify({"prediction": "result"})

if __name__ == '__main__':
    app.run(debug=True)

Step 3: Deploy Your App

You can deploy your app to Heroku or Google Cloud. Here’s a quick overview of deploying to Heroku:

  1. Install the Heroku CLI.
  2. Create a new Heroku app: heroku create your-app-name.
  3. Push your code: git push heroku master.
  4. Open your app: heroku open.

Pricing Breakdown for Hosting

| Platform | Free Tier | Paid Plans | Best For | |---------------|-------------------------------|--------------------------------|---------------------------| | Heroku | Free tier for 550 hours/month | Starts at $7/month | Simple web apps | | Google Cloud | Free tier with credits | Pay-as-you-go pricing | Scalable projects | | AWS | 12-month free tier available | Pay-as-you-go pricing | Complex applications |

Step 4: Create a Simple Frontend

You can use HTML and JavaScript for a basic frontend. Here’s a simple example:

<!DOCTYPE html>
<html>
<head>
    <title>ML Web App</title>
</head>
<body>
    <h1>Predict with ML Model</h1>
    <input type="text" id="inputData">
    <button onclick="makePrediction()">Predict</button>
    <p id="result"></p>

    <script>
        async function makePrediction() {
            const response = await fetch('/predict', {
                method: 'POST',
                body: JSON.stringify({ text: document.getElementById('inputData').value }),
                headers: { 'Content-Type': 'application/json' }
            });
            const data = await response.json();
            document.getElementById('result').innerText = data.prediction;
        }
    </script>
</body>
</html>

Troubleshooting Common Issues

  • App not running: Check if you have all dependencies installed and that your Flask app is running.
  • Model not responding: Ensure your ML model is correctly integrated and that you're sending the right data format.
  • Deployment errors: Make sure your environment variables are set correctly on Heroku or whatever platform you're using.

Conclusion: Start Here

If you want to build a simple web app using machine learning in under 2 hours, start with Flask and a pre-trained model. Focus on a specific use case to keep things manageable. It’s entirely possible to get something functional up and running quickly, even if it means making some sacrifices in terms of features or complexity.

What We Actually Use

In our experience, we use Flask for web frameworks, TensorFlow for custom models, and deploy on Heroku for quick setups. This stack keeps our projects lean and efficient.

Follow Our Building Journey

Weekly podcast episodes on tools we're testing, products we're shipping, and lessons from building in public.

Subscribe

Never miss an episode

Subscribe to Built This Week for weekly insights on AI tools, product building, and startup lessons from Ryz Labs.

Subscribe
Ai Coding Tools

How to Code a Web App in 48 Hours Using AI Tools

How to Code a Web App in 48 Hours Using AI Tools (2026) Building a web app in just 48 hours sounds like a pipe dream, right? But with the right AI tools, it’s not only possible but

Apr 17, 20264 min read
Ai Coding Tools

Top 3 AI Coding Tools: Cursor vs GitHub Copilot vs Codeium

Top 3 AI Coding Tools: Cursor vs GitHub Copilot vs Codeium (2026) As an indie hacker or solo founder, you know time is money. When it comes to coding, AI tools can either save you

Apr 17, 20263 min read
Ai Coding Tools

How to Build Your First App with AI Coding Tools in Just 10 Days

How to Build Your First App with AI Coding Tools in Just 10 Days Building your first app can feel like climbing a mountain. The skills, the tools, the endless learning curves—it's

Apr 17, 20264 min read
Ai Coding Tools

How to Use AI Tools to Write Your First Program in Under 2 Hours

How to Use AI Tools to Write Your First Program in Under 2 Hours Feeling overwhelmed by the idea of coding your first program? You’re not alone. Many aspiring builders hit a wall w

Apr 17, 20264 min read
Ai Coding Tools

Cursor vs GitHub Copilot: Which AI Tool is the Best for Solo Developers in 2026?

Cursor vs GitHub Copilot: Which AI Tool is the Best for Solo Developers in 2026? As a solo developer, you often find yourself juggling multiple roles: coding, debugging, and even p

Apr 17, 20264 min read
Ai Coding Tools

How to Integrate GPT-4 into Your Development Workflow in Under 2 Hours

How to Integrate GPT4 into Your Development Workflow in Under 2 Hours Integrating GPT4 into your development workflow can seem daunting, especially if you’re a solo founder or indi

Apr 17, 20263 min read