Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@ docs/_build/
htmlcov/
.coverage
.coverage.*
*,cover
*,cover

#pycache
__pycache__/

#credentials
credentials.py

#chat-history
chat_history
102 changes: 96 additions & 6 deletions application.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime, timedelta

import credentials as c
import bcrypt
import smtplib
import re
Expand All @@ -13,6 +13,46 @@
from tabulate import tabulate
from forms import HistoryForm, RegistrationForm, LoginForm, CalorieForm, UserProfileForm, EnrollForm, WorkoutForm
from service import history as history_service
import openai
import os
from utilities import get_response
import time

# Set the OpenAI API key
openai.api_key = c.openAI_api_key

# Define the name of the bot
name = 'BOT'

# Define the role of the bot
role = 'fitness-advisor, dietician and nutritionist'

# Define the impersonated role with instructions
impersonated_role = f"""
From now on, you are going to act as {name}. Your role is {role}.
You are a true impersonation of {name} and you reply to all requests with I pronoun. You never give unknown information.
Forward them to the website for more information.
YOU ARE NOT AN AI MODEL!
"""

# Initialize variables for chat history
explicit_input = ""
chatgpt_output = 'Chat log: /n'
cwd = os.getcwd() + '/chat_history/'
i = 1

# Find an available chat history file
while os.path.exists(os.path.join(cwd, f'chat_history{i}.txt')):
i += 1

history_file = os.path.join(cwd, f'chat_history{i}.txt')

# Create a new chat history file
with open(history_file, 'w') as f:
f.write('\n')

# Initialize chat history
chat_history = ''

app = Flask(__name__)
app.secret_key = 'secret'
Expand Down Expand Up @@ -399,6 +439,55 @@ def friends():
myFriendsList=myFriendsList)


@app.route('/bmi_calc', methods=['GET', 'POST'])
def bmi_calci():
bmi = ''
bmi_category = ''

if request.method == 'POST' and 'weight' in request.form:
weight = float(request.form.get('weight'))
height = float(request.form.get('height'))
bmi = calc_bmi(weight, height)
bmi_category = get_bmi_category(bmi)

return render_template("bmi_cal.html", bmi=bmi, bmi_category=bmi_category)


@app.route('/chatbot', methods=['GET', 'POST'])
def chatbot():
return render_template("chatbot.html")


@app.route("/get", methods=['GET', 'POST'])
# Function for the bot response
def get_bot_response():
userText = request.args.get('msg')
return str(
get_response(chat_history, name, chatgpt_output, userText,
history_file, impersonated_role, explicit_input))


@app.route('/refresh', methods=['GET', 'POST'])
def refresh():
time.sleep(600) # Wait for 10 minutes
return redirect('/refresh')


def calc_bmi(weight, height):
return round((weight / ((height / 100)**2)), 2)


def get_bmi_category(bmi):
if bmi < 18.5:
return 'Underweight'
elif bmi < 24.9:
return 'Normal Weight'
elif bmi < 29.9:
return 'Overweight'
else:
return 'Obese'


@app.route("/send_email", methods=['GET', 'POST'])
def send_email():
# ############################
Expand All @@ -410,18 +499,19 @@ def send_email():
email = session.get('email')
data = list(
mongo.db.calories.find({'email': email},
{'date', 'email', 'calories', 'burnout'}))
table = [['Date', 'Email ID', 'Calories', 'Burnout']]
{'date', 'email', 'calories'}))
print(data)
table = [['Date', 'Email ID', 'Calories']]
for a in data:
tmp = [a['date'], a['email'], a['calories'], a['burnout']]
tmp = [a['date'], a['email'], a['calories']]
table.append(tmp)

friend_email = str(request.form.get('share')).strip()
friend_email = str(friend_email).split(',')
server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
#Storing sender's email address and password
sender_email = "calorie.app.server@gmail.com"
sender_password = "Temp@1234"
sender_email = "calorieapp508@gmail.com"
sender_password = c.email_password

#Logging in with sender details
server.login(sender_email, sender_password)
Expand Down
Binary file added static/img/pexels-rfstudio-3820441.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 26 additions & 2 deletions static/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,33 @@
padding: 10px 20px;
border: 1px solid #dddddd;
border-radius: 3px;
margin-bottom: 20px;
width: 50%;
margin: auto;
position: relative;
top: 250px;
border-radius: 1%;
bottom: 250px;
box-shadow: 10px 10px 5px lightblue;
}


.sign-in-div {
position: relative;
top: 653px;
display: flex;
width: 50%;
margin: auto;
}
.login-img-div {
z-index: -999;
display: block;
position: absolute;
top: 25px;
}
.login-img {
width: 653px;
padding: unset;
}


.account-img {
height: 125px;
Expand Down
80 changes: 80 additions & 0 deletions templates/bmi_cal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{% extends "layout.html" %}

{% block content %}
<div class="container">
<h1>Your Health, Your BMI</h1>
<div class="main-content">
<p>
Welcome to our BMI Calculator! Body Mass Index (BMI) is a helpful measure
to understand how your weight relates to your height. It's a simple tool
that can give you insights into your health.

To discover your BMI, input your weight (in kilograms) and height (in
centimeters) below:
</p>

<div class="content-section">
<form class="pure-form" method="POST" action="/bmi_calc" id="bmi-form">
<label for="weightInput">Weight in kilograms:</label><br />
<input type="text" name="weight" id="weightInput" placeholder="Enter your weight" required /><br />

<label for="heightInput">Height in centimeters:</label><br />
<input type="text" name="height" id="heightInput" placeholder="Enter your height" required /><br />
<br>
<button type="button" class="pure-button pure-button-primary" onclick="calculateBMI()">
Calculate BMI
</button>
</form>
</div>

<div id="resultSection" style="display: none;">
<p style="text-align: center" class="display-4">
Your BMI is <span id="bmiResult"></span>.
</p>
<p style="text-align: center" class="display-6">You fall into the category of <span id="bmiCategory"></span></p>
</div>
</div>
</div>

<script>
function calculateBMI() {
var weight = document.getElementById("weightInput").value;
var height = document.getElementById("heightInput").value;

// Validate inputs
if (!isNumeric(weight) || !isNumeric(height)) {
alert("Please enter valid numeric values for weight and height.");
return;
}

// Perform BMI calculation here and set the results
var bmi = calculateBMIValue(weight, height);
var bmiCategory = determineBMICategory(bmi);

// Display the result section
document.getElementById("bmiResult").innerText = bmi;
document.getElementById("bmiCategory").innerText = bmiCategory;
document.getElementById("resultSection").style.display = "block";
}

function isNumeric(value) {
return !isNaN(parseFloat(value)) && isFinite(value);
}

function calculateBMIValue(weight, height) {
return (weight / (height / 100) ** 2).toFixed(2);
}

function determineBMICategory(bmi) {
if (bmi < 18.5) {
return "Underweight";
} else if (bmi < 24.9) {
return "Normal Weight";
} else if (bmi < 29.9) {
return "Overweight";
} else {
return "Obese";
}
}
</script>
{% endblock content %}
Loading