55from app .mod_photos .models import Photo
66
77from factory_responses import FactoryResponse
8+ from subprocess import check_output
89
910import uuid
1011import 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\n caca2:resultado2\n caca3:resultado3\n caca4:resultado4\n caca5:resultado5" ])
30+ values = output .split ("\n " )[:- 1 ]
31+ return values
32+
2633@mod_photos .route ('/photos' ,methods = ['POST' ])
2734def 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
0 commit comments