Sasvataa
commited on
Commit
•
41cef72
1
Parent(s):
a8d1ab0
Initial Commit
Browse files- Prompts/Gym.prompt +8 -0
- Prompts/Gym_home.prompt +8 -0
- Prompts/Home.prompt +8 -0
- Resource/td-logo.png +0 -0
- app.py +101 -0
- requirements.txt +5 -0
- utils/BMI_graph.py +57 -0
- utils/llm_helper.py +135 -0
Prompts/Gym.prompt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
A person named {name} who is {age} years old with height of {height} cm and weight is {weight} kg and gender is {gender}
|
2 |
+
{gender_suffix} wants to {fitness_goal} and {gender_suffix} doesn't have any medical condition
|
3 |
+
make a day by day workout plane for Gym
|
4 |
+
|
5 |
+
make sure you can cover up whole body in a week
|
6 |
+
Give only day by day very detailed workout plan with how many sets and reps
|
7 |
+
Mention day name (e.g. "Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
|
8 |
+
Provied additioal tips and some motivation wothout any extra information at the end and make a box around it
|
Prompts/Gym_home.prompt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
A person named {name} who is {age} years old with height of {height} cm and weight is {weight} kg and gender is {gender}
|
2 |
+
{gender_suffix} wants to {fitness_goal} and {gender_suffix} doesn't have any medical condition
|
3 |
+
make a day by day workout plane for Home and Gym both
|
4 |
+
Consider {additioal_info}
|
5 |
+
|
6 |
+
Give only day by day very detailed workout plan with how many sets and reps
|
7 |
+
Mention day name (e.g. "Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
|
8 |
+
Provied additioal tips and some motivation wothout any extra information at the end and make a box around it
|
Prompts/Home.prompt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
A person named {name} who is {age} years old with height of {height} cm and weight is {weight} kg and gender is {gender}
|
2 |
+
{gender_suffix} wants to {fitness_goal} and {gender_suffix} doesn't have any medical condition
|
3 |
+
make a day by day workout plane for Home
|
4 |
+
|
5 |
+
make sure {gender_suffix} doesn't have access of the gym so give a workout plan accordingly
|
6 |
+
Give only day by day very detailed workout plan with how many reps for each excersise and time taken by that excersise
|
7 |
+
Mention day name (e.g. "Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
|
8 |
+
Provied additioal tips and some motivation wothout any extra information at the end and make a box around it
|
Resource/td-logo.png
ADDED
app.py
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
import utils.llm_helper as helper
|
4 |
+
import utils.BMI_graph as plot
|
5 |
+
|
6 |
+
def main():
|
7 |
+
# Page icon
|
8 |
+
icon = Image.open('Resource/td-logo.png')
|
9 |
+
|
10 |
+
# Page config
|
11 |
+
st.set_page_config(page_title="GYM",
|
12 |
+
page_icon=icon,
|
13 |
+
layout="wide"
|
14 |
+
)
|
15 |
+
|
16 |
+
company_logo_path = 'Resource/td-logo.png'
|
17 |
+
st.sidebar.image(company_logo_path, width=50)
|
18 |
+
|
19 |
+
name = st.sidebar.text_input("Name")
|
20 |
+
|
21 |
+
# Non-negative Integer Field for Age
|
22 |
+
age = st.sidebar.number_input("Age", min_value=0, step=1)
|
23 |
+
|
24 |
+
# Non-negative Float Field for Weight
|
25 |
+
weight = st.sidebar.number_input("Weight (kg)", min_value=0.0, step=0.1)
|
26 |
+
|
27 |
+
# Non-negative Float Field for Height
|
28 |
+
height = st.sidebar.number_input("Height (cm)", min_value=0.0, step=0.1)
|
29 |
+
|
30 |
+
# Long Text Field for Medical Conditions
|
31 |
+
medical_conditions = st.sidebar.text_area("Medical Conditions")
|
32 |
+
|
33 |
+
# Radio Button for Gender
|
34 |
+
gender_options = ["Male", "Female"]
|
35 |
+
gender = st.sidebar.radio("Gender", gender_options,horizontal=True)
|
36 |
+
|
37 |
+
# Checkbox for Fitness Goals
|
38 |
+
st.sidebar.write("Accessability")
|
39 |
+
access_options = ["Gym", "Home"]
|
40 |
+
accessability = st.sidebar.multiselect("Select options:", access_options)
|
41 |
+
if accessability == [] or len(accessability) == 1:
|
42 |
+
flexibility = ''
|
43 |
+
gym = 0
|
44 |
+
home = 0
|
45 |
+
gym_home = gym + home
|
46 |
+
else:
|
47 |
+
flexibility_option = ["Gym & Home everyday", "Gym & Home on alternate day","Specify a day"]
|
48 |
+
flexibility = st.sidebar.radio("Flexibility", flexibility_option,horizontal=True)
|
49 |
+
if flexibility_option == 'Gym & Home everyday':
|
50 |
+
flexibility_option = 'Provide a workout plane each day Gym workout and home workout so same day both workout plane should be there (e.g. Day 1 : Monday Gym,Home Day 2 : Tuesday Gym,Home till Day 7 : Sunday Gym,Home)'
|
51 |
+
elif flexibility == 'Specify a day':
|
52 |
+
gym = st.sidebar.number_input("Gym day", min_value=1, step=1)
|
53 |
+
home = st.sidebar.number_input("Home day", min_value=1, step=1)
|
54 |
+
gym_home = gym + home
|
55 |
+
else:
|
56 |
+
gym = 0
|
57 |
+
home = 0
|
58 |
+
gym_home = gym + home
|
59 |
+
|
60 |
+
|
61 |
+
|
62 |
+
# Checkbox for Fitness Goals
|
63 |
+
st.sidebar.write("Fitness Goals")
|
64 |
+
fitness_goals_options = ["Weight Loss", "Stay Fit", "Muscle Building"]
|
65 |
+
selected_options = st.sidebar.multiselect("Select options:", fitness_goals_options)
|
66 |
+
|
67 |
+
if st.sidebar.button("Submit"):
|
68 |
+
if age == 0:
|
69 |
+
st.error("Age is a mandatory field.")
|
70 |
+
elif weight == 0:
|
71 |
+
st.error("weight is a mandatory field.")
|
72 |
+
elif height == 0:
|
73 |
+
st.error("height is a mandatory field.")
|
74 |
+
elif len(access_options) == 0:
|
75 |
+
st.error("Select atleast one option.")
|
76 |
+
elif gym_home >=8:
|
77 |
+
st.error("Gym day and Home day as per week please check value addition of both values should be 7 or less")
|
78 |
+
elif len(selected_options) == 0:
|
79 |
+
st.error("Select atleast one fitness goal.")
|
80 |
+
else:
|
81 |
+
with st.spinner('Generating Workout Plan...'):
|
82 |
+
#with st.container(border=True):
|
83 |
+
if name != '':
|
84 |
+
st.title(f"***Hello {name}***")
|
85 |
+
else:
|
86 |
+
st.title(f"***Hello There***")
|
87 |
+
|
88 |
+
fig = plot.BMI_Value(height=height, weight=weight)
|
89 |
+
#fig.update_traces(x=[value], selector=dict(name="Value"))
|
90 |
+
#fig.update_traces(x=[max_value], selector=dict(name="Forward Arrow"))
|
91 |
+
st.plotly_chart(fig)
|
92 |
+
#st.write(name,age,weight,height,gender,accessability,flexibility,gym,home,selected_options)
|
93 |
+
response = helper.main(name,age,weight,height,gender,accessability,flexibility,gym,home,selected_options)
|
94 |
+
st.write(response)
|
95 |
+
|
96 |
+
|
97 |
+
|
98 |
+
|
99 |
+
|
100 |
+
if __name__ == '__main__':
|
101 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
langchain==0.2.4
|
2 |
+
streamlit==1.35.0
|
3 |
+
google-ai-generativelanguage==0.6.4
|
4 |
+
google-generativeai==0.6.0
|
5 |
+
plotly==5.22.0
|
utils/BMI_graph.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import plotly.graph_objs as go
|
3 |
+
|
4 |
+
def BMI_Value(height,weight):
|
5 |
+
height = height/100
|
6 |
+
bmi = weight / (height ** 2)
|
7 |
+
|
8 |
+
|
9 |
+
color = "black"
|
10 |
+
if bmi <= 18.5:
|
11 |
+
bmi_class = 'Thin'
|
12 |
+
color = "blue"
|
13 |
+
elif bmi < 24.0:
|
14 |
+
bmi_class = 'Ideal'
|
15 |
+
color = "green"
|
16 |
+
elif bmi < 28.0:
|
17 |
+
bmi_class = 'Fat'
|
18 |
+
color = "yellow"
|
19 |
+
else:
|
20 |
+
bmi_class = 'Obesity'
|
21 |
+
color = "red"
|
22 |
+
|
23 |
+
fig = go.Figure(go.Indicator(
|
24 |
+
mode = "gauge+number",
|
25 |
+
value = bmi,
|
26 |
+
domain = {'x': [0, 1], 'y': [0, 1]},
|
27 |
+
title = {'text': "BMI"},
|
28 |
+
number = {'font': {'color': color},'suffix': f"<br>({bmi_class})"}, # Change number color based on value
|
29 |
+
gauge = {'axis': {'range': [None, 60]},
|
30 |
+
'bar': {'color': "white",'thickness': 0},
|
31 |
+
'steps' : [
|
32 |
+
{'range': [0, 18.5], 'color': "blue"},
|
33 |
+
{'range': [18.5, 24.0], 'color': "green"},
|
34 |
+
{'range': [24.0, 28.0], 'color': "yellow"},
|
35 |
+
{'range': [28.0, 60], 'color': "red"}],
|
36 |
+
'threshold' : {'line': {'color': "black", 'width': 7}, 'thickness': 1, 'value': bmi}}))
|
37 |
+
|
38 |
+
fig.add_trace(go.Scatter(
|
39 |
+
x=[0],
|
40 |
+
y=[0],
|
41 |
+
#marker=dict(color="red", size=12),
|
42 |
+
showlegend=False,
|
43 |
+
name="BMI",
|
44 |
+
))
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
fig.update_layout(width=400, height=300, plot_bgcolor='rgba(0,0,0,0)', showlegend=False, xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
49 |
+
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False))
|
50 |
+
|
51 |
+
fig.update_traces(x=[bmi], selector=dict(name="BMI"))
|
52 |
+
|
53 |
+
return fig
|
54 |
+
|
55 |
+
|
56 |
+
if __name__ == "__main__":
|
57 |
+
BMI_Value()
|
utils/llm_helper.py
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import google.generativeai as genai
|
3 |
+
from langchain.prompts import PromptTemplate
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
|
6 |
+
|
7 |
+
load_dotenv()
|
8 |
+
GOOGLE_API_KEY = os.getenv('GOOGLE_GEMINI_API_KEY')
|
9 |
+
|
10 |
+
genai.configure(api_key=GOOGLE_API_KEY)
|
11 |
+
model = genai.GenerativeModel('gemini-pro')
|
12 |
+
|
13 |
+
def Gym(name,age,weight,height,gender,selected_options):
|
14 |
+
if gender == 'Male':
|
15 |
+
gender_suffix = 'He'
|
16 |
+
elif gender == 'Female':
|
17 |
+
gender_suffix = 'She'
|
18 |
+
|
19 |
+
if len(selected_options) == 1:
|
20 |
+
selected_options = selected_options[0]
|
21 |
+
else:
|
22 |
+
selected_options = additioal_info = ' and '.join(selected_options)
|
23 |
+
|
24 |
+
with open("Prompts/Gym.prompt", "r") as f:
|
25 |
+
template = f.read()
|
26 |
+
|
27 |
+
template = PromptTemplate(template=template,input_variables=["name","age","height","weight","gender","gender_suffix","fitness_goal"])
|
28 |
+
formatted_input = template.format_prompt(
|
29 |
+
name = name,
|
30 |
+
age = age,
|
31 |
+
height = weight,
|
32 |
+
weight = height,
|
33 |
+
gender = gender,
|
34 |
+
gender_suffix = gender_suffix,
|
35 |
+
fitness_goal = selected_options
|
36 |
+
)
|
37 |
+
|
38 |
+
response = model.generate_content(formatted_input.to_string())
|
39 |
+
|
40 |
+
final_response = response.text
|
41 |
+
|
42 |
+
return final_response
|
43 |
+
|
44 |
+
def Home(name,age,weight,height,gender,selected_options):
|
45 |
+
if gender == 'Male':
|
46 |
+
gender_suffix = 'He'
|
47 |
+
elif gender == 'Female':
|
48 |
+
gender_suffix = 'She'
|
49 |
+
|
50 |
+
if len(selected_options) == 1:
|
51 |
+
selected_options = selected_options[0]
|
52 |
+
else:
|
53 |
+
selected_options = additioal_info = ' and '.join(selected_options)
|
54 |
+
|
55 |
+
with open("Prompts/Home.prompt", "r") as f:
|
56 |
+
template = f.read()
|
57 |
+
|
58 |
+
template = PromptTemplate(template=template,input_variables=["name","age","height","weight","gender","gender_suffix","fitness_goal"])
|
59 |
+
formatted_input = template.format_prompt(
|
60 |
+
name = name,
|
61 |
+
age = age,
|
62 |
+
height = weight,
|
63 |
+
weight = height,
|
64 |
+
gender = gender,
|
65 |
+
gender_suffix = gender_suffix,
|
66 |
+
fitness_goal=selected_options,
|
67 |
+
)
|
68 |
+
|
69 |
+
response = model.generate_content(formatted_input.to_string())
|
70 |
+
|
71 |
+
final_response = response.text
|
72 |
+
|
73 |
+
return final_response
|
74 |
+
|
75 |
+
def Gym_Home(name,age,weight,height,gender,selected_options,flexibility,gym,home):
|
76 |
+
if gender == 'Male':
|
77 |
+
gender_suffix = 'He'
|
78 |
+
elif gender == 'Female':
|
79 |
+
gender_suffix = 'She'
|
80 |
+
|
81 |
+
if flexibility == 'Specify a day':
|
82 |
+
additioal_info = str(gym) + " day Gym and " + str(home) + ' day home.'
|
83 |
+
else:
|
84 |
+
additioal_info = ' and '.join(flexibility)
|
85 |
+
|
86 |
+
if len(selected_options) == 1:
|
87 |
+
selected_options = selected_options[0]
|
88 |
+
else:
|
89 |
+
selected_options = additioal_info = ' and '.join(selected_options)
|
90 |
+
|
91 |
+
with open("Prompts/Gym_home.prompt", "r") as f:
|
92 |
+
template = f.read()
|
93 |
+
|
94 |
+
template = PromptTemplate(template=template,input_variables=["name","age","height","weight","gender","gender_suffix","additioal_info","fitness_goal"])
|
95 |
+
formatted_input = template.format_prompt(
|
96 |
+
name = name,
|
97 |
+
age = age,
|
98 |
+
height = weight,
|
99 |
+
weight = height,
|
100 |
+
gender = gender,
|
101 |
+
gender_suffix = gender_suffix,
|
102 |
+
additioal_info = additioal_info,
|
103 |
+
fitness_goal=selected_options
|
104 |
+
)
|
105 |
+
|
106 |
+
response = model.generate_content(formatted_input.to_string())
|
107 |
+
|
108 |
+
final_response = response.text
|
109 |
+
|
110 |
+
return final_response
|
111 |
+
|
112 |
+
def main(form_name,form_age,form_weight,form_height,form_gender,form_access,form_flexibility,form_gym,form_home,form_selected_options):
|
113 |
+
if len(form_access) == 1:
|
114 |
+
if form_access[0] == 'Gym':
|
115 |
+
final_response = Gym(name = form_name,age = form_age,weight = form_weight,height = form_height,gender = form_gender,selected_options = form_selected_options)
|
116 |
+
elif form_access[0] == 'Home':
|
117 |
+
final_response = Home(name = form_name,age = form_age,weight = form_weight,height = form_height,gender = form_gender,selected_options = form_selected_options)
|
118 |
+
else:
|
119 |
+
final_response = 'Something went wrong'
|
120 |
+
elif form_access == ['Gym','Home']:
|
121 |
+
final_response = Gym_Home(name = form_name,age = form_age,weight = form_weight,height = form_height,gender = form_gender,selected_options = form_selected_options,flexibility=form_flexibility,gym=form_gym,home=form_home)
|
122 |
+
else:
|
123 |
+
final_response = 'Something went wrong'
|
124 |
+
|
125 |
+
return final_response
|
126 |
+
|
127 |
+
|
128 |
+
if __name__ == "__main__":
|
129 |
+
print(main(
|
130 |
+
name = 'Dharmik',
|
131 |
+
age = 25,
|
132 |
+
height = 178,
|
133 |
+
weight = 97.7,
|
134 |
+
gender = 'Male'
|
135 |
+
))
|