Commit 8ab0ac5a authored by Josh's avatar Josh
Browse files

update

parent d51b6ffd
......@@ -11,6 +11,8 @@ from redis import Redis
import rq
from rq import get_current_job
from ai4hdr_backend import importAndProcess
'''
HDR App database interface
......@@ -216,24 +218,25 @@ class HDRFileDB( HDRDatabaseInterface ):
def importAndProcessImage( self, imagePath: Path ):
def importAndProcessImage( self, imagePath: str ):
print( imagePath )
'''
- arg1: path to the image
- arg2: path to database
- arg3: new name for image
'''
imageName = imagePath.name.split( "." )[0]
imageName = Path(imagePath).name.split( "." )[0]
#os.system( "python ai4hdr_backend/Scripts/importAndProcessImage.py {} {} {}".format( imagePath, self.dbBasePath, imageName ) )
imgPath = str( imagePath )
dbPath = str( self.dbBasePath )
newName = imageName
#importAndProcess( imgPath=imgPath, dbPath=dbPath, newImgName=newName )
queue = rq.Queue( "hdr-tasks", connection=Redis.from_url( "redis://" ) )
job = queue.enqueue( "tasks.importAndProcessImageTask", imgPath, dbPath, newName )
print( "IMPORT AND PROCESS" )
importAndProcess( imgPath=imgPath, dbPath=dbPath, newImgName=newName )
print( "DONE")
#queue = rq.Queue( "hdr-tasks", connection=Redis.from_url( "redis://" ) )
#job = queue.enqueue( "tasks.importAndProcessImageTask", imgPath, dbPath, newName )
'''
......
......@@ -14,6 +14,23 @@ import numpy as np
import io
import base64
from celery import Celery
def make_celery(app):
celery = Celery(
app.import_name,
backend=app.config['result_backend'],
broker=app.config['broker_url']
)
celery.conf.update(app.config)
class ContextTask(celery.Task):
def __call__(self, *args, **kwargs):
with app.app_context():
return self.run(*args, **kwargs)
celery.Task = ContextTask
return celery
'''
Global Variables
......@@ -25,10 +42,20 @@ ALLOWED_EXTENSIONS = { "png", "jpg", "jpeg" }
'''
App Config
'''
app = Flask(__name__)
imageDB = None
app = Flask( __name__ )
imageDB = HDRFileDB( "../ImageDatabase" )
app.config["STATIC_PATH"] = str( Path.cwd().joinpath( "static" ) )
app.config["broker_url"] = 'redis://localhost:6379'
app.config["result_backend"] = 'redis://localhost:6379'
celery = make_celery(app)
app.config["STATIC_PATH"] = str( Path.cwd().joinpath( "static" ) )
@celery.task(name="app.importAndProcessImage")
def importAndProcessImage( imagePath ):
imageDB.importAndProcessImage( imagePath )
return "OK"
'''
App Routes
......@@ -114,7 +141,9 @@ def uploadImage():
file.save( os.path.join( str( tmpDir ), filename ) )
# Launch import and process
imageDB.importAndProcessImage( tmpDir.joinpath( filename ).resolve() )
#imageDB.importAndProcessImage( tmpDir.joinpath( filename ).resolve() )
result = importAndProcessImage.delay( str( tmpDir.joinpath( filename ).resolve() ) )
result.wait() # 65
print( "BACK TO APP" )
return render_template( "imageUpload.html" )
......@@ -176,11 +205,11 @@ def getProcessedImages( sliceId ):
if __name__ == "__main__":
if len( sys.argv ) == 2:
#if len( sys.argv ) == 2:
imageDB = HDRFileDB( sys.argv[1] )
#imageDB = HDRFileDB( sys.argv[1] )
webbrowser.open_new( "http://127.0.0.1:2000/" )
app.run( debug=True, port=2000 )
else:
print( "Must Provide Database Location" )
\ No newline at end of file
webbrowser.open_new( "http://127.0.0.1:2000/" )
app.run( debug=True, port=2000 )
#else:
# print( "Must Provide Database Location" )
\ No newline at end of file
sudo service redis-server start
\ No newline at end of file
......@@ -32,3 +32,5 @@ def importAndProcessImageTask( imagePath, dbPath, newName ):
#example( 5 )
shutil.rmtree( Path( imagePath ).parent )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment