diff --git a/Database/userdatahandler.py b/Database/userdatahandler.py index 31f8c85..8274c99 100644 --- a/Database/userdatahandler.py +++ b/Database/userdatahandler.py @@ -67,7 +67,7 @@ def get_user_by_username(username: str): return user # Save image to MongoDB -def save_image(username, filename, title, description, time_created,audio_filename=None): +def save_image(username, filename, title, description, time_created,audio_filename=None,sentiment=None): image = { 'username': username, 'filename': filename, @@ -75,6 +75,7 @@ def save_image(username, filename, title, description, time_created,audio_filena 'description': description, 'created_at': time_created, 'audio_filename': audio_filename, + 'sentiment': sentiment } beehive_image_collection.insert_one(image) @@ -109,7 +110,7 @@ def get_currentuser_from_session(): # Get all images from MongoDB def get_images_by_user(username): images = beehive_image_collection.find({'username': username}) - return [{'id': str(image['_id']), 'filename': image['filename'], 'title': image['title'], 'description': image['description'], 'audio_filename': image.get('audio_filename', "")} for image in images] + return [{'id': str(image['_id']), 'filename': image['filename'], 'title': image['title'], 'description': image['description'], 'audio_filename': image.get('audio_filename', ""), 'sentiment':image.get('sentiment', "")} for image in images] # Update image in MongoDB def update_image(image_id, title, description): diff --git a/app.py b/app.py index afbef9b..02f20be 100644 --- a/app.py +++ b/app.py @@ -183,8 +183,9 @@ def upload_images(): files = request.files.getlist('files') # Supports multiple file uploads title = request.form.get('title', '') + sentiment = request.form.get('sentiment') description = request.form.get('description', '') - audio_data = request.form.get('audioData') # Retains audio support + audio_data = request.form.get('audioData') for file in files: if file and allowed_file(file.filename): @@ -203,12 +204,12 @@ def upload_images(): with open(audio_path, "wb") as f: f.write(audio_binary) - time_created = datetime.datetime.now() - save_image(user['username'], filename, title, description, time_created, audio_filename) - flash('Image uploaded successfully!', 'success') + time_created = datetime.datetime.now() + save_image(user['username'], filename, title, description, time_created, audio_filename, sentiment) + flash('Image uploaded successfully!', 'success') # Generate PDF thumbnail if applicable - if filename.lower().endswith('.pdf'): + if filename.lower().endswith('.pdf'): generate_pdf_thumbnail(filepath, filename) else: @@ -216,7 +217,7 @@ def upload_images(): return redirect(url_for('profile')) - +# generate thumbnail for the pdf def generate_pdf_thumbnail(pdf_path, filename): """Generate an image from the first page of a PDF using PyMuPDF.""" # Ensure the thumbnails directory exists @@ -225,6 +226,7 @@ def generate_pdf_thumbnail(pdf_path, filename): pdf_document = fitz.open(pdf_path) + #select only the first page for the thumbnail first_page = pdf_document.load_page(0) zoom = 2 # Increase for higher resolution diff --git a/static/css/index.css b/static/css/index.css index e7bafcc..3162d7b 100644 --- a/static/css/index.css +++ b/static/css/index.css @@ -41,4 +41,17 @@ button { button:hover { background: #212121; +} + +@media screen and (max-width: 600px) { + h2 { + font-size: 20px; + padding: 5px; + padding-left: 10px; + padding-right: 10px; + } + .material-icons { + font-size: 50px; + } + } \ No newline at end of file diff --git a/static/css/profile.css b/static/css/profile.css index 80e3645..19776de 100644 --- a/static/css/profile.css +++ b/static/css/profile.css @@ -668,3 +668,45 @@ h2{ .button:active { border: 1px solid #146c54; } + + /* Dropdown Label Styling */ +.dropdown-label { + display: block; + font-size: 14px; + font-weight: 500; + color: #333; + margin-bottom: 5px; + margin-top: 10px; +} + +/* Dropdown Styling */ +.dropdown { + width: 80%; + max-width: 300px; + padding: 10px; + font-size: 14px; + border: 1px solid #ccc; + border-radius: 6px; + background-color: #fff; + cursor: pointer; + transition: all 0.3s ease-in-out; + margin-bottom: 20px; +} + +/* Hover and Focus Effects */ +.dropdown:hover { + border-color: #007bff; +} + +.dropdown:focus { + border-color: #007bff; + box-shadow: 0 0 5px rgba(0, 123, 255, 0.5); + outline: none; +} + +.sentiment { + margin-bottom: 10px; + color: #6c52ff; + font-weight: bold; + font-size: 16px; +} \ No newline at end of file diff --git a/static/sentiments.json b/static/sentiments.json new file mode 100644 index 0000000..461bcfa --- /dev/null +++ b/static/sentiments.json @@ -0,0 +1,29 @@ +{ + "sentiments": [ + "Cannot Decide", + "Joyful", + "Melancholic", + "Hopeful", + "Lost in Thought", + "Peaceful", + "Empowered", + "Longing", + "Triumphant", + "Vulnerable", + "Liberated", + "Inspired", + "Nostalgic", + "Celebratory", + "Serene", + "Defiant", + "Lonely", + "Grateful", + "Reflective", + "Bittersweet", + "Determined", + "Frustrated", + "Content", + "Yearning", + "Uncertain" + ] +} diff --git a/templates/profile.html b/templates/profile.html index 3059edb..9c24981 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -191,6 +191,19 @@ }, 2000); } +//function for fetching sentiments from sentiment.json +fetch("{{ url_for('static', filename='sentiments.json') }}") + .then(response => response.json()) + .then(data => { + const sentimentDropdown = document.getElementById("sentiment"); + data.sentiments.forEach(sentiment => { + let option = document.createElement("option"); + option.value = sentiment; + option.textContent = sentiment; + sentimentDropdown.appendChild(option); + }); + }) + .catch(error => console.error("Error loading sentiments:", error)); @@ -222,6 +235,11 @@
{{ image.description }}
+{{ image.description }}
- +