CoolFace
Apppublic

fablefrost/Project2-Quizzie

sourceHugging Facemitupdated 9mo agoView on Hugging Face
0likes
App README

πŸ“– Overview

Quizzie is an AI-powered autonomous quiz-solving agent built for the Tools in Data Science – Project 2 of the IITM BS Degree Programme.

The system uses a LangGraph state machine, LLMs (GPT/Gemini), and Playwright headless browser to:

  1. 1.Fetch quiz pages (HTML, screenshots, console logs from JS-rendered content)
  2. 2.Reason using an AI agent that decides which tools to use
  3. 3.Execute Python code, JavaScript on pages, download files, analyze with vision/audio LLMs
  4. 4.Submit answers and handle feedback (retry on wrong, proceed on correct)
  5. 5.Iterate through the entire quiz chain until completion
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ fetch_context│────▢│ agent_reasoning │◀───▢│ execute_tools β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  submit_answer  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚process_feedback │────▢│ next quiz/ENDβ”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

✨ Features & Capabilities

πŸ€– AI Agent Tools

ToolDescription
python_toolExecute Python code with persistent session (pre-imported: pandas, numpy)
javascript_toolRun JavaScript on browser pages via Playwright
download_file_toolDownload files (up to 50MB) with caching
call_llm_toolAnalyze files with Gemini 2.5 Flash (images, PDFs, audio, video)
call_llm_with_multiple_files_toolAnalyze multiple files together
submit_answer_toolSubmit answers to quiz endpoints

πŸ“Š Supported Task Types

Based on project.md requirements, the system handles:

CategoryCapabilities
Web ScrapingJS-rendered pages, dynamic content, console logs, iframes
File ProcessingPDF extraction, Excel/CSV parsing, ZIP/Gzip decoding
Vision/OCRImage text extraction, QR codes (via cv2), chart reading, screenshots
AudioTranscription via Gemini, waveform analysis
Data AnalysisPandas operations, filtering, aggregation, statistics
Machine LearningRegression, clustering, classification (via Python)
VisualizationGenerate charts as base64 images
GeospatialGeoJSON/KML analysis with networkx
EncodingBase64, Gzip, AES decryption, hashing (MD5/SHA1)

πŸ›‘οΈ Robustness Features

  • β€”3-minute timeout per quiz with automatic skip to next
  • β€”Unlimited retries within timeout window
  • β€”10 max attempts before moving on
  • β€”Exponential backoff on LLM errors (up to 10 retries)
  • β€”Round-robin API key rotation for Gemini (up to 3 keys)
  • β€”File-based caching with TTL for pages and downloads
  • β€”Graceful error handling - agent never crashes
  • β€”Token limit protection - skips quiz if messages exceed 25000 tokens

πŸš€ Quick Start

Prerequisites

  • β€”Python 3.11+ (recommended via uv)
  • β€”Docker (optional, for deployment)
  • β€”Playwright browsers (auto-installed on first run)

1️⃣ Clone & Install

bash
git clone https://github.com/23f3002872/Quizzie
cd Quizzie
uv sync  # or: pip install -e .
playwright install chromium

2️⃣ Configure Environment

Create .env file:

dotenv
# Required
SECRET_KEY=your-secret-key
STUDENT_EMAIL=your-email@ds.study.iitm.ac.in

# LLM Configuration (Primary reasoning model)
LLM_API_KEY=your-openai-api-key
LLM_BASE_URL=https://api.openai.com/v1
LLM_PROVIDER=openai  # or google

# Gemini Keys (for file analysis - round-robin rotation)
GEMINI_API_KEY_1=your-gemini-key-1
GEMINI_API_KEY_2=your-gemini-key-2
GEMINI_API_KEY_3=your-gemini-key-3

# Server
HOST=0.0.0.0
PORT=8000
DEBUG=false

3️⃣ Run

bash
uv run uvicorn main:app --host 0.0.0.0 --port 8000
# or
python main.py

4️⃣ Test

bash
# Health check
curl http://localhost:8000/health

