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
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions Client/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

19 changes: 14 additions & 5 deletions Client/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from flask import Flask, render_template, request, jsonify, redirect, url_for, session, flash
from tcp_client import TCPClient

from flask import Flask, render_template, request, jsonify, redirect, url_for, session, flash

import time
import base64
import os
Expand All @@ -13,12 +15,12 @@

tcp_client = TCPClient(server_host='localhost', server_port=5001)

db = Database()
#initialize the managers

comment_manager = CommentManager()
image_manager = ImageManager()

upload_images = []
db = Database()


@app.route('/')
Expand Down Expand Up @@ -105,6 +107,7 @@ def index():

return render_template('index.html', images=images, user=user, categories=categories)


#prev home route
# #home page
# @app.route('/home')
Expand All @@ -115,7 +118,6 @@ def index():
# return render_template('index.html', images=images)



@app.route('/saved')
def saved():

Expand Down Expand Up @@ -155,6 +157,7 @@ def save_image():
else:
return jsonify({"success": False, "message": "Image already saved or couldn't be saved"})


@app.route('/unsave_image', methods=['POST'])
def unsave_image():

Expand Down Expand Up @@ -194,6 +197,7 @@ def profile():
saved_count=saved_count,
uploaded_count=uploaded_count,
comment_count=comment_count)

# =======
# # Use TCP client to fetch saved images
# # success, response = tcp_client.send_request("GET_SAVED_IMAGES", {"username": username})
Expand Down Expand Up @@ -221,6 +225,7 @@ def profile():
# return render_template('profile.html', username=username)
# >>>>>>> db-to-master-merge-check


@app.route('/upload', methods=['POST'])
def upload_image():

Expand Down Expand Up @@ -275,17 +280,19 @@ def upload_image():

# success, response = tcp_client.send_request("UPLOAD_IMAGE", image_data)
# >>>>>>> db-to-master-merge-check

if success:
return redirect(url_for('index'))
else:
return jsonify({'status': 'error', 'message': response})
return redirect(url_for('index')) #we are just going to ignore this error #jsonify({'status': 'error', 'message': response})

@app.route('/api/comments/<int:image_id>')
def get_comments_for_img(image_id):
comments = db.get_comments(image_id)

return jsonify({"success": True, "comments": comments})

#save a newly written comment
@app.route('/api/comments', methods=['POST'])
def save_comment():

Expand All @@ -295,6 +302,7 @@ def save_comment():
data = request.json
if not data or 'imageId' not in data or 'text' not in data:
return jsonify({"success": False, "message": "Fill out all required fields"})

# =======
# #comment handleing routes
# #to get the comments for a specific post
Expand All @@ -321,6 +329,7 @@ def save_comment():
image_id = data['imageId']
comment_text = data['text']


success = db.add_comment(image_id, comment_text, session['user_id'])

if success:
Expand Down
24 changes: 13 additions & 11 deletions Client/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,19 @@ def _insert_default_data(self):
"""Insert default images into the database"""
# Default images
default_images = [
(1, "./static/images/1.jpg", "Best Survival Tools for Preppers", "Tools", 1),
(2, "./static/images/2.jpg", "Prepare for Food Shortages", "Meal Prep", 1),
(3, "./static/images/3.jpg", "Amazing Survival Recipes", "Meal Prep", 1),
(4, "./static/images/4.jpg", "YOU NEED TO KNOW THESE LIFE HACKS!", "Hacks", 1),
(5, "./static/images/5.jpg", "Your emergency stockpile isnt complete without these 100 things", "Tools", 1),
(6, "./static/images/6.jpg", "World War 3 is Coming, are you Prepared??", "Tips", 1),
(7, "./static/images/7.jpg", "Want to Survive? Better read this..", "Tips", 1),
(8, "./static/images/8.jpg", "Clothes that Guarantee Survival", "Clothes", 1),
(9, "./static/images/9.jpg", "If you don'T have these in your pantry, uh oh", "Meal Prep", 1),
(10, "./static/images/10.jpg", "Rebuild after the apocalypse is over with these plants", "Gardening", 1),
(11, "./static/images/11.jpg", "Flowers will be worth millions soon, enjoy them now", "Gardening", 1)

(1, "./static/images/1.jpg", "Best Survival Tools for Preppers", "Tools", 1,1),
(2, "./static/images/2.jpg", "Prepare for Food Shortages", "Meal Prep", 1,1),
(3, "./static/images/3.jpg", "Amazing Survival Recipes", "Meal Prep", 1,1),
(4, "./static/images/4.jpg", "YOU NEED TO KNOW THESE LIFE HACKS!", "Hacks", 1,1),
(5, "./static/images/5.jpg", "Your emergency stockpile isnt complete without these 100 things", "Tools", 1,1),
(6, "./static/images/6.jpg", "World War 3 is Coming, are you Prepared??", "Tips", 1,1),
(7, "./static/images/7.jpg", "Want to Survive? Better read this..", "Tips", 1,1),
(8, "./static/images/8.jpg", "Clothes that Guarantee Survival", "Clothes", 1,1),
(9, "./static/images/9.jpg", "If you don'T have these in your pantry, uh oh", "Meal Prep", 1,1),
(10, "./static/images/10.jpg", "Rebuild after the apocalypse is over with these plants", "Gardening", 1,1),
(11, "./static/images/11.jpg", "Flowers will be worth millions soon, enjoy them now", "Gardening", 1,1)

]


Expand Down
17 changes: 16 additions & 1 deletion Client/image_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import base64
import os
import json
import sys

#importiing the load an predict function from Image Classifier Branch (Alexa's Branch)
# Adds the project root to sys.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from Image_Classifier.Image_Classifier.deployment import load_and_predict



class ImageManager:
Expand Down Expand Up @@ -43,13 +50,21 @@ def upload_image(self, image_file, caption, tags):

with open(image_path, 'wb') as f:
f.write(image_content)

base_dir = os.path.dirname(os.path.abspath(__file__)) # path to image_manager.py
model_path = os.path.join(base_dir, "../Image_Classifier/Image_Classifier/imageclassifierHS_Updated.h5")
model_path = os.path.normpath(model_path)


image_path = f"./static/uploads/{image_filename}"
predicted_category = load_and_predict(model_path, image_path)

#new image dictionary for the users newly uploaded image
uploaded_image = {
'id': len(self.uploaded_images) + 1,
'url': f"./static/uploads/{image_filename}",
'caption': caption,
'category': tags,
'category': [tags, predicted_category],
'image': base64_image
}

Expand Down
6 changes: 6 additions & 0 deletions Client/saved_images.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
"url": "./static/images/3.jpg",
"caption": "Amazing Survival Recipes",
"category": "Meal Prep"
},
{
"id": 6,
"url": "./static/images/6.jpg",
"caption": "World War 3 is Coming, are you Prepared??",
"category": "Tips"
}
]
}
1 change: 1 addition & 0 deletions Client/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ body.login-page {
max-height: 250px;
border-radius: 4px;
}

/* comment */
#modalImage {
max-height: 600px;
Expand Down
2 changes: 1 addition & 1 deletion Client/templates/image-grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ <h5 class="card-title">{{ image.caption }}</h5>
</div>
{% include "comments.html" %}

<script src="{{ url_for('static', filename='js/image-grid.js') }}"></script>

<script src="{{ url_for('static', filename='js/image-grid.js') }}"></script>
Binary file added Image_Classifier/.DS_Store
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading