Building a Yoga Assistant using Lyzr SDK
Tags: ai, lyzr, yoga, python
Published: 2024-07-01 18:05:53

In today’s fast-paced world, finding time for **self-care and wellness** can be challenging. Whether you’re a beginner looking to start your yoga journey or an experienced yogi aiming to deepen your practice, having personalized guidance tailored to your goals and schedule can make all the difference. That’s where technology steps in to lend a helping hand

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

**Yoga Assistant** is an innovative application designed to revolutionize how you experience yoga. Powered by advanced AI technologies like OpenAI’s GPT-4 Turbo and integrated seamlessly through Streamlit, this app is your go-to tool for creating customized yoga sequences and receiving expert guidance, all from the comfort of your home.

**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!**

Create an **app.py** file

```
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
```
This code snippet imports necessary libraries and components for building a Streamlit app integrated with Lyzr Automata’s capabilities. **Streamlit** (streamlit) is imported for developing interactive web applications. It integrates OpenAIModel from Lyzr Automata's AI models for leveraging OpenAI's API. The Agent and Task classes from **Lyzr Automata** manage roles and execute tasks, while LinearSyncPipeline handles data processing pipelines. Image from the Python Imaging Library (PIL) is imported to display images, and os is used to manage environment variables, crucial for API keys and other sensitive information.

```
# Set the OpenAI API key
os.environ["OPENAI_API_KEY"] = st.secrets["apikey"]
```
By setting this environment variable dynamically, the application can authenticate and interact with **OpenAI’s services** securely during runtime. This approach enhances security by keeping sensitive information confidential while enabling seamless integration with external APIs.

```
# App title and introduction
st.title("Yoga Assistant🧘")
st.markdown("Welcome to Yoga Assistant, your personal yoga companion. Tailored to your experience level, goals, and schedule, Yoga Assistant helps you achieve your wellness objectives, whether you're just starting out or are highly experienced one.")
st.markdown("            1) Experience level (beginner, intermediate, advanced).")
st.markdown("            2) Specific goals (flexibility, strength, relaxation, etc).")
st.markdown("            3) Amount of time you could allocate for a yoga session.")
input = st.text_input(" Please enter the above details:",placeholder=f"""Type here""")
```

This block of code sets up the title and introduction of the **Streamlit** application. st.title("Yoga Assistant🧘") creates a prominent title displaying "Yoga Assistant" with a yoga emoji, marking the beginning of the app interface. st.markdown() functions provide formatted text to introduce users to Yoga Assistant as a personalized yoga companion, highlighting its ability to tailor sessions to users' experience levels, goals (like flexibility or strength), and time available for yoga sessions. The st.text_input() function generates an input box where users can enter their details, such as experience level, goals, and session time, facilitating personalized interaction within the app.

```
open_ai_text_completion_model = OpenAIModel(
    api_key=st.secrets["apikey"],
    parameters={
        "model": "gpt-4-turbo-preview",
        "temperature": 0.2,
        "max_tokens": 1500,
    },
)
```
This code snippet initializes an **OpenAIModel** instance for natural language processing tasks within the application. It securely sets the **OpenAI API key** using Streamlit's secrets management (st.secrets["apikey"]) to authenticate access. Parameters like "model": "gpt-4-turbo-preview", "temperature": 0.2, and "max_tokens": 1500 configure how text is generated and controlled by the model, ensuring accurate and contextually appropriate responses tailored to user inputs in the **Yoga Assistant** app.


```
def generation(input):
    generator_agent = Agent(
        role="Expert YOGA INSTRUCTOR and PERSONAL TRAINER",
        prompt_persona=f"Your task is to DESIGN a CUSTOMIZED YOGA SEQUENCE and provide TIPS and MODIFICATIONS tailored to the user's experience, goals, and available time.")
    prompt = f"""
[Prompts here]
 """
```
The **generation function** defines an agent (generator_agent) with the role of an "Expert YOGA INSTRUCTOR and PERSONAL TRAINER". This agent is tasked with creating a personalized yoga sequence and providing tips and modifications tailored to the user's experience level, goals, and available time. The **prompt** variable sets up a detailed instruction for the AI model, outlining steps for analyzing user inputs, designing a suitable yoga sequence, offering pose-specific tips and safety guidelines, and suggesting modifications to accommodate varying levels of flexibility or physical limitations.


```
    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
```
 
In this code snippet, generator_agent_task is an instance of the Task class from Lyzr Automata. It represents a specific task named "**Generation**" that utilizes the open_ai_text_completion_model (initialized earlier) for natural language processing. The generator_agent acts as the agent responsible for executing this task, leveraging its role and prompt persona defined earlier.

The instructions parameter provides the detailed prompt or instructions for the AI model to generate a response. default_input is the input text provided to the **AI model**, typically containing user-provided details such as experience level, goals, and session time for personalized yoga sequence generation.

The **output_type** (OutputType.TEXT) specifies that the task expects a textual output from the AI model. Similarly, input_type (InputType.TEXT) indicates that the input provided to the AI model is in text format.

Finally, **.execute()** triggers the execution of the task using the configured parameters and returns generator_agent_task, which likely contains the generated text or results based on the AI model's processing of the input.

```
if st.button("Assist!"):
    solution = generation(input)
    st.markdown(solution)
```
This section of the code integrates user interaction with AI-generated responses in the Streamlit app. When the user clicks the “**Assist!**” button, the application triggers the generation(input) function, passing the user's input as input.

Whether you’re embarking on your yoga journey or seeking to enrich your current practice, **Yoga Assistant** is your dedicated companion on this wellness path. Embrace the future of yoga practice with AI-driven personalization and redefine how you achieve your health and fitness goals.

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

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

The **Yoga Assistant** 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)