Inspiration

Teachers spend hours writing quizzes and even more grading them. Paid tools for this exist, but they need accounts, subscriptions and a computer. Many teachers, in Saudi Arabia and beyond, have only their phone and a school printer. We wanted the whole cycle on the phone, free: write, print, scan, grade.

What it does

  • Writes questions from your book:
    • The teacher adds a textbook PDF in any subject, Arabic or English, picks the pages, and names the paper's parts with their question types and counts.
    • The AI writes the questions, and the teacher reviews and edits every one before approving.
  • Prints everything from the phone: the question paper, the answer model, and an answer sheet with each student's name, on any AirPrint printer.
  • Grades with the camera:
    • The sheet carries the quiz and the student, so the teacher just points the camera. Scanning works offline.
    • Each student gets a marked copy: green on the right answer, red on a wrong choice.
  • Results: scores, class statistics, per-question analysis, and an Excel gradebook with a sheet per class.
  • Students imported automatically from the Excel or PDF list the school system exports.
  • Arabic and English: the interface follows the phone's language. Each paper keeps its quiz's language: Arabic right to left, or English left to right.

How we built it (how we used Firebase AI Logic)

Gradal is a SwiftUI app. All of its AI goes through one hybrid engine, FirebaseHybrid.swift:

  1. On-device first.
    • If Apple Intelligence is available, the prompt is in a supported language, and it fits the 4,096-token context, the request runs on the iPhone through Apple's Foundation Models framework.
    • A few pages of an English text qualify: they stay private, free and offline.
  2. Cloud fallback through Firebase AI Logic.
    • Long chapters, Arabic content, scanned pages and phones without Apple Intelligence go to Gemini through Firebase AI Logic.
    • On iOS 27 this uses ai.geminiLanguageModel(name:) in the same Foundation Models LanguageModelSession API.
    • JSON question writing and multimodal PDF input use generativeModel with InlineDataPart.
    • A busy or rate-limited model is retried, then replaced by a second Gemini model.
  3. An optional second check. If the teacher also links a key of their own, that second provider checks the written questions against the book text, and faulty ones are rewritten before the teacher sees them.
  4. Supporting Firebase products.
    • App Check is enforced for AI Logic (the build uses a debug token).
    • Remote Config holds the cloud model names and an on-device switch.
  5. No-Mac CI.
    • Built and tested on GitHub Actions (xcode-27 runner). The camera reader is tested on synthetic sheets in every build.
    • The Firebase config and the App Check token come from repository secrets.
    • A second workflow records the real app in the simulator writing a quiz live through Firebase.

What we built during the submission period (existing app, significantly updated)

Gradal existed before the hackathon (v2.7). AI then worked only through API keys the teacher pasted. During #BuildHybridAI (v3.0) we added:

  • The built-in hybrid AI: on-device Apple Foundation Models with Gemini cloud fallback, through Firebase AI Logic. No key needed any more.
  • App Check and Remote Config.
  • A complete English interface with English sample data, and the layout following the phone's language.
  • A Built-in AI section in Settings that shows on-device availability.
  • The demo-recording CI workflow.

Core value of the existing app

A free, open-source, phone-only quiz cycle for teachers: AI-written papers from their own textbook, printing, camera grading that works offline, and an Excel gradebook, with no account and no server. The hybrid AI removes its biggest barrier: teachers no longer need to create and paste an API key.

Challenges we ran into

  • Arabic is not yet supported by the on-device model. Language detection routes Arabic to Gemini. English short texts can stay on the device.
  • The on-device context is 4,096 tokens. Whole chapters go to the cloud.
  • Free-tier limits. A busy or exhausted model moves to a second Gemini model instead of failing.
  • A bilingual interface without breaking the papers. The interface follows the phone, while each printed paper keeps its quiz's language and direction.
  • No Mac. Everything is built, tested and recorded on GitHub Actions.

Accomplishments that we're proud of

  • The full quiz cycle on one phone, free.
  • Zero AI setup for the teacher.
  • One engine that chooses between on-device and cloud by language, length and modality.

What we learned

Hybrid AI is a routing problem. Making the routing explicit (language, size, modality) gives predictable privacy and cost, and keeps a fallback for every case.

What's next for Gradal

  • On-device rewriting and difficulty tuning of single questions.
  • Structured output on the device.
  • Arabic on the device when Apple's model supports it.

Testing instructions for judges

  1. Install Gradal-unsigned.ipa from the release link with Sideloadly and a free Apple ID (iOS 17+).
  2. With the phone in English, open Settings. The Built-in AI section shows "Ready with no key" and whether Apple's on-device model is available.
  3. Students: tap Paste names, enter a class name and a few names.
  4. Quizzes: tap New quiz from a book.
    • Add any English PDF, set the pages, and choose the class.
    • Tap Write the questions. Gemini writes them through Firebase, or the device does for a short English text on an Apple Intelligence iPhone.
  5. Review and approve the quiz, then print or share the papers.
    • Print the answer sheets on A4 at 100%, fill some bubbles, and tap Scan to grade them with the camera.

The source is all in the repository. The runtime Firebase calls are in ios/Gradal/AI/FirebaseHybrid.swift.

Built With

  • apple-foundation-models
  • firebase
  • firebase-ai-logic
  • firebase-app-check
  • firebase-remote-config
  • gemini
  • github-actions
  • pdfkit
  • swift
  • swiftui
  • vision
Share this project:

Updates

Submission history