DEV Community

Cover image for I Recreated Tom Riddle’s Diary, But Used My Soul Instead πŸ‘»
YCM Jason
YCM Jason

Posted on

I Recreated Tom Riddle’s Diary, But Used My Soul Instead πŸ‘»

YCMJason's Diary πŸ“–βœ¨

This web app is inspired by Tom Riddle's Diary. I've literally enchanted this website with a piece of my soul πŸͺ„πŸ–€. So go ahead, talk to it, and learn more about me!

Tom Riddle's Diary

πŸ”— YCMJason's Diary 🌍✨
πŸ”— GitHub Repo

Here are some quick write up on some of the challenges I faced in this project.

This project had two major challenges:

  1. Recognizing handwriting ✍️
  2. Running an LLM for free πŸ’Έ

Recognizing Handwriting ✍️

A Tom Riddle Diary wannabe that only accepts keyboard input? Absolutely unacceptable! 😀 So I set out to implement handwriting recognition on a canvas.

The Journey:

  • Tesseract.js πŸ€–

    • Great for printed text βœ…
    • Absolute trash for handwriting ❌
  • Transformers.js by πŸ€— Hugging Face

    • Looked promising...
    • Required users to download huge models (~30s load time 😭)
    • Recognition results? Not even close! ❌
  • The Breakthrough: Handwriting.js πŸ”

    • BOOM! Found this hidden gem: handwriting.js πŸ’Ž
    • How does it work? 🀯 It reverse-engineers Google's IME by sending stroke data to Google's API: πŸ‘‰ https://www.google.com/inputtools/request?ime=handwriting&app=mobilesearch&cs=1&oe=UTF-8
    • Results are blazingly fast ⚑ and super accurate 🎯!

πŸ‘¨β€πŸ”§ But the project was 5 years old and looked like it was built in 2003... 😬 So I stole borrowed the core logic and rewrote it in modern JavaScript! Might publish it on JSR later if there’s demand! πŸš€ Let me know if you're interested! πŸ’¬

Running an LLM for Free πŸ’Έ

For the LLM, I remembered this awesome project: mlc-webllm, which runs models directly on your device! πŸ”₯

The Journey:

  • MLC-WebLLM βœ…

    • Model download time: 🚦 30+ seconds (Users will leave after 5 seconds, let's be real πŸ˜…)
    • Inference speed:
    • M1 Max MacBook: 5 seconds ⏳
    • Pixel 9 Pro Fold: 30+ seconds 🚨
    • Turns out, my system prompt was the culprit! 😱 Longer prompts slow down inference a lot.
  • Transformers.js ❌

    • Even slower than MLC-WebLLM 😭
    • Downloads the model in a single request without batching (or so it seems πŸ€”)
  • The Breakthrough: OpenRouter + Vercel AI SDK 🎯

πŸš€ The dev experience? Absolute chef's kiss πŸ‘¨β€πŸ³πŸ‘Œ. Huge thanks to Vercel & OpenRouter! πŸ™Œ

Final Thoughts 🧠

If this app doesn’t go viral, I’ll be sad. 😒 So please, go have fun with it! πŸŽ‰

πŸ’¬ Feedback? File an issue or ping me on X or πŸ¦‹.

Top comments (0)