Logo

dev-resources.site

for different kinds of informations.

Building a Workout Planner App with Lyzr SDK

Published at
4/28/2024
Categories
ai
opensource
lyzr
workout
Author
akshay007
Categories
4 categories in total
ai
open
opensource
open
lyzr
open
workout
open
Author
9 person written this
akshay007
open
Building a Workout Planner App with Lyzr SDK

In today’s fitness landscape, achieving personal fitness goals requires more than just hitting the gym randomly. Customized workout plans tailored to individual goals and preferences are becoming increasingly essential. To streamline this process, we’ve developed a user-friendly Streamlit application that leverages AI to generate personalized workout plans.

Image description

Our Workout Planner App aims to revolutionize how fitness enthusiasts approach their training routines. Powered by advanced AI models and designed with user convenience in mind, this app allows users to create tailored workout plans aligned with their specific fitness objectives and time commitments.

Why use Lyzr SDK’s?

With Lyzr SDKs, crafting your own GenAI application is a breeze, requiring only a few lines of code to get up and running swiftly.

Checkout the Lyzr SDK’s

Lets get Started!

Create a new file app.py and use that

import streamlit as st
from lyzr_automata.ai_models.openai import OpenAIModel
from lyzr_automata import Agent, Task
from lyzr_automata.pipelines.linear_sync_pipeline import LinearSyncPipeline
from PIL import Image
from lyzr_automata.tasks.task_literals import InputType, OutputType
import os
Enter fullscreen mode Exit fullscreen mode

This Python script utilizes Streamlit for creating a web interface and integrates custom modules for automata-related functionality. It imports classes for defining agents, tasks, and pipelines, potentially involving image processing and machine learning tasks with OpenAI models.

This line of code sets “OPENAI_API_KEY” to the value stored in the Streamlit secrets dictionary under the key “apikey”. This API key is essential for authenticating and accessing the OpenAI API, allowing the application to utilize OpenAI’s models and services for natural language processing tasks. By assigning the API key to the environment variable, it ensures that subsequent requests made to the OpenAI API are properly authenticated.

# Set the OpenAI API key
os.environ["OPENAI_API_KEY"] = st.secrets["apikey"]
Enter fullscreen mode Exit fullscreen mode
open_ai_text_completion_model = OpenAIModel(
    api_key=st.secrets["apikey"],
    parameters={
        "model": "gpt-4-turbo-preview",
        "temperature": 0.2,
        "max_tokens": 1500,
    },
)
Enter fullscreen mode Exit fullscreen mode

This block of code initializes an instance of the OpenAIModel class with specific parameters. The api_key parameter is set to the value retrieved from Streamlit secrets, ensuring authentication with the OpenAI API. The parameters dictionary contains settings for the AI model, specifying “gpt-4-turbo-preview” as the model to be used, a temperature of 0.2, and a maximum token limit of 1500. These settings configure how the model generates text responses, controlling factors such as creativity and length. The initialized OpenAIModel instance will be utilized for generating text based on input prompts in subsequent parts of the code.

def workout_generation(input):
    generator_agent = Agent(
        role="FITNESS TRAINER expert",
        prompt_persona=f"Your task  is to DESIGN CUSTOMIZED WORKOUT SPLITS that cater to various user goals, including STRENGTH, ENDURANCE, FLEXIBILITY, BODY COMPOSITION, PERFORMANCE, FUNCTIONAL FITNESS, HEALTH AND WELLNESS, SPORT-SPECIFIC requirements, CONSISTENCY in training, and the DURATION of the workout program."
    )

    prompt = f"""
You are an Expert FITNESS TRAINER. Your task is to DESIGN CUSTOMIZED WORKOUT SPLITS that cater to various user goals, including STRENGTH, ENDURANCE, FLEXIBILITY, BODY COMPOSITION, PERFORMANCE, FUNCTIONAL FITNESS, HEALTH AND WELLNESS, SPORT-SPECIFIC requirements, CONSISTENCY in training, and the DURATION of the workout program.

---------

----------

   """
Enter fullscreen mode Exit fullscreen mode

