Inspiration
What it does
Inspiration
As a CS student in Lahore, I know how often AI tools stop being useful at the worst moment: patchy Wi-Fi during load-shedding, limited mobile data, or a free-tier limit hit the night before an exam. Most AI study tools assume a fast, always-on connection. I wanted to see whether a study assistant could work for every student, whether or not their device or connection is ideal.
Firebase AI Logic's hybrid inference was the perfect fit. It lets an app use the model built into the browser when possible and fall back to the cloud when it isn't.
What it does
Hybrid Study Buddy takes pasted notes and turns them into:
- a simple explanation in Hinglish (English mixed with Urdu)
- a 5-bullet summary
- 5 practice MCQs
- an acronym or memory trick for quick revision
After every response, a badge shows whether it ran on-device (Chrome's Gemini Nano) or in the cloud (Gemini), so the hybrid behavior is visible to the user.
How I built it
- Frontend: Vite and vanilla JavaScript, with no framework, to keep it lightweight.
- AI: The Firebase AI Logic web SDK (
firebase/ai), with the model created usingInferenceMode.PREFER_ON_DEVICE. Responses are streamed withgenerateContentStream, so text appears as it's generated. - Mode switcher: A dropdown lets users choose between
PREFER_ON_DEVICE,PREFER_IN_CLOUD,ONLY_ON_DEVICEandONLY_IN_CLOUD, which makes the hybrid behavior easy to demo and test. - Prompts: Each task has its own prompt, tuned to produce friendly, human-sounding study help with local examples rather than stiff textbook language.
The core of the hybrid logic is a single line:
const model = getGenerativeModel(ai, { mode: InferenceMode.PREFER_ON_DEVICE });
Challenges I ran into
- Browser support: On-device inference currently works only in Chrome on desktop (v139+). Everything else has to fall back to the cloud cleanly, which is exactly why the hybrid approach matters.
- Model download: The first on-device request triggers a model download that needs a user action, so I tied generation to a button click and added a loading state so the wait doesn't feel broken.
- Feature limits: On-device inference supports single-turn text generation, so I designed the app around one-shot tasks (explain, summarize, quiz) instead of long chats.
- Keeping keys safe: Calling Gemini directly from the browser means the app must be protected, so the setup uses environment variables and recommends enabling Firebase App Check before going public.
What I learned
- Hybrid inference is less about the model and more about reach: the same app serves a student on a new Chrome laptop and one on an older device, without separate code paths.
- On-device AI gives real benefits for students: it's free per request, private (notes never leave the device), and works offline.
- Small UX details, like showing where the answer came from, make hybrid AI feel trustworthy instead of magical.
What's next
- Offline-first PWA support
- Saving past summaries and quizzes locally
- Image input so students can snap a photo of handwritten notes
- Urdu script output alongside Roman Urdu
Built with
Firebase AI Logic · Gemini · Chrome built-in AI (Gemini Nano) · JavaScript · Vite
How we built it
Challenges we ran into
Accomplishments that we're proud of
What we learned
What's next for Hybrid Study Buddy
Built With
- chrome-built-in-ai
- css
- firebase
- firebase-ai-logic
- gemini
- gemini-nano
- html
- javascript
- vite