The flexibility to write down your individual packages was certainly one of my all-time-favorite goals and it seamed to me like magic that you could possibly simply consider one thing you want and go create it. Sadly, mixture of my aversion to math (math academics, to be exact) and tendency to procrastinate in each troublesome 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 sensible 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 creating. It match completely with me and my want to search out the solutions proper now or surrender. It didn’t minimize my procrastination habits nevertheless 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 instrument at my disposal that may actually spit out completed (properly, 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 the way to code however my objective now’s to discover ways to learn code, to not write it myself from scratch. I firmly consider that to be a means of the longer term. Capacity to specific your must AI shall be our new programming language.
That brings us to the subject of this text. I wished to indicate 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 illustration is to make a face recognition net software that is ready to undergo all my picture information 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 person interface is far more interesting so we’ll go together with that 🙂 This mission is means over my head as a programmer. I do suppose I might make it myself however it could take me weeks to determine it out. Fortunately I do have entry to ChatGPT 4o.
By the way in which, for those who discovered any of this fascinating and want to study extra, talk about potential tasks, or simply join, be happy to achieve out to me on LinkedIn.
- Connect with me on LinkedIn
- Try my YouTube
- My tasks 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 route you need.
These are my guidelines:
1. I would like this software 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 online app and for comfort I would like it to be written utilizing streamlit and deepface libraries (that is the place even fundamental information of a language can come in useful since you give the output clear route)
3. I would like the app to have three dialogues that the person 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 write down a immediate.
For the immediate I simply transformed all the principles above into somewhat story for the ChatGPT and made positive to inform it to information me each step of the way in which.
I would like you to create an online app utilizing streamlit that makes use of deep face facial recognition library to undergo my picture folders and information and finds all the pictures of my father. I’ll offer you a reference pictures within the reference folder. The app ought to have three enter dialogues the place person can browse to the reference folder, output folder and to the folder that comprises his picture information and sub-folders. The app must also have a method to present progress of the scan and in addition be certain that that there’s a begin button and a cease button in order that the person can cease the scan if he desires to. I’m an entire newbie and I would like your assist each step of the way in which. Inform me what folders to create for this mission and what information go by which folder. Additionally, inform me what code goes by which file.
Whereas not excellent, this immediate was adequate to get me the entire construction of the mission with clear directions what folders, dependencies and information I must create for this app:
Mission Construction:
— Create the primary mission folder, e.g., `facial_recognition_app`.
— Inside this folder, create the next subfolders and information:
— `app.py`: The principle Streamlit app.
— `necessities.txt`: To listing all dependencies.
— `utils.py`: For utility features 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 have to put in Streamlit, DeepFace, and different mandatory 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 means ahead I simply needed to comply with the “recipe” and prepare dinner up this app 🙂
It’s price mentioning that the primary model of the code did have an error, it seams prefer it didn’t embrace 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 might repair it and convey me a revised model of the code. It was actually only a minor factor and the second model of the code labored like a attraction.
Anyway, I began with the creation of the digital setting (since this can be a stroll by means of, 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 complete motive you’ve necessities file so you’ll be able to set up it in a neater means:
pip set up -r necessities.txt
There! Now now we have the whole lot arrange and we’re able to go.
This app consists of two information, ‘utils.py’ and ‘app.py’
Utils.py: This file comprises utility features 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, information in os.stroll(folder):
for file in information:
if file.endswith(('jpg', 'jpeg', 'png')):
pictures.append(os.path.be a 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)
outcome = DeepFace.confirm(img, reference_img, enforce_detection=False)
if outcome['verified']:
matched_images.append(img_path)
output_path = os.path.be a 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 now we have a toolbox, now we want the primary app that can run the streamlit software.
App.py:
import streamlit as st
import os
from utils import find_facial_matchesdef most important():
st.title('Facial Recognition App')
st.sidebar.header('Folders')
reference_folder = st.sidebar.text_input('Reference Folder')
images_folder = st.sidebar.text_input('Photographs 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 a 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__':
most important()
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 laptop I made a decision to go together 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 without end.
The one factor left was to run the app and see what occurs.
Now after I had the whole lot 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 look 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 appliance ran for about 30min on my 100+ take a look at images and introduced 26 matches. I scanned the take a look at images folder myself and located 35 pictures of my father there which suggests the algorithm missed round 9 images. That’s a hit price of roughly 74% if my math is appropriate right here. Not excellent 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 suppose that 74% is an effective outcome particularly for those who don’t have the crucial of the right rating.
Good understanding of a programming language and its dependencies actually goes a good distance and may steer the end in a means you need or want. The truth that it’s sufficient to have a fundamental understanding for spectacular outcomes is simply wonderful. I can’t await ChatGPT 5 to indicate up and see what magic I can do with it.
If you wish to take a look at this mission 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 in order for you. In case you achieve this, I want to see the outcomes so hit me up on Github, Linkedin or YouTube and share your outcomes 🙂
Till subsequent mission…
By the way in which, for those who discovered any of this fascinating and want to study extra, talk about potential tasks, or simply join, be happy to achieve out to me on LinkedIn.