49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
from flask import Flask, render_template, request
|
|
|
|
import os
|
|
# Îi spunem clar că templates este în același folder cu main.py
|
|
template_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'templates'))
|
|
app = Flask(__name__, template_folder=template_dir)
|
|
|
|
# Funcția care calculează caloriile (Formula Mifflin-St Jeor)
|
|
def calculeaza_target(data):
|
|
w = float(data.get('weight'))
|
|
h = float(data.get('height'))
|
|
a = int(data.get('age'))
|
|
gen = data.get('gender')
|
|
act = float(data.get('activity'))
|
|
scop = data.get('goal')
|
|
|
|
# Calcul BMR (Basal Metabolic Rate)
|
|
if gen == 'masculin':
|
|
bmr = (10 * w) + (6.25 * h) - (5 * a) + 5
|
|
else:
|
|
bmr = (10 * w) + (6.25 * h) - (5 * a) - 161
|
|
|
|
# TDEE (Total Daily Energy Expenditure)
|
|
tdee = bmr * act
|
|
|
|
# Ajustare în funcție de scop (slăbire/îngrășare)
|
|
if scop == 'slabire':
|
|
return round(tdee - 500)
|
|
elif scop == 'ingrasare':
|
|
return round(tdee + 500)
|
|
else:
|
|
return round(tdee)
|
|
|
|
@app.route('/')
|
|
def index():
|
|
return render_template('index.html')
|
|
|
|
@app.route('/calculate', methods=['POST'])
|
|
def calculate():
|
|
try:
|
|
data = request.form
|
|
kcal_final = calculeaza_target(data)
|
|
# Trimitem rezultatul înapoi în pagina index.html
|
|
return render_template('index.html', rezultat=kcal_final, date_introduse=data)
|
|
except Exception as e:
|
|
return f"A apărut o eroare: {e}", 400
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host='0.0.0.0', port=5000) |