Food Calorie Tracker - Val Town Version

A web-based food calorie tracker that estimates calories using AI and logs them to Notion.

Features

  • 🍎 Web interface for entering food descriptions
  • 🤖 AI-powered calorie estimation using OpenAI GPT-4o
  • 📊 Automatic logging to Notion database
  • 🎨 Clean, responsive UI with TailwindCSS

Setup

Environment Variables

Set these environment variables in your Val Town account:

  • NOTION_OAUTH_TOKEN - Your Notion OAuth token
  • OPENAI_API_KEY - Your OpenAI API key (handled by Val Town's OpenAI integration)

Notion Database

Your Notion database should have these properties:

  • Name (Title) - Food name
  • Calories (Number) - Calorie count
  • Date (Date) - Entry date (auto-populated)

Update the notionFoodDbId in notion.ts with your database ID.

Usage

  1. Visit the HTTP endpoint URL for your Val Town
  2. Enter a food description (e.g., "RT Rotisserie bowl with chicken and beet tahini sauce")
  3. Click "Estimate Calories & Log"
  4. View the AI's calorie estimate and confirmation of Notion logging

Architecture

  • main.http.ts - HTTP trigger with web interface and AI integration
  • notion.ts - Notion API integration for logging food entries
  • Uses Val Town's OpenAI integration for GPT-4o access
  • Responsive web UI built with TailwindCSS

Migration from Original

This version has been migrated from a Bun CLI script to a Val Town HTTP trigger:

  • ✅ Uses Val Town's OpenAI integration instead of direct OpenAI SDK
  • ✅ Environment variables use Deno.env.get() instead of process.env
  • ✅ ESM imports from https://esm.sh for compatibility
  • ✅ Web interface instead of CLI
  • ✅ HTTP trigger following Val Town conventions