This commit is contained in:
Pei-Yun Sun 2020-10-20 01:26:09 +11:00
parent 5af2071aa0
commit c1b350ab77
14 changed files with 24 additions and 93 deletions

View File

@ -9,41 +9,6 @@ import copy
api = Namespace('general', path='/', description='general information related to app')
# @api.route('/get-breed-info')
# class BreedList(Resource):
# @api.doc('get breed information from csv')
# def get(self):
# """
# return the breed information, which gets from wikipedia
# :return: list of breed information
# """
# breed_info = {}
# for animal_type in CONSTANTS['ANIMAL_TYPE']:
# with open('wikiFile/' + animal_type + '.csv') as csv_file:
# csv_reader = csv.reader(csv_file, delimiter=',')
# line_count = 0
# json_title = []
# animal_list = []
# for row in csv_reader:
# if line_count == 0:
# json_title = row
# line_count += 1
# else:
# info_obj = {
# json_title[0]: row[0],
# json_title[1]: row[1],
# json_title[2]: row[2],
# json_title[3]: row[3],
# json_title[4]: row[4],
# }
# animal_list.append(info_obj)
# line_count += 1
# csv_file.close()
# breed_info[animal_type] = animal_list
# return send_json_response(breed_info, 200)
@api.route('/get-app-info')
class AppInfo(Resource):
@api.doc('return the app developer information')

View File

@ -60,19 +60,24 @@ class DeepFaceLite(object):
sum_of_predictions = emotion_predictions.sum()
all_emotions = {}
all_emotions = []
for j in range(0, len(emotion_labels)):
emotion_label = emotion_labels[j]
emotion_prediction = 100 * emotion_predictions[j] / sum_of_predictions
all_emotions[emotion_label] = emotion_prediction
# all_emotions[emotion_label] = '{:.4f}'.format(emotion_prediction)
max_score = 100 * np.max(emotion_predictions) / sum_of_predictions
all_emotions.append('{}: {:.4f}'.format(emotion_label, emotion_prediction))
emotion = {
'all': all_emotions,
'dominant': emotion_labels[np.argmax(emotion_predictions)],
'dominant_score': np.max(emotion_predictions)
'dominant_score': '{:.4f}'.format(max_score)
}
print(emotion)
# --- age ---
age_predictions = self.age_model.predict(imgs_224[i])[0,:]
apparent_age = Age.findApparentAge(age_predictions)
@ -88,7 +93,8 @@ class DeepFaceLite(object):
# resp_obj = json.loads(resp_obj)
resp_obj = {
'age': apparent_age,
'id': i,
'age': np.round(apparent_age),
'gender': gender,
'emotion': emotion
}

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pet Smile</title>
<title>HappyPeople</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link href="/static/css/fileinput.min.css" media="all" rel="stylesheet" type="text/css"/>
@ -23,7 +23,7 @@
<nav class="navbar navbar-expand-lg navbar-light bg-light" style="background-color: #e3f2fd; margin-bottom: 30px; width: 100%">
<a class="navbar-brand" href="/">
<div style="font-size: 45px; margin-left: 30px">
<span style="font-weight: bold">Happy</span>Pet
<span style="font-weight: bold">Happy</span>People
</div>
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup"
@ -33,7 +33,6 @@
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-item nav-link active" href="/">Home</a>
<a class="nav-item nav-link" href="/breed-list">Breed Info</a>
<a class="nav-item nav-link" href="/statistical-data">Statistical Results</a>
</div>
</div>

View File

@ -1,32 +0,0 @@
{% extends 'base.html' %}
{% block mainContent %}
<div id="breed-table-area" style="margin-left: 50px; margin-right: 50px;">
</div>
<script>
function getBreedList() {
$.get("/api/get-breed-info", function(response) {
let breedTableArea = document.getElementById('breed-table-area')
breedTableArea.innerHTML = ''
let htmlContent = ''
for (let animalType in response) {
htmlContent += '<h2 style="text-align: center">' + animalType + '</h2>' + '<table class="table table-striped"><thead><tr><th scope="col">Breed</th><th scope="col">Image</th><th scope="col">Description</th><th scope="col">URL</th></tr></thead><tbody>'
response[animalType].forEach(eachBreed => {
htmlContent += '<tr>'
htmlContent += '<td>' + eachBreed['breed'] + '</td>'
htmlContent += `<td><img src=${eachBreed['image']} alt=${eachBreed['image']} style="height: 100px; width: 100px"></td>`
htmlContent += '<td>' + eachBreed['description'] + '</td>'
htmlContent += `<td><a href=${eachBreed['link']} target="_blank">wikipedia link</a></td></tr>`
})
htmlContent += '</tbody></table>'
}
htmlContent += '<p style="text-align: end">(all results are downloaded from wikipedia)</p>'
breedTableArea.innerHTML = htmlContent;
});
}
getBreedList();
</script>
{% endblock %}

View File

@ -69,8 +69,8 @@
if (response['status'] === 'success') {
for (let i=0; i<response['results'].length; i++) {
const addedId = `<div style=\"border: 1px dashed darkgrey\"><ul><li><strong>ID: </strong>${response['results'][i].id}`
const emotionList = `<div style=\"margin: 10px 30px; font-weight: lighter;\"><ul><li>${response['results'][i].emotion['allEmotions'][0]}</li><li>${response['results'][i].emotion['allEmotions'][1]}</li><li>${response['results'][i].emotion['allEmotions'][2]}</li><li>${response['results'][i].emotion['allEmotions'][3]}</li><li>${response['results'][i].emotion['allEmotions'][4]}</li></ul></div>`
const otherInfo = `</li><li><strong>Type: </strong>${response['results'][i].pet}</li><li><strong>Breed: </strong>${response['results'][i].breed}</li><li><strong>Emotion: </strong>${response['results'][i].emotion['mostLikely']}</li></ul>${emotionList}</div>`
const emotionList = `<div style=\"margin: 10px 30px; font-weight: lighter;\"><ul><li>${response['results'][i].emotion['all'][0]}</li><li>${response['results'][i].emotion['all'][1]}</li><li>${response['results'][i].emotion['all'][2]}</li><li>${response['results'][i].emotion['all'][3]}</li><li>${response['results'][i].emotion['all'][4]}</li><li>${response['results'][i].emotion['all'][5]}</li><li>${response['results'][i].emotion['all'][6]}</li></ul></div>`
const otherInfo = `</li><li><strong>Age: </strong>${response['results'][i].age}</li><li><strong>Gender: </strong>${response['results'][i].gender}</li><li><strong>Emotion: </strong>${response['results'][i].emotion['dominant']}</li></ul>${emotionList}</div>`
const addedHtml = response['isShowId'] !== 'false' ? addedId + otherInfo : otherInfo
resultArea.innerHTML += addedHtml
}

View File

@ -8,11 +8,6 @@ def render_homepage():
return render_template("homePage.html")
@public_route_bp.route('/breed-list')
def render_breed_info_page():
return render_template('breedPage.html')
@public_route_bp.route('/statistical-data')
def render_statistical_page():
return render_template('statisticalPage.html')