CoolFace
Apppublic

Nipun/gemini-image-puzzle

sourceHugging Faceupdated 3mo agoView on Hugging Face
1likes
App README

๐Ÿงฉ Gemini Image Puzzle

A password-protected FastAPI app that answers vision + text questions with Gemini Flash. Upload an image or paste an image URL, ask a question, and get an answer. Ships with built-in sample puzzles (shape-algebra, similar-triangles geometry, logic, counting, chart reading).

Two answer modes:

  • โ€”Solver (ReAct) โ€” Gemini reasons step by step and uses its code-execution tool to write & run Python (sympy), so arithmetic and algebra are computed and verified, not guessed. Each answer is driven by a skill (Auto, Geometry, Shape Algebra, Logic, Counting, Chart, General) that injects a focused system prompt + worked example. The reasoning + code is shown in a collapsible trace. Math renders with KaTeX.
  • โ€”Quick โ€” a single fast vision answer with no tools.

The frontend is a static HTML/CSS/JS single page styled with the nipunbatra.github.io design system (Playfair Display headings, Work Sans body, warm-red #c44536 accent, light/dark theme). FastAPI serves the page and the /api/* endpoints; this avoids the issues a long-running Streamlit app hits on Spaces.

Secrets (Space settings โ†’ Variables and secrets)

SecretPurpose
GEMINI_API_KEYGoogle AI Studio API key
ACCESS_CODEAccess code required to use the app
GEMINI_MODEL (optional)Default model for Quick mode, e.g. gemini-3.5-flash
GEMINI_SOLVER_MODEL (optional)Default model for Solver mode

Endpoints

  • โ€”GET / โ€” frontend (injects an access-code overlay when ACCESS_CODE is set)
  • โ€”POST /api/auth โ€” exchange access code for a session token
  • โ€”GET /api/config โ€” available models + puzzle catalogue
  • โ€”POST /api/ask โ€” {question, model, image_b64 | image_url | puzzle_id} โ†’ answer
  • โ€”GET /api/puzzle/{id}/answer โ€” intended answer for a sample puzzle
  • โ€”GET /api/health โ€” health/session check

Local run

bash
pip install -r requirements.txt
export GEMINI_API_KEY=... ACCESS_CODE=...
uvicorn main:app --host 0.0.0.0 --port 7860

The puzzle images in static/puzzles/ are generated by python make_puzzles.py.