The power to jot down your personal packages was one among my all-time-favorite desires and it seamed to me like magic that you can simply consider one thing you want and go create it. Sadly, mixture of my aversion to math (math lecturers, to be exact) and tendency to procrastinate in each tough scenario (which is what programming is all about) held me again from studying any programming language past the very fundamentals. I simply gave as much as simply and satisfied myself that I’m simply not good sufficient to study it.
Then ChatGPT confirmed up and turned my world round. It was like a crutch that assist me step over that barrier of entry into the world of constructing. It match completely with me and my want to search out the solutions proper now or surrender. It didn’t reduce my procrastination habits however it boiled them right down to the minimal.
However with ChatGPT 4o issues obtained bizarre. It turned out that it’s so good at writing code that now I had a software at my disposal that may actually spit out completed (nicely, semi-finished) merchandise for each thought I’ve. I simply want to have the ability to clarify what I would like and immediate it to information me over obstacles I don’t but perceive. I didn’t cease studying easy methods to code however my objective now’s to learn to learn code, to not write it myself from scratch. I firmly consider that to be a approach of the longer term. Means to specific your must AI can be our new programming language.
That brings us to the subject of this text. I needed to point out you the way straightforward it’s to make purposes with the assistance of ChatGPT (or another high-end LLM that’s good with writing code).
What I’ll do as an indication is to make a face recognition internet utility that is ready to undergo all my picture recordsdata and discover matching images primarily based on some reference images I present (on this case, ma late father).
You are able to do it as a python script however app with consumer interface is rather more interesting so we’ll go along with that 🙂 This venture is approach over my head as a programmer. I do assume I may make it myself however it could take me weeks to determine it out. Fortunately I do have entry to ChatGPT 4o.
By the best way, for those who discovered any of this fascinating and wish to study extra, focus on potential initiatives, or simply join, be happy to achieve out to me on LinkedIn.
- Connect with me on LinkedIn
- Take a look at my YouTube
- My initiatives on Github
- Any clap/comply with for this text helps me out!
There are couple of issues to determine proper in the beginning. These are the principles and it’s good to have them to steer ChatGPT’s output in a course you need.
These are my guidelines:
1. I would like this utility to be construct in Python as a result of it’s the one programming language I understand how to learn
2. I would like the app to be an internet app and for comfort I would like it to be written utilizing streamlit and deepface libraries (that is the place even primary data of a language can come in useful since you give the output clear course)
3. I would like the app to have three dialogues that the consumer can fill in in order that the app can be utilized extra then as soon as:
a. Reference folder — that’s the place you’ll put your reference images
b. Output folder — the place the app will copy matched images
c. Scan folder — beginning folder of your photograph assortment
d. Lastly, I would like the app to have a progress bar or one thing that signifies progress
With all that found out now it’s time to jot down a immediate.
For the immediate I simply transformed all the principles above into a little bit story for the ChatGPT and made certain to inform it to information me each step of the best way.
I would like you to create an internet app utilizing streamlit that makes use of deep face facial recognition library to undergo my picture folders and recordsdata and finds all the pictures of my father. I’ll give you a reference pictures within the reference folder. The app ought to have three enter dialogues the place consumer can browse to the reference folder, output folder and to the folder that accommodates his picture recordsdata and sub-folders. The app also needs to have a strategy to present progress of the scan and in addition be sure that that there’s a begin button and a cease button in order that the consumer can cease the scan if he desires to. I’m a whole newbie and I want your assist each step of the best way. Inform me what folders to create for this venture and what recordsdata go by which folder. Additionally, inform me what code goes by which file.
Whereas not good, this immediate was adequate to get me the entire construction of the venture with clear directions what folders, dependencies and recordsdata I have to create for this app:
Challenge Construction:
— Create the principle venture folder, e.g., `facial_recognition_app`.
— Inside this folder, create the next subfolders and recordsdata:
— `app.py`: The principle Streamlit app.
— `necessities.txt`: To checklist all dependencies.
— `utils.py`: For utility capabilities like scanning folders and performing facial recognition.
— `reference_images/`: Folder to retailer reference pictures.
— `image_files/`: Folder to retailer pictures to be scanned.
— `output/`: Folder to retailer output outcomes.
Dependencies:
— You will want to put in Streamlit, DeepFace, and different needed libraries.
Code Implementation:
`necessities.txt`
`app.py`
`utils.py`
It even gave me a visible model for the folder construction:
facial_recognition_app/
│
├── app.py
├── necessities.txt
├── utils.py
├── reference_images/
│
├── image_files/
│
└── output/
With a transparent approach ahead I simply needed to comply with the “recipe” and prepare dinner up this app 🙂
It’s value mentioning that the primary model of the code did have an error, it seams prefer it didn’t embody tf-keras within the first model of dependencies so I needed to copy the error and feed it again to ChatGPT in order that it may repair it and produce me a revised model of the code. It was actually only a minor factor and the second model of the code labored like a appeal.
Anyway, I began with the creation of the digital surroundings (since this can be a stroll by, I’ll simply present each step)
python -m venv venv
venvScriptsactivate
Subsequent step was to put in the dependencies.
For this I created the **necessities.txt** doc like I used to be instructed to by ChatGPT and pasted a listing of dependencies within the file:
streamlit
deepface
pandas
opencv-python-headless
tf-keras
You may set up all of this manually one-by-one however that’s the entire cause you will have necessities file so you’ll be able to set up it in a neater approach:
pip set up -r necessities.txt
There! Now we’ve every thing arrange and we’re able to go.
This app consists of two recordsdata, ‘utils.py’ and ‘app.py’
Utils.py: This file accommodates utility capabilities for loading pictures, performing facial recognition, and dealing with the progress
import os
from deepface import DeepFace
import cv2def load_images_from_folder(folder):
pictures = []
for root, dirs, recordsdata in os.stroll(folder):
for file in recordsdata:
if file.endswith(('jpg', 'jpeg', 'png')):
pictures.append(os.path.be part of(root, file))
return pictures
def find_facial_matches(reference_img_path, images_folder, output_folder, update_progress):
reference_img = cv2.imread(reference_img_path)
pictures = load_images_from_folder(images_folder)
matched_images = []
total_images = len(pictures)
for idx, img_path in enumerate(pictures):
img = cv2.imread(img_path)
end result = DeepFace.confirm(img, reference_img, enforce_detection=False)
if end result['verified']:
matched_images.append(img_path)
output_path = os.path.be part of(output_folder, os.path.basename(img_path))
cv2.imwrite(output_path, img)
update_progress((idx + 1) / total_images)
return matched_images
Now when we’ve a toolbox, now we want the principle app that can run the streamlit utility.
App.py:
import streamlit as st
import os
from utils import find_facial_matchesdef principal():
st.title('Facial Recognition App')
st.sidebar.header('Folders')
reference_folder = st.sidebar.text_input('Reference Folder')
images_folder = st.sidebar.text_input('Pictures Folder')
output_folder = st.sidebar.text_input('Output Folder')
if st.sidebar.button('Begin Scan'):
if not reference_folder or not images_folder or not output_folder:
st.error('Please present all folder paths.')
else:
start_scan(reference_folder, images_folder, output_folder)
def start_scan(reference_folder, images_folder, output_folder):
reference_images = os.listdir(reference_folder)
if not reference_images:
st.error('No reference pictures discovered.')
return
reference_img_path = os.path.be part of(reference_folder, reference_images[0])
progress_bar = st.progress(0)
status_text = st.empty()
def update_progress(progress):
progress_bar.progress(progress)
status_text.textual content(f'Scan progress: {progress * 100:.2f}%')
matched_images = find_facial_matches(reference_img_path, images_folder, output_folder, update_progress)
st.success(f'Scan accomplished. Discovered {len(matched_images)} matching pictures.')
if st.button('Cease Scan'):
st.cease()
if __name__ == '__main__':
principal()
There, I simply wanted to create my reference folder and put some reference pictures in there, in addition to the output folder so I can hyperlink it within the app. Since I’ve like 10000 images on my pc I made a decision to go along with a test_images folder with randomly chosen images (only a bit extra then a 100 images) so {that a} testing run doesn’t take perpetually.
The one factor left was to run the app and see what occurs.
Now once I had every thing arrange it was time to run the app:
streamlit run app.py
And all I requested for is right here.
Easy, however efficient. It has three enter dialogues like I requested, a begin button and within the center a reputation of the app and a spot for progress bar to seem with displayed outcomes. Cease button was by no means to be seen however I made my peace with that. It confirmed up when the outcomes have been displayed simply to be annoying however I couldn’t be bothered to repair that :).
The applying ran for about 30min on my 100+ check images and introduced 26 matches. I scanned the check images folder myself and located 35 pictures of my father there which suggests the algorithm missed round 9 images. That’s successful price of roughly 74% if my math is appropriate right here. Not good however for what it’s it’s fairly superior for those who ask me.
I can’t actually inform if the rationale for missed images is a matter of code or reference pictures or that the deep face library has its limitations. Not that it issues, I nonetheless assume that 74% is an effective end result particularly for those who don’t have the crucial of the proper rating.
Good understanding of a programming language and its dependencies actually goes a good distance and might steer the end in a approach you need or want. The truth that it’s sufficient to have a primary understanding for spectacular outcomes is simply wonderful. I can’t look forward to ChatGPT 5 to point out up and see what magic I can do with it.
If you wish to take a look at this venture on my Github you are able to do so on this hyperlink:
https://github.com/BorisHrzenjak/Facial_recognition_webapp
Have enjoyable, mess around with it and improve the hell out of it if you would like. In case you accomplish that, I wish to see the outcomes so hit me up on Github, Linkedin or YouTube and share your outcomes 🙂
Till subsequent venture…
By the best way, for those who discovered any of this fascinating and wish to study extra, focus on potential initiatives, or simply join, be happy to achieve out to me on LinkedIn.