{"slug": "build-a-web-app-for-your-machine-learning-model", "title": "Build a Web App for Your Machine Learning Model", "summary": "MLJAR AutoML and Mercury now enable developers to build web applications for machine learning models using only Python, eliminating the need for HTML, CSS, or JavaScript. The new tool generates two types of web apps — one for single predictions via a form and another for batch predictions through CSV uploads — making machine learning models accessible to non-technical users.", "body_md": "# Build a Web App for your Machine Learning model\n\nYour Machine Learning model is ready. What should you do next? You can save the model and use it in Python. You can create an API. You can add the model to an existing application. There are many ways to [make predictions with a Machine Learning model](https://mljar.com/blog/make-predictions-with-machine-learning-model/).\n\nIn this tutorial, I will show you a beginner-friendly option: we will build a Web App for a Machine Learning model.\n\nThe best part? You don't need to write HTML, CSS, or JavaScript. Only Python.\n\nWe will train a Machine Learning model with [MLJAR AutoML](https://github.com/mljar/mljar-supervised), automatically generate a Web App with `app()`\n\n, and then publish the app online with [MLJAR Platform](https://platform.mljar.com/). The generated application is created with [Mercury](https://github.com/mljar/mercury), a framework for building web apps from Python notebooks.\n\nIn the final result, we will have two web apps:\n\n- An app for single prediction, where the user fills the form and gets one prediction.\n- An app for batch prediction, where the user uploads a CSV file and gets predictions for many rows.\n\nYou can find the full code and results in my GitHub repository:\n\n[https://github.com/pplonski/web-app-from-machine-learning-model](https://github.com/pplonski/web-app-from-machine-learning-model)\n\n## What will we build?\n\nIn this tutorial, we will build an application for predicting medical insurance charges. The model will use patient demographic and health related factors, such as:\n\n- age,\n- sex,\n- BMI,\n- number of children,\n- smoking status,\n- region.\n\nThe target value is `charges`\n\n, which means medical insurance charges. This is a regression problem because we predict a number.\n\nWe will use MLJAR AutoML to train the model. AutoML will automatically check different Machine Learning algorithms, compare their performance, and select the best model. After training, we will generate a Web App from the trained model.\n\nThis is useful because many people don't want to work directly with Python code. They prefer a simple web interface. For example, your boss, client, doctor, researcher, or business teammate can open a link, enter values, and get the prediction.\n\n## Why create a Web App for a Machine Learning model?\n\nTraining a Machine Learning model is only one part of the project. The second part is making the model useful. If your model is hidden in a Python script or notebook, only technical users can use it. It is hard to share it with people who don't know Python.\n\nA Web App solves this problem. You can give users a nice interface where they can:\n\n- enter input values,\n- run prediction,\n- upload CSV files,\n- download results,\n- use the model without touching code.\n\nThis is a very practical way to share Machine Learning models. In many projects, this can be enough to show a prototype, test an idea, or collect feedback from users.\n\n## Install packages\n\nWe need two Python packages:\n\n```\npip install mljar-supervised mercury\n```\n\nThe `mljar-supervised`\n\npackage is used to train the Machine Learning model. The `mercury`\n\npackage is used to run the generated Web App.\n\nThe `requirements.txt`\n\nfile in the repository has only these two packages:\n\n```\nmljar-supervised\nmercury\n```\n\n## Project structure\n\nThe project repository contains the following files and directories:\n\n```\nweb-app-from-machine-learning-model/\n├── AutoML_App/\n├── AutoML_Results/\n├── data/\n├── media/\n├── requirements.txt\n└── train_automl.py\n```\n\nThe most important file is:\n\n```\ntrain_automl.py\n```\n\nIt trains the model and generates the Web App. The `data`\n\ndirectory contains the training and test data. The `AutoML_Results`\n\ndirectory contains the results from MLJAR AutoML training. The `AutoML_App`\n\ndirectory contains the generated Web App.\n\nYou don't need to manually write the web application. MLJAR AutoML generates it for you.\n\n## Load data\n\nLet's start with loading the data.\n\n``` python\nimport pandas as pd\n\ndf = pd.read_csv(\"data/train.csv\")\n```\n\nThe dataset contains patient information and medical insurance charges. The target column is `charges`\n\n. This is the value that we want to predict.\n\nWe split the data into input features and target:\n\n```\nX_train = df.drop(columns=[\"charges\"])\ny_train = df[\"charges\"]\n```\n\nThe `X_train`\n\nvariable contains all input columns. The `y_train`\n\nvariable contains the target column.\n\n## Train Machine Learning model with MLJAR AutoML\n\nNow we can train the model.\n\n``` python\nfrom supervised import AutoML\n\nautoml = AutoML(\n    results_path=\"AutoML_Results\",\n)\n\nautoml.fit(X_train, y_train)\n```\n\nThat's all. MLJAR AutoML will automatically detect that this is a regression task. It will train several models and compare their results.\n\nIn this example, AutoML checks models like:\n\n- Baseline,\n- Linear model,\n- Decision Tree,\n- Random Forest,\n- Xgboost,\n- Neural Network,\n- Ensemble.\n\nThe training output from this project shows that the best model is an Ensemble model.\n\nYou don't need to manually test all these algorithms. AutoML does it for you and saves the full report in the `AutoML_Results`\n\ndirectory. This is very helpful for beginners because you can focus on the problem and the data, not on writing a lot of training code.\n\n## Generate Web App automatically\n\nNow comes the most interesting part.\n\nWe will generate a Web App from the trained AutoML model.\n\n```\nautoml.app(\n    path=\"AutoML_App\",\n    title=\"Insurance Charges Predictor\",\n)\n```\n\nThis command creates a ready-to-use Web App. The app is generated in the `AutoML_App`\n\ndirectory.\n\nYou don't need to write frontend code. You don't need to create forms manually. You don't need to design the layout. MLJAR AutoML creates the app based on your trained model and input data. The generated app is created with Mercury. Mercury can serve Python notebooks as web applications, so the final app is still based on Python.\n\n## What files are generated?\n\nAfter running `automl.app()`\n\n, the `AutoML_App`\n\ndirectory contains files like:\n\n```\nAutoML_App/\n├── app_support.py\n├── automl.zip\n├── config.toml\n├── mljar_app.json\n├── predict_batch.ipynb\n├── predict_single.ipynb\n├── requirements.txt\n└── runtime.txt\n```\n\nThe most important notebooks are:\n\n```\npredict_single.ipynb\npredict_batch.ipynb\n```\n\nThe `predict_single.ipynb`\n\nnotebook is used for single prediction. The `predict_batch.ipynb`\n\nnotebook is used for batch prediction from a CSV file. The `automl.zip`\n\nfile contains the model runtime files needed to make predictions. The `requirements.txt`\n\nfile contains Python packages needed to run the app.\n\nMercury page view with both applications:\n\n## Single prediction app\n\nThe first generated app is for single prediction. In this app, the user can enter values in a form, for example:\n\n- age,\n- sex,\n- BMI,\n- number of children,\n- smoking status,\n- region.\n\nAfter the user changes any value in the form, the prediction is updated automatically. This makes the app very interactive. You can change the input values and immediately see how they affect the predicted medical insurance charges.\n\nThis type of app is great when someone wants to check one case at a time. For example, a non-technical user can open the app in the browser, fill in the form, and get the prediction without writing any Python code.\n\nThe app also shows more information about the prediction. For each input value, we display how it compares with the training data distribution. This helps the user understand whether the selected value is typical or unusual compared to the data used to train the model.\n\nAdditionally, the app displays a feature importance plot. This plot shows which features had the biggest impact on the model predictions. It is useful because the user can better understand what the model is using to make its decision.\n\nSo the single prediction app is not only a simple prediction form. It also gives extra context and helps explain the model behavior.\n\n## Batch prediction app\n\nThe second generated app is for batch prediction. In this app, the user uploads a CSV file with many rows. The app computes predictions for all rows and returns a file with results. This is very useful when users already have data in a spreadsheet or CSV file. For example, they can prepare a file like this:\n\n```\nage,sex,bmi,children,smoker,region\n19,female,27.9,0,yes,southwest\n35,male,30.5,1,no,northwest\n52,female,31.2,2,no,southeast\n```\n\nThe app will add predictions for each row. User can download computed predictions with `Download predictions`\n\nbutton.\n\n## Run the Web App locally\n\nYou can run the generated app locally with Mercury. Go to the generated app directory:\n\n```\ncd AutoML_App/app\n```\n\nInstall dependencies:\n\n```\npip install -r requirements.txt\n```\n\nStart Mercury:\n\n```\nmercury\n```\n\nMercury will start a local server. You can open the app in your browser and test it on your computer. This is a good step before publishing the app online. You can check if the form works, if the predictions are correct, and if the batch CSV upload works as expected.\n\nThere is also a helper function in MLJAR AutoML:\n\n```\nautoml.local_app()\n```\n\nIt can generate and start the local app directly from Python code.\n\n## Publish the Web App online\n\nRunning locally is nice, but sharing a local app with other people is not easy. The easiest way to publish the app online is to use MLJAR Platform. You can publish the app with one Python command:\n\n```\nautoml.publish_app()\n```\n\nIn the repository, this line is commented:\n\n```\n# automl.publish_app()\n```\n\nTo publish the app, remove the `#`\n\nand run the script. The expected output from publish is:\n\n```\nStart app publish\nCreating app workspace\nSigning in to MLJAR platform\nCreating app URL\nCreated app URL: https://model-forge-5fbd.ismvp.org\nUploading file: predict_single.ipynb\nUploading file: predict_batch.ipynb\nUploading file: app_support.py\nUploading file: mljar_app.json\nUploading file: config.toml\nUploading file: requirements.txt\nUploading file: runtime.txt\nUploading file: automl.zip\nFinished. You can access your app at: https://model-forge-5fbd.ismvp.org\n```\n\nMLJAR AutoML will upload the generated application files to MLJAR Platform and create a URL for your app. You can open [MLJAR Platform](https://platform.mljar.com) and inspect your web app:\n\nYou can list all uploaded files:\n\nAfter publishing, you can share the link with other people. They can open the app in the browser and use your Machine Learning model without installing Python. This is very convenient when you want to share your model with: clients, teammates, business users, researchers, students, friends.\n\n## Full training script\n\nHere is the full script used in this tutorial:\n\n``` python\nimport pandas as pd\n\nfrom supervised import AutoML\n\n# Read data\ndf = pd.read_csv(\"data/train.csv\")\n\nX_train = df.drop(columns=[\"charges\"])\ny_train = df[\"charges\"]\n\n# Train AutoML\nautoml = AutoML(\n    results_path=\"AutoML_Results\",\n)\n\nautoml.fit(X_train, y_train)\n\n# Create App\nautoml.app(\n    path=\"AutoML_App\",\n    title=\"Insurance Charges Predictor\",\n)\n\n# Start App locally\n# automl.local_app()\n\n# Deploy App on platform.mljar.com\n# automl.publish_app()\n```\n\nIt is a short script, but it does a lot:\n\n- Loads the data.\n- Splits features and target.\n- Trains Machine Learning models.\n- Saves AutoML results.\n- Generates a Web App.\n- Optionally starts the app locally.\n- Optionally publishes the app online.\n\nThis is why I like this workflow. It keeps the project simple.\n\n## Important note about generated apps\n\nThe Web App is generated automatically. This means that you don't need to manually write the app code. You can focus on the Machine Learning part. Of course, advanced users can later open the generated files and customize them. But for beginners, the default generated app is already very useful. It gives you a working interface for single and batch predictions. For many projects, this is enough to show your model to other people and collect feedback.\n\n## When should you use this approach?\n\nThis approach is good when you want to quickly share a Machine Learning model.\n\nYou can use it for:\n\n- model demos,\n- proof of concept projects,\n- internal tools,\n- educational projects,\n- client presentations,\n- small business applications,\n- research prototypes.\n\nIt is especially useful when the users of the model are not Python developers. Instead of sending them a notebook or Python script, you can send them a link to a Web App.\n\n## Summary\n\nIn this tutorial, we trained a Machine Learning model and created a Web App for predictions. We used MLJAR AutoML to train the model. The model predicts medical insurance charges based on patient information.\n\nThen we used `automl.app()`\n\nto automatically generate a Web App.\n\nThe generated app contains two useful prediction interfaces:\n\n- Single prediction app for one sample.\n- Batch prediction app for CSV files.\n\nWe also saw how to run the app locally with Mercury and how to publish it online with: `automl.publish_app()`\n\nThe full code is available on GitHub:\n\n[https://github.com/pplonski/web-app-from-machine-learning-model](https://github.com/pplonski/web-app-from-machine-learning-model)\n\nThis workflow is beginner-friendly because you don't need to write frontend code. No HTML. No CSS. No JavaScript. Only Python. Happy predicting!\n\n## AI Data Analyst on Your Computer\n\nUse MLJAR Studio to explore data, find insights, and create reports with AI. Everything runs locally, so your data stays with you.", "url": "https://wpnews.pro/news/build-a-web-app-for-your-machine-learning-model", "canonical_source": "https://mljar.com/blog/web-app-machine-learning/", "published_at": "2026-06-12 11:43:34+00:00", "updated_at": "2026-06-12 11:50:25.260021+00:00", "lang": "en", "topics": ["machine-learning", "mlops", "ai-tools", "ai-products"], "entities": ["MLJAR AutoML", "MLJAR Platform", "Mercury", "GitHub", "pplonski"], "alternates": {"html": "https://wpnews.pro/news/build-a-web-app-for-your-machine-learning-model", "markdown": "https://wpnews.pro/news/build-a-web-app-for-your-machine-learning-model.md", "text": "https://wpnews.pro/news/build-a-web-app-for-your-machine-learning-model.txt", "jsonld": "https://wpnews.pro/news/build-a-web-app-for-your-machine-learning-model.jsonld"}}