Skip to content

About

Telegram bot that analyzes food photos and provides recipes and nutrition facts (KBJU). Supports Russian, English, and Armenian

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

🍽 FoodLens Bot

A Telegram bot that analyzes food photos and provides recipes and nutrition facts (KBJU). Supports three languages.

Python License Gemini aiogram


✨ Features

  • 📸 Photo Analysis — send a food photo and get the dish name instantly
  • 🔥 Nutrition Facts — calories, protein, fat, carbs per serving
  • 📖 Recipe — step-by-step recipe for the identified dish
  • 💾 Food Diary — save meals and track daily nutrition
  • 🌐 3 Languages — Russian, English, Armenian

🛠 Tech Stack

  • Python 3.11
  • aiogram 3 — Telegram bot framework
  • Google Gemini API — food photo analysis (gemini-2.0-flash-lite)
  • SQLite — local database for food diary
  • python-dotenv

📁 Project Structure

foodlens-bot/
├── .env                  # your secret keys (not in GitHub)
├── .gitignore
├── bot.py                # entry point
├── requirements.txt
│
├── handlers/
│   ├── __init__.py
│   ├── start.py          # /start and language selection
│   ├── photo.py          # food photo handler
│   └── menu.py           # menu buttons handler
│
├── services/
│   ├── __init__.py
│   ├── vision.py         # Gemini food photo analysis
│   ├── nutrition.py      # Gemini nutrition facts
│   └── recipe.py         # Gemini recipe generation
│
├── locales/
│   ├── __init__.py
│   ├── ru.py             # Russian
│   ├── en.py             # English
│   └── hy.py             # Armenian
│
├── keyboards/
│   ├── __init__.py
│   └── main_kb.py        # reply & inline keyboards
│
└── database/
    ├── __init__.py
    └── db.py             # SQLite logic

⚠️ .env and foodlens.db are excluded from GitHub via .gitignore — your keys and data stay private.


🏗 Architecture

User (Telegram)
      │
      ▼
  bot.py  ──────────────────────────────────────┐
  (Dispatcher)                                  │
      │                                         │
      ├── handlers/start.py                     │
      │       └── Language selection            │
      │                                         │
      ├── handlers/photo.py                     │
      │       ├── services/vision.py ───────► Gemini API
      │       ├── services/nutrition.py ─────► Gemini API
      │       └── services/recipe.py ────────► Gemini API
      │                                         │
      ├── handlers/menu.py                      │
      │       ├── Food diary                    │
      │       ├── Save meal                     │
      │       └── Settings                      │
      │                                         │
      ├── database/db.py ◄────────────────────┘
      │       ├── users table
      │       └── food_log table
      │
      ├── keyboards/main_kb.py
      │       ├── main_menu()
      │       ├── result_keyboard()
      │       └── language_keyboard()
      │
      └── locales/
              ├── ru.py
              ├── en.py
              └── hy.py

Data Flow

[User sends photo]
        │
        ▼
[photo.py downloads photo bytes]
        │
        ▼
[vision.py → Gemini] ──► dish_name, dish_name_en, portion_grams
        │
        ▼
[nutrition.py + recipe.py → Gemini] (parallel)
        │
        ▼
[Bot sends nutrition card + result keyboard]
        │
        ▼
[User taps 📖 Recipe] → menu.py sends recipe text
[User taps 💾 Save]   → db.py saves to food_log
[User taps 📊 Diary]  → db.py fetches today's log

🚀 Getting Started

1. Clone the repository

git clone https://github.com/TyomPapiyan/foodlens-bot.git
cd foodlens-bot

2. Create virtual environment

py -3.11 -m venv venv
venv\Scripts\activate

3. Install dependencies

pip install -r requirements.txt

4. Create .env file

TELEGRAM_TOKEN=your_telegram_bot_token
GEMINI_API_KEY=your_gemini_api_key

5. Run the bot

python bot.py

💬 Example

You:  [sends a photo of pizza]

Bot:  🍽 Pizza Margherita

      Nutrition per serving:
      🔥 Calories: 266 kcal
      🥩 Protein: 11 g
      🧈 Fat: 10 g
      🌾 Carbs: 33 g
      ⚖️ Portion: 200 g

📋 Commands & Buttons

Button / Command Description
📸 Analyse photo Send a food photo for analysis
📖 Recipe Get recipe for the last dish
💾 Save Save meal to food diary
📊 Food diary View today's nutrition summary
⚙️ Settings Change language
🚪 Exit Stop the bot
🔄 Restart Start over

🗄 Database Schema

-- Stores user language preference
CREATE TABLE users (
    user_id   INTEGER PRIMARY KEY,
    language  TEXT DEFAULT 'ru',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Stores food log entries
CREATE TABLE food_log (
    id         INTEGER PRIMARY KEY AUTOINCREMENT,
    user_id    INTEGER,
    dish_name  TEXT,
    calories   REAL,
    protein    REAL,
    fat        REAL,
    carbs      REAL,
    logged_at  TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (user_id) REFERENCES users(user_id)
);

📄 License

This project is licensed under the MIT License — feel free to use, modify, and distribute it.

MIT License — © 2026 TyomPapiyan

About

Telegram bot that analyzes food photos and provides recipes and nutrition facts (KBJU). Supports Russian, English, and Armenian

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages