Building a Training Schedule Generator using Lyzr SDK
Tags: ai, streamlit, python, github
Published: 2024-07-01 18:34:12

In the fast-paced world of **athletic training**, having a personalized training plan can make a significant difference in an athlete’s performance. Leveraging advanced AI technologies, we can now create **tailored training schedules** that cater to individual needs. In this blog post, we explore how to develop a Training Schedule Generator app using Lyzr Automata SDK and OpenAI’s GPT-4 Turbo.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c47wz4erheoyauouk4i8.png)

Imagine being able to generate a customized training plan for any sport, considering the athlete’s experience level and the time remaining until their race day. This is now possible with the integration of **Lyzr Automata** and **OpenAI’s GPT-4 Turbo**. This app will guide you through creating a personalized workout plan, ensuring you’re well-prepared to achieve your goals.

**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](https://docs.lyzr.ai/introduction)

**Lets get Started!**

Before diving into the code, ensure you have the necessary libraries installed. We’ll be using **Streamlit** for the web interface, the Lyzr Automata SDK for task management, and the OpenAI API for text generation.

```
pip install streamlit lyzr-automata openai pillow
```
Here’s a breakdown of the code to create our Training Schedule Generator app.

**First, we need to import the required libraries:**

```
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
```
Here **streamlit** is used for creating the web app interface,
**lyzr_automata** SDK provides classes for managing AI models and tasks,**PIL** (Python Imaging Library) is used for handling images and **os** is used for setting environment variables, such as the OpenAI API key.

We need to set up the **OpenAI API key** to authenticate our requests:

```
os.environ["OPENAI_API_KEY"] = st.secrets["apikey"]
```
This line sets the OpenAI API key from Streamlit’s secrets management.

**Now , we add a title and some introductory text to the app:**

```
st.title("Training Schedule Generator")
st.markdown("Welcome to Training Schedule Generator! We create personalized workout plans based on your sport, experience level, and race date, ensuring you're perfectly prepared to crush your goals and perform at your best.")
st.markdown("1) Name of the sports you are participating at.")
st.markdown("2) Mention your experience level.")
st.markdown("3) Mention the amount of time left until the race day.")
Here, we prompt the user to enter their training details:

input = st.text_input("Please enter the above details:", placeholder="Type here")
```
**We configure the OpenAI model with specific parameters later on:**

```

open_ai_text_completion_model = OpenAIModel(
    api_key=st.secrets["apikey"],
    parameters={
        "model": "gpt-4-turbo-preview",
        "temperature": 0.2,
        "max_tokens": 1500,
    },
)
```
**Defining the Training Plan Generation Function**
We define a function to generate the training plan:

```
def generation(input):
    generator_agent = Agent(
        role="Expert ATHLETIC COACH and PERSONAL TRAINER",
        prompt_persona="Your task is to DEVELOP a personalized training plan based on the INPUTS provided: the SPORT NAME, the athlete's EXPERIENCE LEVEL, and the RACE DATE.")
    prompt = """
[Prompts here]
   """
```

```
    generator_agent_task = Task(
        name="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
```
**We add a button to generate the training plan when clicked:**

```
if st.button("Generate"):
    solution = generation(input)
    st.markdown(solution)
```
By leveraging the power of **Lyzr Automata** and **OpenAI’s GPT-4 Turbo**, we can create a highly customized and effective training schedule generator. This app allows athletes to input their specific needs and receive a tailored training plan to help them achieve their goals. Whether you’re a coach or an athlete, this tool can be a game-changer in **optimizing performance** and ensuring readiness for race day.

**App link**: https://trainingassistant-lyzr.streamlit.app/

**Source Code**: https://github.com/isakshay007/Training_Assistant

The **Training Schedule Generator** is powered by the Lyzr Automata Agent, utilizing the capabilities of OpenAI’s GPT-4 Turbo. For any inquiries or issues, please contact Lyzr. You can learn more about Lyzr and their offerings through the following links:

**Website**: [Lyzr.ai](https://www.lyzr.ai/)
**Book a Demo**: [Book a Demo](https://www.lyzr.ai/book-demo/)
**Discord**: [Join our Discord community](https://discord.com/invite/nm7zSyEFA2)
**Slack**: [Join our Slack channel](https://anybodycanai.slack.com/join/shared_invite/zt-2a7fr38f7-_QDOY1W1WSlSiYNAEncLGw#/shared-invite/email)