C22-098-Fruity-Website
C22-098-Fruity-Website copied to clipboard
π Capstone Project of MSIB Dicoding 2022 Cycle 3. We plan to build a machine learning model to predict fresh fruit. That way, users are expected to be able to easily separate between fresh and rotten...
Fruity App by C22-098
π€ Fruity helps you quickly identify rotten fruit, saving you the hassle of sorting to get fresh fruit.
π Demo Link
In this project, we initially used Railway as a hosting platform for our application. But Railways have limited access. Alternatively, you can visit https://itsfruity.onrender.com/ if the service in https://itsfruity.up.railway.app/ is no longer available.
Click here to view Fruity website
π Table of Contents
- Introduction
- Demo Link
- Table of Contents
-
About Fruity
- Background
- Goal & Aim
-
Quickstart
- Built Using
- Prerequisite
- Installation & Get Started Project
- Deploy Machine Learning Model with Flask
- How Does the Inference Work?
- Project Management Plan
- Project Repository Structure
- Project Resources
- Academic Paper & References
- Support
- Contributing
- Acknowledgments
πΏ About Fruity
Fruity is a website-based machine learning program which is currently under development process for the Capstone Project of Certified Independent Study of MBKM Dicoding Cycle 3 from Machine Learning & Front End Web Development learning path.
π‘Background
Horticulture is an agricultural sub-sector which is important contribution to agriculture in Indonesia. In 2020, the value of horticultural exports increased by 37.75% compared to 2019. This increase was dominated by fruit commodities during the 2020 COVID-19 pandemic. This indicates that fruits have a high level of demand. Assessment of fruit quality is a major challenge in the agricultural sector. Controlling the external quality of fruit manually may be possible. However, it will take a long time and have implications for productivity. Based on the problems above, we propose a website-based classification system "Fruity" to help identify rotten fruit as a first step for quality control in fruit commodities.
π― Goal & Aim
This website aims to help everyone (especially fruit growers and fruit sellers) as an utility to help identify fresh and rotten fruits by uploading the image of the fruits. This feature is expected to increase productivity in detecting defects in agricultural fruits.
β‘οΈ Quickstart
This section will explain the steps for installing and deploying Fruity to a web service with a short code. This process is divided into 3 parts, the first one introduction and prerequisites, the second is creating the Flask project itself, and the last is the hosting process on the platform as a service. Fyi, initially, we used Heroku. Sadly, since today (starting November 28, 2022), Heroku has eliminated all free services. We are using other alternative platforms, one of which is Fly.io and Railway. In the project, we use Railway. But, Railway has drawbacks, access is limited to 500 hours of use. Therefore, we're looking into how to set up Fly.io as a backup host.
π¦ Built Using
Fruity is a web-based machine learning program developed by training models using the end-to-end machine learning platform, TensorFlow. And then, the trained model is connected to the web server using Flask.
π¨ Prerequisite
- Python, one of the top machine learning and AI programming languages.
- Tensorflow, The core open-source library to help you develop and train ML models. in this package there is Keras. Keras is a deep learning API written in Python, running on top of the machine learning platform TensorFlow.
- Flask, Flask is a web application framework written in Python.
βοΈ Installation & Get Started Project
This step, steps to creating Flask project and setting up in the development environment, which is running on a local server.
𧡠Installation of the Project to Virtual Environment
To be able to push it into a stand-alone virtual environment, follow this step. If you have already done this, step to the next step.
-
Clone this repository
$ git clone https://github.com/nurmuhimawann/C22-098-Fruity-Website.git
-
Install Python Virtual Environment
$ virtualenv venv
-
Install All the Requirements Inside "requirements.txt"
$ pip install -r requirements.txt
-
Create Flask App Environment Variables & Run Server
$ env:FLASK_APP = "wsgi" $ flask run
-
Open URL referencing LocalHost in your browser
π Yeaay, Congrats. The web app is successfully running on the local server. If you want the application accessible on the internet, you must deploy this app to a web service platform. Let's go to the next step π.
π Deploy Machine Learning Model with Flask
Annotation
You don't have to use both. Just choose either Fly.io or Railway.
Click on the triangle icon to expand
Fly.io
-
Install Flyctl
On OS windows, Run the Powershell install script.
$ iwr https://fly.io/install.ps1 -useb | iex
-
Login Fly.io
If itβs your first time using Fly.io, youβll need to sign up for an account.
$ flyctl auth signup
If you already have a Fly.io account, all you need to do is sign in with flyctl. Simply run:
$ flyctl auth login
-
Configure the App for Fly
Each Fly application needs a
fly.toml
file to tell the system how we'd like to deploy it. That file can be automatically generated.$ flyctl launch
-
Deploying to Fly
$ flyctl deploy
-
Viewing the Deployed App
You can see, the application has been assigned with a DNS hostname.
$ flyctl status
-
Connecting to the App
This will open a browser on the HTTP version of the site.
$ flyctl open
And thatβs it! This is everything, now your web application accessible on the internet. Congrats π
Railway App

