Home > Article > Backend Development > Building a GenAI Fitness App with Gemini
Last summer, when I found out about the Gemini API Developer Competition, I saw it as a great chance to get my hands dirty with GenAI applications. As fitness enthusiasts, we (me & Manos Chainakis) thought of creating an app that could generate personalised workout and nutrition plans—combining AI with the preferences of human coaches. That’s how Fitness Tribe AI was born. This post will walk you through the development process and the tech stack I used, with focus on the GenAI aspect.
Fitness Tribe AI combines the expertise of human coaches with the capabilities of AI models to create custom fitness programs that meet each athlete's needs and goals.
The main components of the tech stack are:
FastAPI serves as the backbone of Fitness Tribe AI, handling the AI-powered analysis.
Here’s how the project is structured:
fitness-tribe-ai/ ├── app/ │ ├── main.py # Entry point for FastAPI app │ ├── routers/ # Handles API routes (meals, nutrition, workouts) │ ├── models/ # Manages interactions with AI models │ ├── schemas/ # Pydantic models for input validation │ ├── services/ # Business logic for each feature
from fastapi import FastAPI from app.routers import meals, nutrition, workouts app = FastAPI() app.include_router(meals.router) app.include_router(nutrition.router) app.include_router(workouts.router)
class GeminiModel: @staticmethod def analyze_meal(image_data): prompt = ( "Analyze the following meal image and provide the name of the food, " "total calorie count, and calories per ingredient..." "Respond in the following JSON format:" "{'food_name': 'df57eb746fe8e90f79b5901b2a85225c' ...}" ) image = Image.open(BytesIO(image_data)) response = model.generate_content([prompt, image]) return response.text
from pydantic import BaseModel from typing import Dict class Meal(BaseModel): food_name: str total_calories: int calories_per_ingredient: Dict[str, int]
from app.models.gemini_model import GeminiModel from app.schemas.meal import Meal from fastapi import HTTPException import logging import json def analyze_meal(image_data: bytes) -> Meal: try: result_text = GeminiModel.analyze_meal(image_data) if not result_text: raise HTTPException(status_code=500, detail="No response from Gemini API") clean_result_text = result_text.strip("``` json\n").strip(" ```") result = json.loads(clean_result_text) return Meal( food_name=result.get("food_name"), total_calories=result.get("total_calories"), calories_per_ingredient=result.get("calories_per_ingredient"), ) except Exception as e: raise HTTPException(status_code=500, detail=str(e))
By leveraging FastAPI’s modular structure, clear API routing, Pydantic for data validation, and well-organized service logic, Fitness Tribe AI efficiently handles AI model interactions with custom prompts to deliver personalized fitness and nutrition insights. You can find the full repo here:
Fitness Tribe AI is an AI-powered fitness API designed for coaches and athletes. The API provides meal analysis functionality by analyzing meal photos and an AI powered workout builder, which can generate workout plans based on athlete profiles. Fitness Tribe AI has been built the Gemini model.
fitness-tribe-ai/ ├── app/ │ ├── __init__.py │ ├── main.py │ ├── models/ │ │ ├── __init__.py │ │ ├── gemini_model.py │ ├── routers/ │ │ ├── __init__.py │ │ ├── meals.py │ │ ├── nutrition.py │ │ ├── workouts.py │ ├── schemas/ │ │ ├── __init__.py │ │ ├── meal.py │ │ ├── nutrition.py │ │ ├──…
For user authentication and account management, I used Supabase, which provided a secure, scalable solution without requiring a custom-built authentication system.
Key features I leveraged:
Authentication: Supabase's built-in authentication enabled users to log in and manage their profiles with ease.
Database Management: Using Supabase’s PostgreSQL-backed database, I stored user preferences, workout routines, and meal plans to ensure updates reflected immediately in the app.
For the frontend, I chose Ionic and Angular, which enabled me to create a mobile-first app that could be deployed on the web right away while it could also be shipped as native for both iOS and Android.
For the landing page, I opted for Astro, which focuses on performance by shipping minimal JavaScript. Astro allowed me to build a fast, lightweight page that efficiently showcased the app.
Developing Fitness Tribe AI was a learning journey that enabled me to explore the power that AI models give us nowadays. Each framework played a role, from FastAPI’s robust backend capabilities and ease of use to Supabase’s user management, Ionic’s cross-platform frontend and Astro’s high-performance landing pages.
For anyone looking to build a GenAI app, I highly recommend exploring these frameworks (and especially FastAPI) for their powerful features and smooth developer experience.
Have questions or want to learn more about it? Let me know in the comments!
The above is the detailed content of Building a GenAI Fitness App with Gemini. For more information, please follow other related articles on the PHP Chinese website!