Skip to content

AyushPathak4650/Book_Affinity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Book Personality Quiz

A Django web application that recommends books based on your MBTI personality type. Take a 12-question personality quiz, and the app uses AI (Groq/LLaMA) to determine your MBTI type, then recommends books from Google Books API based on your personality.


Product Requirements Document (PRD)

1. Concept & Vision

What it does: Users complete a personality quiz with 12 questions about their preferences, work style, and social behavior. The app analyzes their responses using AI to determine their MBTI personality type, then recommends books tailored to their personality.

Core value proposition: A fun, personalized book discovery experience that combines personality psychology with literary recommendations.

Target users:

  • Book lovers curious about personality types
  • Readers seeking personalized book recommendations
  • MBTI enthusiasts looking for a practical application

2. Design Language

Aesthetic direction: Warm, cozy, bookish feel with a coffee-shop vibe.

Color palette:

  • Primary: #986c48ff (warm brown)
  • Background: #fff6ebff (cream/warm white)
  • Text: Standard dark colors for readability

Typography:

  • Primary: Segoe UI, Arial, sans-serif
  • Clean, readable 1.1-1.3rem sizes

Visual assets:

  • Bootstrap 5.3 for responsive UI components
  • Google Books API thumbnails for book covers
  • Card-based layout with subtle shadows

3. Features & Interactions

Quiz Flow

  1. User lands on quiz page with 12 questions
  2. Each question presents 3 options (A, B, C)
  3. Radio buttons for single selection per question
  4. Submit button sends all answers to server
  5. Loading state while AI processes answers

Results Flow

  1. AI (Groq/LLaMA) analyzes answers and returns MBTI type
  2. MBTI type maps to a genre
  3. Google Books API fetches 6 books in that genre
  4. Results display with:
    • Book cover (blurred background effect)
    • Title and author
    • Description with "Read more" toggle
    • Link to web reader
  5. Option to retake quiz

Error Handling

  • API failures display friendly error page with retry option
  • Form validation requires all questions answered
  • Graceful handling of missing book data

4. Technical Architecture

Stack:

  • Backend: Django 5.x
  • AI: Groq API (LLaMA 3 8B model)
  • Book Data: Google Books API
  • Frontend: HTML5, Bootstrap 5.3, vanilla JS
  • Deployment: Gunicorn + Whitenoise

Key endpoints:

  • GET / - Quiz page
  • POST /recommend-books/ - Process quiz and show results

Data flow:

  1. User submits quiz form with 12 answers
  2. Server builds prompt with Q&A pairs
  3. Groq API returns MBTI type
  4. MBTI maps to genre
  5. Google Books API fetches books by genre
  6. Results rendered with book data

5. MBTI to Genre Mapping

MBTI Genre
INFP Poetry
INTP Science Fiction
INFP Fantasy
ENTP Debate Essays
ISFJ Historical Fiction
INFJ Mystery
ENFP Adventure
ISTJ Biography
ESTJ Business
ENTJ Leadership
ESFJ Romance
ESFP Travel
ISFP Art
ESTP Sports
ENFJ Self-help
INTJ Strategy
ISTP Technology

Quick Start

Prerequisites

Local Setup

  1. Clone and navigate to project:

    cd Mini_Project_Sem4
  2. Create virtual environment:

    python -m venv env
    source env/bin/activate  # Linux/Mac
    env\Scripts\activate     # Windows
  3. Install dependencies:

    pip install -r requirements.txt
  4. Configure environment:

    cp .env.example .env
    # Edit .env and add your GROQ_API_KEY
  5. Run migrations:

    python manage.py migrate
  6. Start development server:

    python manage.py runserver
  7. Open in browser: Navigate to http://localhost:8000


Deployment

Deploy to Render

  1. Create account at https://render.com
  2. Connect your GitHub repository
  3. Create a Web Service:
    • Build Command: pip install -r requirements.txt
    • Start Command: gunicorn config.wsgi:application --bind 0.0.0.0:$PORT
  4. Add environment variables:
    • GROQ_API_KEY: Your Groq API key
    • DJANGO_SECRET_KEY: Generate a secure key
    • DEBUG: False
    • ALLOWED_HOSTS: Your domain

Deploy to Railway

  1. Create account at https://railway.app
  2. New Project → Deploy from GitHub
  3. Add environment variables (same as Render)
  4. Railway auto-detects Django

Deploy to PythonAnywhere

  1. Create account at https://pythonanywhere.com
  2. Open Bash console
  3. Clone repository
  4. Set up virtualenv and install requirements
  5. Configure WSGI file
  6. Reload web app

Environment Variables

Variable Required Default Description
GROQ_API_KEY Yes - Groq API key for MBTI detection
DJANGO_SECRET_KEY No dev key Django secret key
DEBUG No True Debug mode
ALLOWED_HOSTS No localhost Comma-separated allowed hosts
CSRF_TRUSTED_ORIGINS No - CSRF trusted origins

API Rate Limits

  • Groq API: Free tier includes rate limits. Consider caching or queuing for high traffic.
  • Google Books API: 1000 requests/day for free tier.

Troubleshooting

"Error with Groq API"

  • Verify your API key is correct
  • Check your Groq API quota

"Error fetching books"

  • Google Books API may be rate limited
  • Check internet connectivity

Static files not loading

  • Run python manage.py collectstatic
  • Check STATIC_ROOT configuration

Project Structure

Mini_Project_Sem4/
├── config/                 # Django project settings
│   ├── settings.py         # Main settings file
│   ├── urls.py             # Root URL configuration
│   ├── wsgi.py             # WSGI application
│   └── asgi.py             # ASGI application
├── core/                   # Main application
│   ├── templates/          # HTML templates
│   │   ├── quiz.html      # Quiz page
│   │   ├── results.html   # Results page
│   │   └── error.html      # Error page
│   ├── views.py            # View logic
│   ├── urls.py             # App URLs
│   ├── models.py           # Database models
│   └── apps.py             # App configuration
├── static/                # Static files (if any)
├── manage.py              # Django CLI
├── requirements.txt       # Python dependencies
├── .env                   # Environment variables (not in git)
├── .env.example           # Environment template
├── .gitignore             # Git ignore file
├── Procfile               # Deployment config
├── runtime.txt            # Python version
└── README.md              # This file

License

MIT License - Feel free to use and modify for your projects.


Credits

  • MBTI to Genre mapping inspired by personality-book correlations
  • Powered by Groq LLaMA 3 and Google Books API
  • Built with Django and Bootstrap

About

BookAffinity is a Django web app that recommends books tailored to your personality. Take a 12-question MBTI quiz powered by Groq LLaMA 3 AI, and get personalized book recommendations from Google Books API based on your unique personality type. Built with a clean Bootstrap 5 UI.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages