Skip to content

Instantly share code, notes, and snippets.

View andrisgauracs's full-sized avatar

Andris Gauračs andrisgauracs

View GitHub Profile
@andrisgauracs
andrisgauracs / run_prompt.sh
Created July 31, 2026 02:57
Test a custom prompt against an already-trained, already-flashed ESP32-S3 model
#!/usr/bin/env bash
# esp32-ai: test a custom prompt against an already-trained, already-flashed model.
# Does NOT retrain and does NOT rewrite the 15MB model partition.
#
# Usage:
# ./run_custom_prompt.sh "Once there was a robot"
set -euo pipefail
if [ "$#" -lt 1 ]; then
echo "Usage: $0 \"Your custom prompt\""
@andrisgauracs
andrisgauracs / build_and_flash.sh
Created July 31, 2026 02:21
One Shot Build Script For Running 28M AI Model On ESP32-S3
#!/usr/bin/env bash
# esp32-ai: clone, train, export, build, and flash — end to end
# Reproduces github.com/slvDev/esp32-ai from a bare board.
# Requires: ESP32-S3 N16R8 (16MB flash, 8MB PSRAM).
#
# Usage:
# ./build_and_flash.sh # full run: data prep, train, export, build, flash
# ./build_and_flash.sh --skip-train # reuse an existing firmware/model/model.bin, just build + flash
set -euo pipefail
# Once the list is full with all the images we need, we can start to
# combine it into the final output image
if (framesTaken == framesSpecified):
resultImgs = []
for i in framesTakenList:
# here we just add a whitespace rectangle as a top margin
resultImgs.append(cv2.imread(i))
im = np.zeros((
borderSize*2,
cv2.imread(i).shape[1],
# To show a thumbnail version of this image, we need to store it
# in a pixmap and then add it to a label widget
pixmap = QtGui.QPixmap()
pixmap.load(imagePath)
pixmap = pixmap.scaledToWidth(50)
self.imageBoxes[framesTaken].setPixmap(pixmap)
framesTaken = framesTaken + 1
# Now that we have at least one image captured and processed,
# we can go ahead and show the bottom layout with our thumbnail labels
# Let's fetch the video frame we just captured
imagePath = os.getcwd() + "/img_"+str(framesTaken)+".png"
# Transform the image to an OpenCV readable image
image = cv2.imread(imagePath)
# Let's make a copy of this image
# to use for the color palette generation
image_copy = image_resize(cv2.cvtColor(
image, cv2.COLOR_BGR2RGB), width=100)
# Courtesy of https://www.pyimagesearch.com/2014/05/26/opencv-python-k-means-color-clustering/
def plot_colors(hist, centroids):
# initialize the bar chart representing the relative frequency
# of each of the colors
bar = np.zeros((50, 300, 3), dtype="uint8")
startX = 0
# Sort the centroids to form a gradient color look
centroids = sorted(centroids, key=lambda x: sum(x))
# Courtesy of https://www.pyimagesearch.com/2014/05/26/opencv-python-k-means-color-clustering/
def centroid_histogram(clt):
# grab the number of different clusters and create a histogram
# based on the number of pixels assigned to each cluster
numLabels = np.arange(0, len(np.unique(clt.labels_)) + 1)
(hist, _) = np.histogram(clt.labels_, bins=numLabels)
# normalize the histogram, such that it sums to one
hist = hist.astype("float")
hist /= hist.sum()
# return the histogram
def take_snapshot(self):
# Import the global variables we'll be using
global framesTaken, clusters, borderSize, offset
# This will be needed to check if the player was playing at the
# time of the button press
wasPlaying = None
# We need to get the width and height of the video file
videoSize = self.mediaplayer.video_get_size()
# This is the VLC function, that let's us
# take a snap shot of the video frame and save it in the directory
def valuechange(self):
# We access our global variables within the function
global framesTaken
global framesSpecified
# We set the framesSpecified value to
# whatever is specified on the spinbox
framesSpecified = self.sp.value()
# We modify our label to give us info, how many
class Custom_VLC_Player(Player):
def __init__(self):
# We inherit all the attributes of the original class
super(Custom_VLC_Player, self).__init__()
# We want the width and height to be fixed, so the layout dimensions
# don't change in a weird way
self.videoframe.setFixedWidth(640)
self.videoframe.setFixedHeight(360)