This function, workout_generation, is designed to generate customized workout splits. It begins by creating an agent with the role of a fitness trainer expert, providing a prompt persona specifying the task of designing workout splits tailored to various user goals such as strength, endurance, flexibility, and more. The function then constructs a prompt string incorporating this persona, prompting the fitness trainer to fulfill the task.

generator_agent_task = Task(
        name="workout Generation",
        model=open_ai_text_completion_model,
        agent=generator_agent,
        instructions=prompt,
        default_input=input,
        output_type=OutputType.TEXT,
        input_type=InputType.TEXT,
    ).execute()

    return generator_agent_task 

if st.button("Generate!"):
    solution = workout_generation(input)
    st.markdown(solution)
Enter fullscreen mode Exit fullscreen mode

This code segment defines a task named “workout Generation” with specific parameters including the name, the OpenAI text completion model, an agent assigned to handle the task, instructions provided as a prompt, default input, and the expected input and output types. The task is then executed, returning the result stored in generator_agent_task. Subsequently, it checks if a button labeled "Generate!" is clicked using Streamlit's st.button function. If the button is clicked, it triggers the workout_generation function, passing the input provided by the user. The result is then displayed using st.markdown.

With just a few clicks, users can access expertly curated workout plans tailored to their unique needs and preferences. Whether you’re a beginner embarking on your fitness journey or a seasoned athlete seeking to optimize your training regime, our Workout Planner App is your ultimate companion for achieving fitness success.

App link: https://workoutplanner-lyzr.streamlit.app/

Source Code: https://github.com/isakshay007/workout_planner

Connect with Lyzr
To learn more about Lyzr and its SDK’s, visit our website or get in touch with our team:

Website: Lyzr.ai
Book a Demo: Book a Demo
Discord: Join our Discord community
Slack: Join our Slack channel

lyzr Article's
30 articles in total
Favicon
Building a Yoga Assistant using Lyzr SDK
Favicon
Building a Smart Home Setup Assistant using Lyzr SDK
Favicon
Building a Remote Team Management Assistant Lyzr SDK
Favicon
Building a Troubleshoot Assistant using Lyzr SDK
Favicon
Consult with AI Neurologist with Lyzr Automata, Streamlit and OpenAI
Favicon
Simplify Restaurant Reservations with Lyzr.ai's Chatbot-Powered App
Favicon
Revolutionize Your Podcast Content Creation with Lyzr's Podcast Series Generator
Favicon
Automating YouTube Script Writing with Lyzr Automata
Favicon
AI-Driven Art Analysis and Generation with Lyzr Automata
Favicon
Elevate Your Interview Preparation with the AI Interviewer App
Favicon
Simplify Instagram Content Creation with Caption Studio by Lyzr.ai
Favicon
Building Book Recommendation Assistant with Lyzr Automata
Favicon
Building a Mood Analyzer App with Lyzr Automata
Favicon
Building Text Toxicity Classifier using Lyzr Automata
Favicon
Building a First Aid Assistant with Lyzr SDK
Favicon
Building Job Consultant Bot with Lyzr SDK
Favicon
Building a Personalized News Agent with Lyzr Automata
Favicon
Building a Workout Planner App with Lyzr SDK
Favicon
Building a Skin Care Assistant with Lyzr Automata
Favicon
In Just 5 Minutes: How I Created a Bot to Discover World Heritage Sites
Favicon
Building a Personalized Playlist Generator with Lyzr Automata
Favicon
Building Idea Generator with Lyzr SDK
Favicon
Building NL2MongoDB with Lyzr SDK
Favicon
Simplifying Exploratory Data Analysis with Lyzr Agent
Favicon
Building a Lyzr-powered Chatbot for Educational Purposes
Favicon
Building Domain Name Generator using Lyzr SDK
Favicon
Building Environmental Analyzer using Lyzr SDK
Favicon
Building Student Advisor using Lyzr SDK
Favicon
Revolutionize Education with Lyzr's Question-Answer Generator
Favicon
Discover Recipes Easily with Lyzr ChatBot

Featured ones: