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 (1)

Collapse
 
peter profile image
Peter Kim Frank โ€ข

This is fun, recognized my handwriting 100% of the time ๐ŸŽฏ

Sentry image

See why 4M developers consider Sentry, โ€œnot bad.โ€

Fixing code doesnโ€™t have to be the worst part of your day. Learn how Sentry can help.

Learn more