Spaces:
Runtime error
Runtime error
from langchain.prompts import PromptTemplate | |
from langchain.chains import LLMChain | |
from langchain.llms import OpenAI | |
from load_model import call_palm | |
from calling_apis import google_api_key, openai_api_key | |
def workout_plan_gen(my_goals:str, fitness_level:str, days:int, hours:int, helth_cosnd:str, routine:str, language='En', model_name='Google Palm 2', creativity='Original')->str: | |
""" | |
Generates a Gym Workout Plan based on user's goal, fiteness_level, days and hours avaliable, his routine and health considiration. | |
Parameters: | |
my_goals (str): Trainee Goal from the Gym Workout. | |
fitness_level (str): Level of the trainee Fitness. | |
days (int): Avaliable Days. | |
hours (int): Avaliable Hours. | |
helth_cosnd (str): Health Considiration. | |
routine (str): Trainee Routine. | |
language (str): the language of the generated content (optional, default value is 'EN'). | |
creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original | |
model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2 | |
Returns: | |
workout_plan (str): Generated Workout Plan. | |
""" | |
temp = 0 | |
if creativity == 'Original': | |
temp = 0 | |
elif creativity == 'Balanced': | |
temp = 0.25 | |
elif creativity == 'Creative': | |
temp = 0.5 | |
elif creativity == 'Spirited': | |
temp = 0.75 | |
elif creativity == 'Visionary': | |
temp = 1 | |
if model_name == 'Google Palm 2': | |
llm = call_palm(google_api_key, temperature=temp) | |
elif model_name == 'GPT-3.5': | |
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp) | |
elif model_name == 'GPT-4': | |
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp) | |
if language == 'En': | |
workout_plan_prompt = f"""Generate a workout plan with diversity and creative exercises. | |
Please note the following details: | |
* My Goals: I'm looking to {my_goals} | |
* Fitness Level: {fitness_level}. | |
* Available Equipment: I have access to a gym with various equipment. | |
* Time Commitment: I'm dedicated to working out {days} days a week, and I have {hours} hours a day I can spend during each session. | |
* Health Considerations: I'm in the {helth_cosnd}. | |
* Preferred Routine: I like to follow {routine} routine.\nWorkout Plan:""" | |
workout_plan_promptTemp = PromptTemplate( | |
input_variables=["text_input"], | |
template="You are a Professional Fitness Trainer:\n{text_input}") | |
elif language == 'Ar': | |
workout_plan_prompt = f"""قم بإنشاء خطة تمارين رياضية متنوعة ومبتكرة. | |
يرجى مراعاة التفاصيل التالية: | |
* أهدافي: أنا أسعى لـ {my_goals}. | |
* مستوى اللياقة: {fitness_level}. | |
* المعدات المتاحة: لدي الوصول إلى صالة ألعاب رياضية بها معدات متنوعة. | |
* الالتزام الزمني: أنا ملتزم بممارسة التمارين {days} أيام في الأسبوع، ولدي {hours} ساعة يوميًا يمكنني قضائها خلال كل جلسة. | |
* اعتبارات الصحة: أنا في حالة {helth_cosnd}. | |
* الروتين المفضل: أحب اتباع الروتين {routine}.\nخطة التمارين:""" | |
workout_plan_promptTemp = PromptTemplate( | |
input_variables=["text_input"], | |
template="أنت مدرب لياقة مهني:\n{text_input}") | |
workout_plan_extraction_chain = LLMChain(llm=llm, prompt=workout_plan_promptTemp) | |
workout_plan = workout_plan_extraction_chain.run(workout_plan_prompt) | |
return workout_plan |