Skip to content

Commit

Permalink
get picture route #105
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvanie85 committed Jul 26, 2024
1 parent 97b7728 commit e2e7d44
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
71 changes: 69 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from tkinter import image_names
import urllib.request
import json
import os
Expand Down Expand Up @@ -176,10 +177,14 @@ async def before_serving():
"""
) #TODO Transform into logging

except (ServerError, inference.ModelAPIErrors) as e:
except (Exception, ServerError, inference.ModelAPIErrors) as e:
print(e)
raise

@app.before_request
def log_request_info():
print(f"Call:{request.path}")


@app.post("/get-user-id")
async def get_user_id() :
Expand Down Expand Up @@ -321,7 +326,7 @@ async def delete_with_archive():
print(error)
return jsonify([f"DeleteDirectoryRequestError: {str(error)}"]), 400


# Deprecated
@app.post("/dir")
async def list_directories():
"""
Expand All @@ -346,6 +351,68 @@ async def list_directories():
print(error)
return jsonify([f"ListDirectoriesRequestError: {str(error)}"]), 400

@app.post("/get-directories")
async def get_directories():
"""
get all directories in the user's container with pictures names and number of pictures
"""
try:
data = await request.get_json()
user_id = data["container_name"]
if user_id:
# Open db connection
connection = datastore.get_connection()
cursor = datastore.get_cursor(connection)

directories_list = await datastore.get_directories(cursor, str(user_id))

# Close connection
datastore.end_query(connection, cursor)

result = {"folders" : directories_list}
return jsonify(result)
else:
raise ListDirectoriesRequestError("Missing container name")

except (KeyError, TypeError, ListDirectoriesRequestError, azure_storage.MountContainerError, datastore.DatastoreError) as error:
print(error)
return jsonify([f"ListDirectoriesRequestError: {str(error)}"]), 400

@app.post("/get-picture")
async def get_picture():
"""
get all directories in the user's container with pictures names and number of pictures
"""
try:
data = await request.get_json()
user_id = data["container_name"]
picture_id = data["picture_id"]

if user_id:
# Open db connection
connection = datastore.get_connection()
cursor = datastore.get_cursor(connection)

picture = {}
picture["picture_id"] = picture_id

inference = await datastore.get_inference(cursor, str(user_id), str(picture_id))
picture["inference"] = inference

image = await datastore.get_image_hash_value(cursor, str(user_id), str(picture_id))
print(image)
picture["image"] = image

# Close connection
datastore.end_query(connection, cursor)
return jsonify(picture)
else:
raise ListDirectoriesRequestError("Missing container name")

except (KeyError, TypeError, ListDirectoriesRequestError, azure_storage.MountContainerError, datastore.DatastoreError) as error:
print(error)
return jsonify([f"ListDirectoriesRequestError: {str(error)}"]), 400


@app.post("/create-dir")
async def create_directory():
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ cryptography
pyyaml
pydantic
python-magic
nachet-datastore @git+https://github.com/ai-cfia/nachet-datastore.git@b0d85ce68ed08928b7240c35d9d462cda48ba294
nachet-datastore @git+https://github.com/ai-cfia/nachet-datastore.git@a06703a6d32da71c851469ada1d5a4e5cfb3eda9
12 changes: 12 additions & 0 deletions storage/datastore_storage_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,15 @@ async def get_directories(cursor, user_id):
return await datastore.get_picture_sets_info(cursor, user_id)
except Exception as error:
raise DatastoreError(error)

async def get_inference(cursor, user_id, picture_id):
try :
return await nachet_datastore.get_picture_inference(cursor, user_id, picture_id)
except Exception as error:
raise DatastoreError(error)

async def get_image_hash_value(cursor, user_id, picture_id):
try :
return await nachet_datastore.get_picture_blob(cursor, user_id, picture_id)
except Exception as error:
raise DatastoreError(error)

0 comments on commit e2e7d44

Please sign in to comment.