# Submit a quiz (runs in background)
curl -X POST http://localhost:8000/solve \
  -H "Content-Type: application/json" \
  -d '{"email":"your-email","secret":"your-secret","url":"https://quiz-url"}'

🐳 Docker Deployment

bash
# Build
docker build -t Quizzie .

# Run
docker run -p 8000:8000 \
  -e SECRET_KEY=xxx \
  -e STUDENT_EMAIL=xxx \
  -e LLM_API_KEY=xxx \
  -e GEMINI_API_KEY_1=xxx \
  Quizzie

HuggingFace Spaces

  1. 1.Create new Space with Docker SDK
  2. 2.Push this repository
  3. 3.Add secrets in Space settings
  4. 4.Access via https://your-space.hf.space/

🌲 Project Structure

Quizzie/
β”œβ”€β”€ main.py                    # FastAPI entry point
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── settings.py        # Pydantic settings from env
β”‚   β”œβ”€β”€ graph/
β”‚   β”‚   β”œβ”€β”€ graph.py           # LangGraph workflow definition
β”‚   β”‚   β”œβ”€β”€ state.py           # QuizState TypedDict
β”‚   β”‚   └── resources.py       # GlobalResources (browser, llm)
β”‚   β”œβ”€β”€ nodes/
β”‚   β”‚   β”œβ”€β”€ fetch.py           # Fetch page content node
β”‚   β”‚   β”œβ”€β”€ agent.py           # AI reasoning node
β”‚   β”‚   β”œβ”€β”€ tools.py           # Tool execution node
β”‚   β”‚   β”œβ”€β”€ submit.py          # Answer submission node
β”‚   β”‚   └── feedback.py        # Process server response node
β”‚   β”œβ”€β”€ tools/
β”‚   β”‚   β”œβ”€β”€ python.py          # Python execution sandbox
β”‚   β”‚   β”œβ”€β”€ javascript.py      # Browser JS execution
β”‚   β”‚   β”œβ”€β”€ download.py        # File downloader with cache
β”‚   β”‚   β”œβ”€β”€ call_llm.py        # Gemini multimodal analysis
β”‚   β”‚   └── submit_answer.py   # HTTP POST submission
β”‚   β”œβ”€β”€ resources/
β”‚   β”‚   β”œβ”€β”€ llm.py             # Multi-provider LLM client
β”‚   β”‚   β”œβ”€β”€ browser.py         # Playwright browser wrapper
β”‚   β”‚   └── api.py             # HTTP client utilities
β”‚   └── utils/
β”‚       β”œβ”€β”€ logging.py         # Structured logger
β”‚       β”œβ”€β”€ cache.py           # File-based caching
β”‚       β”œβ”€β”€ helpers.py         # Temp file management
β”‚       └── gemini.py          # Gemini API utilities
β”œβ”€β”€ tests/                     # Pytest test suite
β”œβ”€β”€ Dockerfile                 # Production container
└── pyproject.toml             # Dependencies & scripts

πŸ“š API Reference

GET / or GET /health

Health check endpoint.

json
{"status": "ok", "message": "Quiz Solver is running"}

POST /solve

Start quiz solving (runs in background).

Request:

json
{
  "email": "student@example.com",
  "secret": "your-secret-key",
  "url": "https://example.com/solve/1"
}

Response:

  • β€”200 - Quiz solving started
  • β€”400 - Invalid JSON payload
  • β€”403 - Invalid secret or email

βš™οΈ Configuration

VariableDefaultDescription
SECRET_KEYrequiredAuthentication secret
STUDENT_EMAILrequiredStudent email ID
LLM_API_KEYrequiredPrimary LLM API key
LLM_PROVIDERopenaiopenai or google
LLM_MODELgpt-5-miniModel for reasoning
LLM_TEMPERATURE0.1Sampling temperature
GEMINI_API_KEY_1/2/3optionalRound-robin Gemini keys
TEMP_DIR/tmp/quiz_filesTemporary file storage
CACHE_DIR/tmp/quiz_cacheCache storage
BROWSER_PAGE_TIMEOUT10000Playwright timeout (ms)

πŸ§ͺ Testing

bash
uv run pytest -v

