Designing a responsive and aesthetically pleasing frontend for your Flask-based yoga recommendation application involves structuring your HTML templates, integrating CSS for styling (using Bootstrap for ease and responsiveness), and incorporating JavaScript libraries for interactive components like the calendar and graph.
Below is a comprehensive guide, including the necessary code for index1.html and recommendations.html, along with explanations on how to set up each feature as per your requirements.
1. Project Structure
Ensure your project directory is organized as follows:
your_project/
│
├── static/
│ ├── css/
│ │ └── styles.css
│ ├── js/
│ │ └── scripts.js
│ └── images/
│
├── templates/
│ ├── index1.html
│ └── recommendations.html
│
├── poses.json
└── app.py
2. Including Necessary Libraries
To achieve a clean, responsive, and interactive design, we'll use the following libraries:
Include these libraries in your HTML templates via CDN links.
3. index1.html Template
This template includes the navbar, search bar, upload image button, calendar with date selection, and the graph section.
<!-- templates/index1.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Yoga Recommendation App</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- FullCalendar CSS -->
<link href='https://cdn.jsdelivr.net/npm/fullcalendar@5.11.0/main.min.css' rel='stylesheet' />
<!-- Font Awesome -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="{{ url_for('static', filename='css/styles.css') }}" rel="stylesheet">
</head>
<body>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-light bg-light shadow-sm">
<div class="container-fluid">
<a class="navbar-brand" href="{{ url_for('index') }}">YogaApp</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown"
aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="{{ url_for('index') }}">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
<!-- Dropdown for Yoga Instructor -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="instructorDropdown" role="button"
data-bs-toggle="dropdown" aria-expanded="false">
Yoga Instructor
</a>
<ul class="dropdown-menu" aria-labelledby="instructorDropdown">
<li><a class="dropdown-item" href="#">Instructor 1</a></li>
<li><a class="dropdown-item" href="#">Instructor 2</a></li>
<li><a class="dropdown-item" href="#">Instructor 3</a></li>
</ul>
</li>
</ul>
<!-- Placeholder for additional navbar items -->
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="#"><i class="fas fa-user"></i> Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="fas fa-sign-out-alt"></i> Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Main Container -->
<div class="container-fluid mt-4">
<div class="row">
<!-- Left Section -->
<div class="col-lg-6 mb-4">
<!-- Search Bar -->
<div class="card p-3 mb-4 shadow-sm">
<form method="POST" action="/">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search yoga poses by mood..."
name="mood" aria-label="Search" required>
<button class="btn btn-primary" type="submit"><i class="fas fa-search"></i> Search</button>
</div>
</form>
</div>
<!-- Calendar and Date Selection -->
<div class="card p-3 mb-4 shadow-sm">
<h5>Select a Date</h5>
<div id='calendar'></div>
<div class="mt-3">
<h6>Selected Dates:</h6>
<ul id="selected-dates" class="list-group mb-3">
<!-- Dates will be appended here -->
{% if selected_dates %}
{% for date in selected_dates %}
<li class="list-group-item">{{ date }}</li>
{% endfor %}
{% endif %}
</ul>
<button id="upload-date" class="btn btn-success"><i class="fas fa-upload"></i> Upload Date</button>
</div>
</div>
<!-- Graph Section -->
<div class="card p-3 shadow-sm">
<h5>Your Progress</h5>
<canvas id="progressChart"></canvas>
</div>
</div>
<!-- Right Section -->
<div class="col-lg-6 mb-4">
<!-- Upload Image Button -->
<div class="d-flex justify-content-center align-items-center h-100">
<form method="POST" action="/upload_image" enctype="multipart/form-data">
<div class="mb-3">
<input class="form-control" type="file" id="formFile" name="image" accept="image/*" required>
</div>
<button type="submit" class="btn btn-secondary btn-lg"><i class="fas fa-upload"></i> Upload Image</button>
</form>
</div>
</div>
</div>
</div>
<!-- Bootstrap JS, Popper.js, and jQuery -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<!-- FullCalendar JS -->
<script src='https://cdn.jsdelivr.net/npm/fullcalendar@5.11.0/main.min.js'></script>
<!-- Chart.js -->
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.9.1/dist/chart.min.js"></script>
<!-- Custom JS -->
<script src="{{ url_for('static', filename='js/scripts.js') }}"></script>
<!-- Inline JS for Calendar and Chart (Alternatively, place in scripts.js) -->
<script>
document.addEventListener('DOMContentLoaded', function () {
// Initialize FullCalendar
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
initialView: 'dayGridMonth',
selectable: true,
select: function(info) {
// Highlight selected date
// You can implement logic to handle date selection
},
dateClick: function(info) {
// Handle date click if needed
}
});
calendar.render();
// Handle Upload Date Button
$('#upload-date').click(function(){
// Get selected date(s)
var selectedDates = calendar.getSelectedDates(); // You may need to implement this
// For demonstration, we'll just add a fixed date
var date = prompt("Enter date to upload (YYYY-MM-DD):");
if(date){
$.ajax({
url: '/upload_date',
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({date: date}),
success: function(response){
// Append to the list
$('#selected-dates').append('<li class="list-group-item">' + date + '</li>');
},
error: function(){
alert('Error uploading date.');
}
});
}
});
// Initialize Chart.js
var ctx = document.getElementById('progressChart').getContext('2d');
var progressChart = new Chart(ctx, {
type: 'line', // or 'bar'
data: {
labels: ['January', 'February', 'March', 'April', 'May', 'June'],
datasets: [{
label: 'Progress',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: 'rgba(54, 162, 235, 0.2)',
borderColor: 'rgba(54, 162, 235, 1)',
borderWidth: 2,
fill: true
}]
},
options: {
responsive: true,
maintainAspectRatio: false
}
});
// You can add AJAX calls to update the chart based on user data
});
</script>
</body>
</html>
4. recommendations.html Template
This template displays the recommended yoga poses based on the selected mood.
<!-- templates/recommendations.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Recommendations - {{ mood }}</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="{{ url_for('static', filename='css/styles.css') }}" rel="stylesheet">
</head>
<body>
<!-- Navbar (Same as index1.html) -->
<nav class="navbar navbar-expand-lg navbar-light bg-light shadow-sm">
<div class="container-fluid">
<a class="navbar-brand" href="{{ url_for('index') }}">YogaApp</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown"
aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="{{ url_for('index') }}">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
<!-- Dropdown for Yoga Instructor -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="instructorDropdown" role="button"
data-bs-toggle="dropdown" aria-expanded="false">
Yoga Instructor
</a>
<ul class="dropdown-menu" aria-labelledby="instructorDropdown">
<li><a class="dropdown-item" href="#">Instructor 1</a></li>
<li><a class="dropdown-item" href="#">Instructor 2</a></li>
<li><a class="dropdown-item" href="#">Instructor 3</a></li>
</ul>
</li>
</ul>
<!-- Placeholder for additional navbar items -->
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="#"><i class="fas fa-user"></i> Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="fas fa-sign-out-alt"></i> Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Recommendations Container -->
<div class="container mt-4">
<h2 class="mb-4">Recommended Yoga Poses for {{ mood }}</h2>
<div class="row">
{% if poses %}
{% for pose in poses %}
<div class="col-md-4 mb-4">
<div class="card h-100 shadow-sm">
<img src="{{ pose.image_url }}" class="card-img-top" alt="{{ pose.name }}">
<div class="card-body">
<h5 class="card-title">{{ pose.name }}</h5>
<p class="card-text">{{ pose.description }}</p>
</div>
</div>
</div>
{% endfor %}
{% else %}
<p>No poses found for the selected mood.</p>
{% endif %}
</div>
</div>
<!-- Bootstrap JS and dependencies -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
5. Custom CSS (styles.css)
Add custom styles to enhance the aesthetic as per your requirements.
/* static/css/styles.css */
/* General Styling */
body {
background-color: #f8f9fa; /* Light grey background for calmness */
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
/* Navbar Styling */
.navbar-brand {
font-weight: bold;
color: #2c3e50 !important;
}
/* Card Styling */
.card {
border: none;
border-radius: 15px;
}
.card img {
border-top-left-radius: 15px;
border-top-right-radius: 15px;
height: 200px;
object-fit: cover;
}
/* Buttons */
.btn-primary {
background-color: #3498db;
border-color: #3498db;
border-radius: 25px;
}
.btn-secondary {
background-color: #95a5a6;
border-color: #95a5a6;
border-radius: 25px;
}
.btn-success {
border-radius: 25px;
}
/* Calendar */
#calendar {
max-width: 100%;
margin: 0 auto;
}
/* Graph Section */
#progressChart {
width: 100%;
height: 300px;
}
6. Custom JavaScript (scripts.js)
Handle interactive features like uploading dates and updating the graph. Below is a basic example; you may need to expand it based on your backend routes and data handling.
// static/js/scripts.js
$(document).ready(function() {
// Handle Calendar Initialization if not using inline script
// Already handled in index1.html
// Handle Upload Date via AJAX
$('#upload-date').click(function(){
// Get selected date(s) from FullCalendar
var selectedDate = prompt("Enter date to upload (YYYY-MM-DD):");
if(selectedDate){
$.ajax({
url: '/upload_date',
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({date: selectedDate}),
success: function(response){
// Append to the list
$('#selected-dates').append('<li class="list-group-item">' + response.date + '</li>');
},
error: function(){
alert('Error uploading date.');
}
});
}
});
// Initialize Chart.js (if not using inline script)
// Already handled in index1.html
});
7. Backend Adjustments (app.py)
You need to handle additional routes for uploading images and dates. Update your Flask application accordingly.
from flask import Flask, render_template, request, redirect, url_for, jsonify
import json
import os
from werkzeug.utils import secure_filename
app = Flask(__name__)
# Configure upload folder and allowed extensions
UPLOAD_FOLDER = 'static/images/uploads'
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# Ensure upload folder exists
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
# Load yoga poses data
with open('poses.json', 'r') as f:
poses = json.load(f)
# Load or initialize selected dates
DATES_FILE = 'selected_dates.json'
if os.path.exists(DATES_FILE):
with open(DATES_FILE, 'r') as f:
selected_dates = json.load(f)
else:
selected_dates = []
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
mood = request.form.get('mood')
return redirect(url_for('recommendations', mood=mood))
return render_template('index1.html', selected_dates=selected_dates)
@app.route('/recommendations/<mood>')
def recommendations(mood):
recommended_poses = poses.get(mood.lower(), [])
return render_template('recommendations.html', mood=mood.capitalize(), poses=recommended_poses)
@app.route('/upload_image', methods=['POST'])
def upload_image():
if 'image' not in request.files:
return redirect(request.url)
file = request.files['image']
if file.filename == '':
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
file.save(filepath)
# Optionally, save the image info to a database or JSON
return redirect(url_for('index'))
return redirect(request.url)
@app.route('/upload_date', methods=['POST'])
def upload_date():
data = request.get_json()
date = data.get('date')
if date and date not in selected_dates:
selected_dates.append(date)
with open(DATES_FILE, 'w') as f:
json.dump(selected_dates, f)
return jsonify({'status': 'success', 'date': date}), 200
return jsonify({'status': 'error'}), 400
if __name__ == '__main__':
app.run(debug=True)
8. poses.json Example
Ensure your poses.json file is structured appropriately. Here's an example structure:
{
"happy": [
{
"name": "Sun Salutation",
"description": "A series of poses to greet the new day.",
"image_url": "https://example.com/images/sun_salutation.jpg"
},
{
"name": "Warrior II",
"description": "Strengthens legs and opens hips.",
"image_url": "https://example.com/images/warrior_ii.jpg"
}
],
"calm": [
{
"name": "Child's Pose",
"description": "A restful pose that calms the mind.",
"image_url": "https://example.com/images/child_pose.jpg"
},
{
"name": "Savasana",
"description": "Corpse pose for deep relaxation.",
"image_url": "https://example.com/images/savasana.jpg"
}
]
// Add more moods and poses as needed
}
9. Additional Notes
-
Image Uploads: Uploaded images are saved to the static/images/uploads directory. You can display these images in the recommendations or profile sections as needed.
-
Calendar Integration: The above implementation uses a prompt to enter dates. For a more seamless experience, you can integrate FullCalendar's selection features to capture dates without prompts.
-
Graph Data: The progressChart in index1.html uses static data. To dynamically update the graph based on user data, fetch the data from the backend via AJAX and update the chart accordingly.
-
Responsive Design: Using Bootstrap ensures the layout adjusts gracefully across different screen sizes. Test the interface on various devices to ensure optimal usability.
-
Security: Implement proper validation and security measures, especially for file uploads, to prevent malicious files from being uploaded.
10. Final Touches
-
Testing: Run your Flask application and navigate through the interface to ensure all components function as expected.
-
Styling Enhancements: Customize the color palette and typography further to align with your brand and the calming essence of yoga.
-
Functionality Expansion: Depending on user feedback, consider adding more features like user authentication, personalized pose recommendations, or progress tracking over time.
By following the above guidelines and utilizing the provided code snippets, you can create a comprehensive and user-friendly frontend interface for your Flask-based yoga recommendation application. Remember to iterate based on user feedback and continuously enhance both functionality and design for the best user experience.