-
-
Uploading a suspicious cybercrime PDF notice (Mock Cyber Notice.pdf), with text extracted on the server and routed to cloud analysis.
-
Cloud-routed analysis flags a 99/100 HIGH risk impersonation scam, highlighting coercive terms like "ARREST" and "Within 2 Hours".
-
Deterministic Python rule breakdown scoring urgency (35 pts), payment demands (35 pts), lookalike links (40 pts), and OTP lures (35 pts).
-
Extracted entities (INR 14,500, fake URLs) paired with structured AI explanations breaking down each manipulation tactic
-
"Before you act" safety checklist advising users to withhold OTPs/payments and verify via official .gov.in portals.
-
Hindi police warrant scam routed to cloud inference, scoring 84/100 HIGH risk with localized Hindi explanations and highlighted evidence.
-
Extracted Hindi UPI demand (₹10,000) and localized guidance advising users to verify claims directly with their local police station.
Inspiration
Scam messages in India often pretend to be the police, a bank, a courier or a government office. They use fake arrest warrants, "your account will be blocked in 2 hours" threats and OTP requests to panic people into acting. The people most at risk are often the ones who don't have time or confidence to check. RedFlagged already helps people spot these warning signs. For #BuildHybridAI I wanted it to keep working when the person is offline, and to keep their messages on their own device whenever possible. A scam message often contains private details.
What it does
RedFlagged Hybrid takes a suspicious message (pasted text, a JPEG/PNG screenshot, or a PDF) and returns:
- a 0–100 risk score and a LOW / MEDIUM / HIGH level,
- the exact evidence that triggered each warning sign (urgency, payment demands, OTP/credential requests, suspicious or lookalike links, courier and job scams),
- a plain-language explanation, safe next steps and official verification guidance, in English or Hindi.
A badge on every result shows where the analysis actually ran: "Checked on your device" or "Sent to cloud", with the reason (for example, "Only English is supported for on-device inference" or "PDF input is not eligible for on-device inference").
How we built it
Firebase AI Logic is the core of the app. The React frontend calls Firebase AI Logic (firebase/ai, Gemini Developer API) directly from the browser. There is no key in the app code, and App Check protects the calls (reCAPTCHA Enterprise in production, a debug token in development).
- On-device: short English messages run with
InferenceMode.PREFER_ON_DEVICE, which uses Gemini Nano in Chrome through the Prompt API. This works with Wi-Fi off once the model is downloaded. - Cloud: Hindi/Devanagari text, long text (checked against a conservative token budget), and text extracted from PDFs go to Gemini in the cloud through the same SDK. JPEG/PNG text extraction also uses cloud inference.
- Fallback chain: on-device, then one cloud retry, then a rules-only result if AI is unavailable. The badge always uses the SDK's reported
inferenceSource, never the requested mode.
The score never depends on the AI. The risk score, level and evidence come from my deterministic Python rule engine, so the result is identical on every path. To run it in the browser without rewriting about 900 lines of rules, I run the unchanged Python files in a Web Worker with Pyodide. 30/30 test messages match native Python. The AI only writes the explanation.
A small FastAPI service on Render now does one job: PDF text extraction. The frontend is on Vercel.
Built during the contest vs. before: RedFlagged existed before this contest (FastAPI backend, Python rules, React UI). This is a separate repository. The Firebase AI Logic integration, hybrid routing, App Check, the Pyodide in-browser rule engine, the inference-source badge, and removing the AI call from the backend were all built for this contest.
Challenges we ran into
- Hindi is not supported on-device. Gemini Nano only outputs a few languages, and Hindi isn't one of them. I built routing that detects Devanagari text and sends it to the cloud, with the reason shown to the user.
- Fitting a small on-device model. The 9,216-token limit and the lack of an exact on-device token counter meant a conservative input budget. Anything that might not fit goes to the cloud.
- Running Python rules in the browser without changing their behavior. Pyodide solved it, and parity tests proved it.
- App Check setup. reCAPTCHA v3 was deprecated in the console, so I moved to reCAPTCHA Enterprise. I also had to keep the debug token and localhost out of production.
- Honest labelling. Early on it was easy to show "on-device" when the request had only asked for it. Reading the real
inferenceSourcefixed that.
Accomplishments that we're proud of
- A scam check that works with Wi-Fi off, with the same score as the online run.
- Identical, explainable scores on every inference path.
- An honest fallback chain that always returns a useful result.
- 65 passing frontend tests and a 30/30 rule-engine parity check, plus live testing of English, Hindi, mixed-language and PDF messages.
What we learned
- Hybrid AI is a design problem, not just an SDK call. The routing rules (language, length, input type) matter as much as the model.
- Keeping the decision logic deterministic and using AI only for explanation makes results trustworthy and testable.
- On-device models are good for private, short, offline tasks, and the cloud fills the gaps.
What's next for RedFlagged-hybrid
- Better Roman-script Hindi and more Indian languages, including Gujarati.
- Fixing known rule gaps (for example, "UPI PIN to receive cashback" in Hindi currently scores MEDIUM).
- Handling URLs that get split across lines in PDFs.
- More end-to-end browser tests for the on-device, cloud, image and PDF paths.
Built With
- chrome-prompt-api
- fastapi
- firebase
- firebase-ai-logic
- firebase-app-check
- gemini
- gemini-nano
- javascript
- pyodide
- python
- react
- recaptcha-enterprise
- render
- tailwindcss
- vercel
- vite
- webassembly
