Skip to content

Commit f7e80a3

Browse files
committed
Fixed design error, added TODO to fix webpage, it is not working
1 parent b97c73b commit f7e80a3

File tree

6 files changed

+31
-29
lines changed

6 files changed

+31
-29
lines changed

app/mod_photos/controllers.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from app.mod_photos.models import Photo
66

77
from factory_responses import FactoryResponse
8+
from subprocess import check_output
89

910
import uuid
1011
import os
@@ -23,6 +24,12 @@ def timestamp():
2324
import time
2425
return str(time.time()).split(".")[0]
2526

27+
def execute_tiny_cnn(filepath):
28+
#TODO add code tiny cpp example
29+
output=check_output(["echo", "caca1:resultado1\ncaca2:resultado2\ncaca3:resultado3\ncaca4:resultado4\ncaca5:resultado5"])
30+
values = output.split("\n")[:-1]
31+
return values
32+
2633
@mod_photos.route('/photos',methods=['POST'])
2734
def post_photos():
2835
app.logger.debug("Applying post photo...")
@@ -38,14 +45,19 @@ def post_photos():
3845

3946

4047
extension = os.path.splitext(file.filename)[1]
41-
f_name=timestamp()+str(uuid.uuid4()) + extension
48+
identifier=timestamp()+str(uuid.uuid4())
49+
f_name=identifier + extension
4250
app.logger.debug("f_name="+f_name)
51+
app.logger.debug("identifier="+identifier)
4352
filepath=os.path.join(app.config['UPLOAD_FOLDER'], f_name)
44-
photo = Photo(f_name,filepath)
45-
data ={'uuid':f_name, 'filepath': filepath}
46-
Photo.create(**data)
53+
#First result
54+
values = execute_tiny_cnn(filepath)
55+
result = '\n'.join(values)
56+
57+
data ={'uuid':identifier, 'filepath': filepath, 'analysed':True, 'info':str(values)}
58+
new_photo = Photo.create(**data)
4759
file.save(filepath)
48-
data = {'filename':f_name}
60+
data = {'filename':f_name, 'info':str(values),'id': new_photo.id}
4961
#TODO refactor to set up necessary methods to create responses
5062
#TODO is it necessary to return 200 command
5163
resp = None

app/mod_photos/models.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,28 @@ class Base(db.Model):
66
id = db.Column(db.Integer, primary_key=True)
77
date_created = db.Column(db.DateTime, default=db.func.current_timestamp())
88

9+
910
class Photo(Base,CRUDMixin):
1011
__tablename__='photo'
1112
uuid = db.Column(db.String(128), nullable=False)
1213
filepath = db.Column(db.String(500), nullable=False)
14+
analysed = db.Column(db.Boolean,default=False)
15+
info = db.Column(db.String(1000),nullable=False)
1316

1417

15-
def __init__(self,uuid,filepath):
18+
def __init__(self,uuid,filepath,analysed=False,info=""):
1619
self.uuid = uuid
1720
self.filepath = filepath
21+
self.analysed=analysed
22+
self.info=info
1823

1924
def get_id(self):
2025
return self.id
2126

2227
def serialize(self):
2328
return {'uuid':self.uuid}
2429
def serialize_all(self):
25-
return {'uuid':self.uuid, 'filepath': self.filepath}
30+
return {'uuid':self.uuid, 'filepath': self.filepath, 'analysed': self.analysed, 'info': self.info}
2631
def __repr__(self):
2732
return '<photo uuid=%r filepath=%r>' % (self.uuid,self.filepath)
2833

app/static/js/app.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ app.directive('fileModel',['$parse', function($parse) {
3333

3434

3535

36-
app.service('fileUpload',['$http','$scope'
36+
app.service('fileUpload',['$http','$scope',
3737
function($http, $scope) {
3838
this.uploadFileToUrl = function(file) {
3939
var fd = new FormData();
@@ -60,13 +60,6 @@ app.controller('myController', ['$scope', 'fileUpload',
6060
console.dir(file1);
6161
var uploadUrl = "/fileUpload";
6262
fileUpload.uploadFileToUrl(file1);
63-
64-
var file2 = $scope.myFile2;
65-
console.log('File is ');
66-
console.dir(file2);
67-
var uploadUrl = "/fileUpload";
68-
fileUpload.uploadFileToUrl(file2);
69-
7063
};
7164

7265
}]);

app/templates/index.html

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!doctype html>
22
<html lang="en">
33
<meta charset="utf-8">
4-
<title>Give me an avatar</title>
4+
<title>Give me a photo</title>
55

66
<link rel="stylesheet" href="/static/css/bootstrap.css">
77
<link rel="stylesheet" href="/static/css/main.css">
@@ -25,15 +25,10 @@
2525
};
2626
};
2727

28-
function UploadImage2(){
29-
var oFReader = new FileReader();
30-
oFReader.readAsDataURL(document.getElementById("uploadImage2").files[0]);
31-
oFReader.onload = function(oFREvent){
32-
document.getElementById("image2").src = oFREvent.target.result;
33-
};
34-
};
3528
</script>
36-
<!-- <script type="text/javascript" src="angular.min.js"></script>-->
29+
<!--
30+
//TODO remove this web it is not working
31+
<script type="text/javascript" src="angular.min.js"></script>-->
3732

3833
<body ng-app="app" ng-controller="myController">
3934
<!-- <input type="file" ng-file-selected="onFileSelected($files)" ng-model="imageSrc" /> -->
@@ -48,11 +43,6 @@ <h3>{{responseid}}</h3>
4843
<div class="image1">
4944
<img id="image1">
5045
</div>
51-
<input type="file" id="uploadImage2" onchange="UploadImage2();" file_model="myFile2">
52-
<br><br>
53-
<div class="image2">
54-
<img id="image2">
55-
</div>
5646

5747
<button ng-click="uploadFile()"> upload me</button>
5848
</form>

tasks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from celery import Celery
22
from flask.ext.sqlalchemy import SQLAlchemy
3+
from app.mod_photos.models import Photo
34
from app.data import db
45

56
celery = Celery('tasks')

test_curl.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
curl -F "userid=1"-F "filecomment=This is an image file" -F "file=@/home/carlos/Desktop/caffenet/cat.jpg" localhost:5000/photos/v1.0/photos

0 commit comments

Comments
 (0)