This is the easiest way to deploy a web application to a railway because you don't need to type commands on the CLI like Fly.io.
-
Prerequisite
You need GitHub and Railway account. If this is your first time using GitHub and Railway, you will need to register both GitHub and Railway. If you already have a Github and Railway account, Make sure to connect your Railway account to GitHub.
-
Forking a GitHub Repository
If you have this project in your repository, you can skip this step and proceed to the next step. But, if you don't have it yet, you can go to GitHub, navigate to the nurmuhimawann/C22-098-Fruity-Website repository. In the top-right corner of the page, click Fork.
-
Go to your railway dashboard and click on
New Project
Button. -
Select the option
Deploy from GitHub repo
-
Provide Railway app to access your GitHub repositories.
-
Soon, your project should be live.
On your dashboard, you can see the application has been assigned with a DNS hostname.
Every time we make changes in our repo, the app will be redeployed. And thatβs it. Your project has been completely deployed on Railway and is easily available for public use! Congrats π
β How Does the Inference Work?
- User uploads an image to web application.
- Gets the user input of images from Flask pages. After that, the application checks file extension to ensure that file uploaded is an image. The uploaded image is stored at
static/user_uploads
folder. - App extract the image's path.
- Load the images using tf.keras.utils.load_img(img_path, target_size=(150, 150)). This function is applied to load image from specified path for preparation before applying image classification. The image is resized into 150x150px resolution.
- Because the model can't classify images directly in the initial extension. So, the image is converted first into an array of integers using tf.keras.utils.img_to_array(img).
- Expand the dimension of the array in input Tensor using tf.expand_dims(img_array, axis=0).
- Use the model to predict the array's class using fresh_rotten_model.predict(img_array). This function returns an array of model's confidence of each label. From the array, the index of maximum value is fetched using np.argmax(prediction).
- Cast the label of the prediction using fresh_rotten_label(prediction) to get the result. This integer value is converted into a string based on the JSON labels that matches the value. And the final result will display the predicted, such as βFresh Applesβ, "Rotten Apples" etc.
π Project Management Plan
-
Project Brief Document
ποΈ Project Repository Structure
ποΈ Project Structure
<Main Repository>
.
βββ app/ # App Modules
β βββ models/ # the place where machine learning models are saved
β β βββ image_dir # test image files
β β βββ label_dir # json label dictionary
β β βββ model_dir # models hdf5
β βββ static/ # the place where JS,Images and CSS files are saved
β β βββ css # CSS files
β β βββ data # JSON files
β β βββ fonts # Fonts files
β β βββ img # Image files
β β βββ js # Javascripts files
β β βββ user_uploads # Store uploaded Files by users
β βββ templates/ # the place pages & components files are saved
β β βββ includes # Page chunks, components
β β βββ layouts # App Layouts (the master pages)
β βββ __init__.py # the place where flask app are initialized
β βββ application.py # Bundle all above sections, routing and expose the Flask APP
βββ datasets # links datasets
βββ notebooks # baseline models .ipynb
βββ readme-assets # Contains thumbs used in documentation (README.md)
βββ .gitignore # Specifies file intentionally untracked files
βββ Procfile # List of process types in an app
βββ README.md # Information about a repository
βββ requirements.txt # Application dependencies
βββ runtime.txt # Specify the version of Python
βββ set-env.txt # Setting for enviroment python
βββ wsgi.py # Start the app in development and production
πΎ Project Repository & Branch
This repository is divided into a main and two development branches as follows:
-
Main Branch (main)
Main branch is used as an integration between fe-development and ml-development. The flask framework is used to build and integrate models with the front-end.
-
Front-End Development Branch (fe-development)
A branch used exclusively for front-end development. In its development, written in HTML, CSS, and JS.
-
Machine Learning Development Branch (ml-development)
A branch is used exclusively for machine learning development. It's written in Jupyter Notebook using most libraries like Keras and Tensorflow.
π Project Resources
Progamming Languange
Datasets:
-
Fruits Fresh & Rotten for Classifications:
https://www.kaggle.com/datasets/sriramr/fruits-fresh-and-rotten-for-classification/
Framework, Library & Utility:
-
Colaboratory Notebooks
https://colab.research.google.com/
-
Fly.io
https://fly.io/
-
Railway
https://railway.app/
-
Font Awesome
https://fontawesome.com/
-
Ionicons
https://ionic.io/ionicons
Design Tools:
-
Pexels
https://www.pexels.com/
-
Unsplash
https://unsplash.com/
Project Management Tools:
-
Asana
https://app.asana.com/
-
Project Libre
https://www.projectlibre.com/
π Academic Paper & References
-
A. Kumar, R. C. Joshi, M. K. Dutta, M. Jonak and R. Burget, "Fruit-CNN: An Efficient Deep learning-based Fruit Classification and Quality Assessment for Precision Agriculture," 2021 13th International Congress on Ultra Modern Telecommunications and Control Systems and Workshops (ICUMT), 2021, pp. 60-65, doi: 10.1109/ICUMT54235.2021.9631643.
-
Cortez, Atreyu Jasper Laxa.(2021)."Deploying Machine Learning Models Into A Website Using Flask". Accessed from https://towardsdatascience.com/deploying-machine-learning-models-into-a-website-using-flask-8582b7ce8802 on October, 23 2022 at 18.00 WIB.
-
Kemenko Perekonomian. (2021)."Pengembangan Hortikultura Berorientasi Ekspor Tingkatkan Produktivitas, Kualitas, dan Kontinuitas Produk Hortikultura". Accessed from https://www.ekon.go.id/publikasi/detail/3358/pengembangan-hortikultura-berorientasi-ekspor-tingkatkan-produktivitas-kualitas-dan-kontinuitas-produk-hortikultura on October, 23 2022 at 18.00 WIB.
-
Maulana, Febian Fitra dan Rochmawati, Naim,β Klasifikasi Citra Buah Menggunakan Convolutional Neural Network,β Journal of Informatics and Computer Science, vol. 01, no. 02 pp. 2686-2220 2019, doi: 10.26740/jinacs.v1n02.p104-108.
-
Naik, Sapan & Patel, Bankim. (2017). Machine Vision based Fruit Classification and Grading - A Review. International Journal of Computer Applications. 170. 22-34. 10.5120/ijca2017914937.
-
Sena, Samuel. (2017)." Pengenalan Deep Learning Part 7: Convolutional Neural Network (CNN)". Accessed from https://medium.com/@samuelsena/pengenalan-deep-learning-part-7-convolutional-neural-network-cnn-b003b477dc94 on October, 23 2022 at 18.00 WIB.
π Like this project ?
Leave a β If you think this project is cool.
π₯ Contributing
Sarah Salsabilla - Our lovely adviser
Thank you for being such an amazing advisor! You are so understanding, kind and helpful. we very lucky to have you as our advisor teams, and you give a lot of help. A thousand words cannot express our gratitude to you. we really really appreciate you! Thanks kak.
Nur Muhammad Himawan - Team Leader
Putri Nur Aini Mahfudz - Machine Learning Developer
Laily Farkhah Adhimah - Machine Learning Developer
Mohamad Ilman Huda - Front-End Web Developer
π Acknowledgements
- Dicoding Academy
- My Supervisor - Mr. Fahrobby Adnan, S.Kom.,MMSI
- My Advisor - Sarah Salsabilla
- My Mentor - Ahmad Sholihin
- M05 Class
- Inspiration
- References