diff --git a/server/infra/web/recognizer.py b/server/infra/web/recognizer.py index d6bf633..d530264 100644 --- a/server/infra/web/recognizer.py +++ b/server/infra/web/recognizer.py @@ -63,5 +63,6 @@ class BreedsController(Controller): context={ "result": result, "attachment": attachments[0], + "share_id": result_id, }, ) diff --git a/server/modules/recognizer/service.py b/server/modules/recognizer/service.py index 305d541..adb6864 100644 --- a/server/modules/recognizer/service.py +++ b/server/modules/recognizer/service.py @@ -47,6 +47,7 @@ class RecognizerResult(UJsonMixin): images: list description: dict[str, list] | None uploaded_attach_id: str | None + share_id: str | None @dataclass @@ -90,12 +91,13 @@ class RecognizerService: async def create_result( self, attachment: Attachment, user_id: str, device_id: str, beerd_results: list[ResultNameBeerds] - ): + ) -> str: beerd_names = {b.name: b for b in beerd_results} characters = await self._repository_characters.get_characters() + share_id = str(uuid4()) await self._repository.create_result_with_beerds( models.Results( - id=str(uuid4()), + id=share_id, attachment_id=attachment.id, user_id=user_id, device_id=device_id, @@ -107,15 +109,16 @@ class RecognizerService: if ch.name in beerd_names ], ) + return share_id async def get_results(self, result_id: str) -> SharingResult: results = await self._repository.get_results() beerds_store: dict[str, Breed] = {b.id: b for b in await self._repository_characters.get_characters()} images_dogs = await self._repository.images_dogs() + beers: list[SharingBeerds] = [] for r in results: if r.result.id != result_id: continue - beers: list[SharingBeerds] = [] for beerd in r.beerds: name = beerds_store[beerd.beerd_id].name.replace(" ", "_") beers.append( @@ -148,16 +151,20 @@ class RecognizerService: ) description.setdefault(name, []).append(f"/dogs-characteristics/{name.replace(' ', '_')}") results[probabilities] = name - asyncio.create_task( - self.create_result( - attachment, - user_id, - device_id, - [ResultNameBeerds(name=results[key], probability=key*100) for key in results], - ) + + share_id = await self.create_result( + attachment, + user_id, + device_id, + [ResultNameBeerds(name=results[key], probability=key*100) for key in results], ) + return RecognizerResult( - results=results, images=images, description=description, uploaded_attach_id=attachment.id + results=results, + images=images, + description=description, + uploaded_attach_id=attachment.id, + share_id=share_id ) async def predict_cat_image(self, image: bytes) -> RecognizerResult: @@ -176,7 +183,13 @@ class RecognizerService: ) ) results[probabilities] = name - return RecognizerResult(results=results, images=images, description=None, uploaded_attach_id=attachment.id) + return RecognizerResult( + results=results, + images=images, + description=None, + uploaded_attach_id=attachment.id, + share_id=None + ) def _predict(self, image: bytes, model, device="cpu") -> list[Any]: img_size = (224, 224) diff --git a/server/static/scripts.js b/server/static/scripts.js index 701a0e9..cc8ed4f 100644 --- a/server/static/scripts.js +++ b/server/static/scripts.js @@ -16,8 +16,23 @@ async function SavePhoto(self) { if (response.ok) { let json = await response.json(); currentAttachmentID = json.uploaded_attach_id; - - let text = "