Skip to content

Commit

Permalink
Fix/enhance multigenerator (#300)
Browse files Browse the repository at this point in the history
* Instanciate more dalle2 and 3 provides, fix the way of instanciating several model passing the model instance

* Fix response parser in SDXLImageProvider

* Add retry logic and give 2 more seconds to SDXL Image Provider
  • Loading branch information
shincap8 authored Sep 3, 2024
1 parent ef25b4c commit bf2cfdf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions backend/app/domain/services/utils/image_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def __init__(self, model_instance: str):
self.api_key = os.getenv("HF")
self.session = RequestSession()
self.model_instance = model_instance
self.timeout = 62

def generate_images(
self, prompt: str, num_images: int, model, endpoint, user_id
Expand Down
18 changes: 17 additions & 1 deletion backend/worker/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ def generate_images(
res = images.apply_async()
print(res)
all_responses = res.get(disable_sync_subtasks=False)
successes = len(
[response for response in all_responses if response["message"] == "Success"]
)
if (successes + num_of_current_images) < 5:
more_images = celery.group(
*[
generate_nibbler_images_celery.s(
prompt, num_images, models, endpoint, user_id
)
for _ in range(5 - successes + num_of_current_images)
]
)
res = more_images.apply_async()
additional_responses = res.get(disable_sync_subtasks=False)
all_responses.extend(additional_responses)
if (len(all_responses) + num_of_current_images) >= 5:
job_service.remove_registry({"prompt": prompt, "user_id": user_id})

Expand All @@ -85,5 +100,6 @@ def generate_images(

logger.critical(json.dumps(info_to_log))
except Exception as e:
print(e)
error = e
print("Error: ", error)
job_service.remove_registry({"prompt": prompt, "user_id": user_id})

0 comments on commit bf2cfdf

Please sign in to comment.