Test coverage includes:

  • β€”API endpoint validation
  • β€”Browser initialization
  • β€”LLM response mocking

πŸ“‹ TODO: Future Improvements

Note: The project statement (project-llm-analysis-quiz.md) itself contains TODOs and states "THIS PROJECT IS WORK IN PROGRESS. SOME DETAILS MAY CHANGE." Below are improvements that could be made with more time.

πŸ”΄ High Priority

  • β€”[ ] Gemini Function Calling - Currently it is experiencing Malformed Function Call errors
  • β€”[ ] Dynamic Model Selection - Allow choosing different LLMs per quiz
  • β€”[ ] Advanced Error Handling - More granular error categories and recovery

🟑 Medium Priority

  • β€”[ ] Parallel Quiz Handling - Process current and next URL simultaneously on wrong answers
  • β€”[ ] Better Visualization Support - Generate charts as images or interactive formats
  • β€”[ ] Geo-spatial Analysis - Improve GeoJSON/KML processing capabilities
  • β€”[ ] Network Analysis - Better graph/network data handling

🟒 Nice to Have

  • β€”[ ] Comprehensive Test Suite - Add more unit tests
  • β€”[ ] Performance Metrics - Track success rates per question type
  • β€”[ ] Caching Optimization - Smarter cache invalidation
  • β€”[ ] Enhanced Logging - More granular logs for debugging
  • β€”[ ] User Interface - Simple web UI for monitoring quiz progress
  • β€”[ ] More Test Cases - Cover edge cases in quiz solving

πŸ“ Project Notes

What the Project Requires (from project-llm-analysis-quiz.md)

  1. 1.API Endpoint that:
  2. 2.Accepts POST with {email, secret, url}
  3. 3.Returns HTTP 200 for valid requests, 400 for invalid JSON, 403 for invalid secrets
  4. 4.Solves quiz within 3 minutes of receiving the request
  1. 1.Quiz Solving capabilities for:
  2. 2.Web scraping (JS-rendered pages)
  3. 3.API sourcing (with provided headers)
  4. 4.Data cleansing (text/PDF/etc.)
  5. 5.Data processing (transformation, transcription, vision)
  6. 6.Analysis (filtering, sorting, aggregating, ML models, geo-spatial, network)
  7. 7.Visualization (charts as images, narratives, slides)
  1. 1.Answer Submission:
  2. 2.POST to URL specified on quiz page (never hardcoded)
  3. 3.Payload: {email, secret, url, answer} under 1MB
  4. 4.Answer can be: boolean, number, string, base64 URI, or JSON object
  1. 1.Prompt Testing (separate evaluation):
  2. 2.System prompt (max 100 chars) to resist revealing a code word
  3. 3.User prompt (max 100 chars) to extract code words from other system prompts

⚠️ Unclear Aspects in Project Statement

The official project statement has these unresolved items:

  1. 1."THIS PROJECT IS WORK IN PROGRESS" - Requirements may change
  2. 2.Scoring weights - "will be finalized later"
  3. 3.Model selection - "Which models will prompts be tested on?" marked as TODO
  4. 4.Test pairing - "How many other prompts will each prompt be tested against?" marked as TODO
  5. 5.Viva format - Only says "voice viva with LLM evaluator" without details
  6. 6.3 minute timer - Unclear if for a single question or entire quiz

πŸ’‘ Design Decisions Made

Given the ambiguity, this implementation:

  • β€”Uses LangGraph for flexible workflow management
  • β€”Implements multiple LLM providers (OpenAI, Google) for redundancy
  • β€”Has aggressive retry logic (10 attempts, 3-min timeout per quiz)
  • β€”Uses Gemini for multimodal (vision, audio, PDF) analysis
  • β€”Maintains persistent Python sessions for stateful computations
  • β€”Caches page content to avoid redundant fetches

Test endpoint provided: https://tds-llm-analysis.s-anand.net/demo


πŸ“œ License

MIT License - see LICENSE file.


πŸ“ž Contact

` Khushi Choudhary

  • β€”Email: 23f3002872@ds.study.iitm.ac.in
  • β€”GitHub: @23f3002872