The core of the game is shipping off images to different LLM APIs to get guesses. As games happen and drawings are made (or the webcam pics are streamed in, in this physical version) there are threads running that call out to the different models, sending the latest image about once every 3 seconds:
def make_prompt(guess_history=None):
prompt = "Guess the pictionary prompt. Reply with a single word only."
if guess_history:
prompt += f"\nPast guesses: {', '.join([g['guess'] for g in guess_history])}"
return prompt
def guess_gemini(image_fn, guess_history=None):
img = PILImage.open(image_fn)
model = genai.GenerativeModel('gemini-1.5-flash')
response = model.generate_content([make_prompt(guess_history), img])
response.resolve()
return "Flash 1.5", response.text
I made an enclosure around a donated laptop (thanks to a generous member of my hackerspace - CTRL-H - who had some spares). A piece of whiteboard material sits atop a box of corrugated plastic, which protects the keyboard from the vagaries of frantic drawing. The material was obtained at a new favorite shop of mine: Scrap PDX:
Talk about a wealth of materials!
The code change to turn a canvas-based drawing app into a webcam-and-whiteboard based one was done in a single prompt by Claude 3.5 Sonnet, a very pleasant time-saver for me since I'd been putting off that part of this project for a week or two! Apart from the changes to the javaScript responsible for handling the drawing/webcam reading, the code remains the same as the original demo I made, on GitHub here: https://github.com/AnswerDotAI/fasthtml-example/tree/main/03_pictionary/moodle_demo.
I'm not sure if this whole lot counts as "tiny" (https://moodle-game.com/ is ~750 lines of code) but the physical incarnation is hopefully minimal enough to count :)