|
import gradio as gr |
|
from queries import (clustering_esfuerzo_dieta_response, clustering_objetivo_response, clustering_entrenamiento_response, |
|
clustering_cumplimiento_dieta_response, clustering_compromiso_response, clustering_diferencia_peso_response, |
|
make_query, get_min_max_mean_mode_macros_differences) |
|
from find_matches import find_user_dates_matches, find_macros_that_match_dates_of_users |
|
|
|
def clustering_responses(esfuerzo_dieta, objetivo, cumplimiento_entrenamiento, |
|
cumplimiento_dieta, compromiso, variacion_peso): |
|
cluster_esfuerzo_dieta = clustering_esfuerzo_dieta_response(esfuerzo_dieta) |
|
cluster_objetivo = clustering_objetivo_response(objetivo) |
|
cluster_entrenamiento = clustering_entrenamiento_response(cumplimiento_entrenamiento) |
|
cluster_cumplimiento_dieta = clustering_cumplimiento_dieta_response(cumplimiento_dieta) |
|
cluster_compromiso = clustering_compromiso_response(compromiso) |
|
diff_peso_min, diff_peso_max = clustering_diferencia_peso_response(variacion_peso) |
|
|
|
return cluster_esfuerzo_dieta, cluster_objetivo, cluster_entrenamiento, cluster_cumplimiento_dieta, cluster_compromiso, diff_peso_min, diff_peso_max |
|
|
|
def calcular_macros(esfuerzo_dieta, objetivo, cumplimiento_entrenamiento, |
|
cumplimiento_dieta, compromiso, variacion_peso): |
|
|
|
valor_esfuerzo = next(list(opcion.values())[0]["value"] |
|
for opcion in opciones_esfuerzo |
|
if list(opcion.values())[0]["text"] == esfuerzo_dieta) |
|
|
|
valor_objetivo = next(list(opcion.values())[0]["value"] |
|
for opcion in opciones_objetivo |
|
if list(opcion.values())[0]["text"] == objetivo) |
|
|
|
valor_cumplimiento_entr = next(list(opcion.values())[0]["value"] |
|
for opcion in opciones_cumplimiento_entrenamiento |
|
if list(opcion.values())[0]["text"] == cumplimiento_entrenamiento) |
|
|
|
valor_cumplimiento_dieta = next(list(opcion.values())[0]["value"] |
|
for opcion in opciones_cumplimiento_dieta |
|
if list(opcion.values())[0]["text"] == cumplimiento_dieta) |
|
|
|
valor_compromiso = next(list(opcion.values())[0]["value"] |
|
for opcion in opciones_compromiso |
|
if list(opcion.values())[0]["text"] == compromiso) |
|
|
|
|
|
(cluster_esfuerzo_dieta, cluster_objetivo, cluster_entrenamiento, cluster_cumplimiento_dieta, |
|
cluster_compromiso, diff_peso_min, diff_peso_max) = clustering_responses(valor_esfuerzo, valor_objetivo, |
|
valor_cumplimiento_entr, |
|
valor_cumplimiento_dieta, valor_compromiso, |
|
variacion_peso) |
|
|
|
|
|
print(f"Consulta:") |
|
print(f"\tEsfuerzo para cumplir dieta: {cluster_esfuerzo_dieta}") |
|
print(f"\tObjetivo: {cluster_objetivo}") |
|
print(f"\tEntrenamiento: {cluster_entrenamiento}") |
|
print(f"\tCumplimiento dieta: {cluster_cumplimiento_dieta}") |
|
print(f"\tCompromiso: {cluster_compromiso}") |
|
print(f"\tVariación de peso: {variacion_peso}") |
|
print(f"\t{diff_peso_min} <= Diferencia peso <= {diff_peso_max}") |
|
|
|
|
|
query = make_query(cluster_esfuerzo_dieta, cluster_objetivo, cluster_entrenamiento, cluster_cumplimiento_dieta, cluster_compromiso, diff_peso_min, diff_peso_max) |
|
|
|
|
|
print(f"Query: {query}") |
|
|
|
|
|
matches_dict = find_user_dates_matches(query) |
|
|
|
|
|
print(f"Matches:\n{matches_dict}") |
|
|
|
|
|
macros_differences_list = find_macros_that_match_dates_of_users(matches_dict) |
|
|
|
|
|
print(f"Macros:\n{macros_differences_list}") |
|
|
|
|
|
(train_day_protein_std, train_day_carbs_std, train_day_fat_std, intratrain_protein_std, intratrain_carbs_std, |
|
rest_day_protein_std, rest_day_carbs_std, rest_day_fat_std) = get_min_max_mean_mode_macros_differences(macros_differences_list) |
|
|
|
|
|
print(f"Macros min, max and mean:\n{train_day_protein_std}, {train_day_carbs_std}, {train_day_fat_std}, {intratrain_protein_std}, {intratrain_carbs_std}, {rest_day_protein_std}, {rest_day_carbs_std}, {rest_day_fat_std}") |
|
|
|
|
|
train_day_protein_str = f"min: {train_day_protein_std[0]}, max: {train_day_protein_std[1]}, mean: {train_day_protein_std[2]:.2f}, mode: {train_day_protein_std[3]}" |
|
train_day_carbs_str = f"min: {train_day_carbs_std[0]}, max: {train_day_carbs_std[1]}, mean: {train_day_carbs_std[2]:.2f}, mode: {train_day_carbs_std[3]}" |
|
train_day_fat_str = f"min: {train_day_fat_std[0]}, max: {train_day_fat_std[1]}, mean: {train_day_fat_std[2]:.2f}, mode: {train_day_fat_std[3]}" |
|
intratrain_protein_str = f"min: {intratrain_protein_std[0]}, max: {intratrain_protein_std[1]}, mean: {intratrain_protein_std[2]:.2f}, mode: {intratrain_protein_std[3]}" |
|
intratrain_carbs_str = f"min: {intratrain_carbs_std[0]}, max: {intratrain_carbs_std[1]}, mean: {intratrain_carbs_std[2]:.2f}, mode: {intratrain_carbs_std[3]}" |
|
rest_day_protein_str = f"min: {rest_day_protein_std[0]}, max: {rest_day_protein_std[1]}, mean: {rest_day_protein_std[2]:.2f}, mode: {rest_day_protein_std[3]}" |
|
rest_day_carbs_str = f"min: {rest_day_carbs_std[0]}, max: {rest_day_carbs_std[1]}, mean: {rest_day_carbs_std[2]:.2f}, mode: {rest_day_carbs_std[3]}" |
|
rest_day_fat_str = f"min: {rest_day_fat_std[0]}, max: {rest_day_fat_std[1]}, mean: {rest_day_fat_std[2]:.2f}, mode: {rest_day_fat_std[3]}" |
|
|
|
return train_day_protein_str, train_day_carbs_str, train_day_fat_str, intratrain_protein_str, intratrain_carbs_str, rest_day_protein_str, rest_day_carbs_str, rest_day_fat_str |
|
|
|
|
|
opciones_esfuerzo = [ |
|
{ |
|
"No entiendo la calculadora, quiero menús tipo": { |
|
"text": "No entiendo la calculadora, quiero menús tipo", |
|
"value": " | no data" |
|
} |
|
}, |
|
{ |
|
"No costó nada": { |
|
"text": "No costó nada", |
|
"value": " | no costo" |
|
} |
|
}, |
|
{ |
|
"Costó demasiado, súbeme macros": { |
|
"text": "Costó demasiado, súbeme macros", |
|
"value": " | costo subir macros" |
|
} |
|
}, |
|
{ |
|
"Costó demasiado, bájame macros": { |
|
"text": "Costó demasiado, bájame macros", |
|
"value": " | costo bajar macros" |
|
} |
|
}, |
|
{ |
|
"Costó, pero me adapto a nuevos ajustes": { |
|
"text": "Costó, pero me adapto a nuevos ajustes", |
|
"value": " | costo y me adapto a nuevos ajustes" |
|
} |
|
}, |
|
{ |
|
"Iba a coger menús tipo, pero al final por precio no": { |
|
"text": "Iba a coger menús tipo, pero al final por precio no", |
|
"value": " | no data" |
|
} |
|
} |
|
] |
|
|
|
opciones_objetivo = [ |
|
{ |
|
"definición (nada cambia)": { |
|
"text": "definición (nada cambia)", |
|
"value": " | definicion" |
|
} |
|
}, |
|
{ |
|
"empezamos a definir (cambia)": { |
|
"text": "empezamos a definir (cambia)", |
|
"value": " | definicion" |
|
} |
|
}, |
|
{ |
|
"perder peso (nada cambia)": { |
|
"text": "perder peso (nada cambia)", |
|
"value": " | definicion" |
|
} |
|
}, |
|
{ |
|
"volumen (nada cambia)": { |
|
"text": "volumen (nada cambia)", |
|
"value": " | volumen" |
|
} |
|
}, |
|
{ |
|
"empezamos a coger volumen (cambia)": { |
|
"text": "empezamos a coger volumen (cambia)", |
|
"value": " | volumen" |
|
} |
|
}, |
|
{ |
|
"empezamos a coger volumen, sobre todo tren inferior (cambia)": { |
|
"text": "empezamos a coger volumen, sobre todo tren inferior (cambia)", |
|
"value": " | volumen" |
|
} |
|
}, |
|
{ |
|
"empezamos a coger volumen, en todo el cuerpo (cambia)": { |
|
"text": "empezamos a coger volumen, en todo el cuerpo (cambia)", |
|
"value": " | volumen" |
|
} |
|
} |
|
] |
|
|
|
opciones_cumplimiento_entrenamiento = [ |
|
{ |
|
"Lo hice perfecto": { |
|
"text": "Lo hice perfecto", |
|
"value": " | bien" |
|
} |
|
}, |
|
{ |
|
"He fallado algunos días, pero sí": { |
|
"text": "He fallado algunos días, pero sí", |
|
"value": " | bien" |
|
} |
|
}, |
|
{ |
|
"Lesión importante": { |
|
"text": "Lesión importante", |
|
"value": " | mal" |
|
} |
|
}, |
|
{ |
|
"Lo hice prácticamente perfecto": { |
|
"text": "Lo hice prácticamente perfecto", |
|
"value": " | bien" |
|
} |
|
}, |
|
{ |
|
"Pequeña lesión": { |
|
"text": "Pequeña lesión", |
|
"value": " | mal" |
|
} |
|
}, |
|
{ |
|
"No hice nada, mantenemos la rutina un mes más": { |
|
"text": "No hice nada, mantenemos la rutina un mes más", |
|
"value": " | mal" |
|
} |
|
}, |
|
{ |
|
"Alárgame la rutina una semana más": { |
|
"text": "Alárgame la rutina una semana más", |
|
"value": " | mal" |
|
} |
|
} |
|
] |
|
|
|
opciones_cumplimiento_dieta = [ |
|
{ |
|
"al 70%": { |
|
"text": "al 70%", |
|
"value": " | bien" |
|
} |
|
}, |
|
{ |
|
"regular, me cuesta llegar": { |
|
"text": "regular, me cuesta llegar", |
|
"value": " | regular" |
|
} |
|
}, |
|
{ |
|
"Nada, mantén mis macros": { |
|
"text": "Nada, mantén mis macros", |
|
"value": " | mal" |
|
} |
|
}, |
|
{ |
|
"casi perfecta": { |
|
"text": "casi perfecta", |
|
"value": " | bien" |
|
} |
|
}, |
|
{ |
|
"regular, me salto la dieta": { |
|
"text": "regular, me salto la dieta", |
|
"value": " | regular" |
|
} |
|
}, |
|
{ |
|
"Perfecta": { |
|
"text": "Perfecta", |
|
"value": " | bien" |
|
} |
|
} |
|
] |
|
|
|
opciones_compromiso = [ |
|
{ |
|
"Bueno, pero mejorable": { |
|
"text": "Bueno, pero mejorable", |
|
"value": " | bueno" |
|
} |
|
}, |
|
{ |
|
"Mal, pero a partir de ahora voy a por todas": { |
|
"text": "Mal, pero a partir de ahora voy a por todas", |
|
"value": " | mal" |
|
} |
|
}, |
|
{ |
|
"Mal, demasiado exigente": { |
|
"text": "Mal, demasiado exigente", |
|
"value": " | mal" |
|
} |
|
}, |
|
{ |
|
"Máximo": { |
|
"text": "Máximo", |
|
"value": " | bueno" |
|
} |
|
} |
|
] |
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
|
naranja = "#FF9300" |
|
|
|
|
|
textos_esfuerzo = [list(opcion.values())[0]["text"] for opcion in opciones_esfuerzo] |
|
textos_objetivo = [list(opcion.values())[0]["text"] for opcion in opciones_objetivo] |
|
textos_cumplimiento_entr = [list(opcion.values())[0]["text"] for opcion in opciones_cumplimiento_entrenamiento] |
|
textos_cumplimiento_dieta = [list(opcion.values())[0]["text"] for opcion in opciones_cumplimiento_dieta] |
|
textos_compromiso = [list(opcion.values())[0]["text"] for opcion in opciones_compromiso] |
|
|
|
|
|
with gr.Row(): |
|
esfuerzo = gr.Dropdown( |
|
choices=textos_esfuerzo, |
|
label="Esfuerzo dieta", |
|
value="No costó nada" |
|
) |
|
cumplimiento_dieta = gr.Dropdown( |
|
choices=textos_cumplimiento_dieta, |
|
label="Cumplimiento de la dieta", |
|
value="Perfecta" |
|
) |
|
objetivo = gr.Dropdown( |
|
choices=textos_objetivo, |
|
label="Objetivo", |
|
value="volumen (nada cambia)" |
|
) |
|
with gr.Row(): |
|
cumplimiento_entr = gr.Dropdown( |
|
choices=textos_cumplimiento_entr, |
|
label="Cumplimiento del entrenamiento", |
|
value="Lo hice perfecto" |
|
) |
|
compromiso = gr.Dropdown( |
|
choices=textos_compromiso, |
|
label="Compromiso", |
|
value="Máximo" |
|
) |
|
variacion_peso = gr.Number( |
|
label="Variación de peso", |
|
precision=2, |
|
value=0.7 |
|
) |
|
|
|
|
|
calcular_btn = gr.Button( |
|
"Calcular", |
|
variant="primary", |
|
size="lg" |
|
) |
|
|
|
|
|
css = f""" |
|
<style> |
|
#boton-naranja {{ |
|
background-color: {naranja} !important; |
|
border: 1px solid {naranja} !important; |
|
}} |
|
#boton-naranja:hover {{ |
|
background-color: {naranja}DD !important; |
|
border: 1px solid {naranja}DD !important; |
|
}} |
|
</style> |
|
""" |
|
|
|
css_outputs = """ |
|
<style> |
|
.output-row { |
|
align-items: flex-end !important; |
|
display: flex !important; |
|
gap: 1rem !important; |
|
} |
|
.output-row > * { |
|
flex: 1; |
|
min-width: 0; |
|
} |
|
</style> |
|
""" |
|
|
|
gr.Markdown(css + css_outputs) |
|
|
|
|
|
with gr.Row(elem_classes="output-row"): |
|
proteina_entreno = gr.Textbox(label="Proteína día de entreno (g)") |
|
carbs_entreno = gr.Textbox(label="Carbohidratos día de entreno (g)") |
|
grasas_entreno = gr.Textbox(label="Grasas día de entreno (g)") |
|
proteina_intra = gr.Textbox(label="Proteína intraentreno (g)") |
|
carbs_intra = gr.Textbox(label="Carbohidratos intraentreno (g)") |
|
proteina_descanso = gr.Textbox(label="Proteína día de descanso (g)") |
|
carbs_descanso = gr.Textbox(label="Carbohidratos día de descanso (g)") |
|
grasas_descanso = gr.Textbox(label="Grasas día de descanso (g)") |
|
|
|
|
|
calcular_btn.click( |
|
fn=calcular_macros, |
|
inputs=[esfuerzo, objetivo, cumplimiento_entr, cumplimiento_dieta, |
|
compromiso, variacion_peso], |
|
outputs=[proteina_entreno, carbs_entreno, grasas_entreno, |
|
proteina_intra, carbs_intra, |
|
proteina_descanso, carbs_descanso, grasas_descanso] |
|
) |
|
|
|
demo.launch() |
|
|
|
|