|
import time |
|
from .Provider.bing import CreateImagesBing |
|
|
|
|
|
class ImageTextGenerator: |
|
def __init__(self, prompt, max_attempts=5): |
|
self.prompt = prompt |
|
self.max_attempts = max_attempts |
|
self.results = [] |
|
|
|
def generate_images_text(self): |
|
attempts = 0 |
|
|
|
while attempts < self.max_attempts: |
|
try: |
|
bing_images_provider = CreateImagesBing() |
|
result_generator = bing_images_provider.create_completion(prompt=self.prompt) |
|
|
|
|
|
self.results.extend(result_generator) |
|
|
|
|
|
break |
|
|
|
except (RuntimeError, Exception) as e: |
|
print(f"Error: {e}") |
|
print(f"Error during image creation (Attempt {attempts + 1}/{self.max_attempts})") |
|
attempts += 1 |
|
|
|
|
|
if attempts == 1: |
|
time.sleep(1) |
|
|
|
return self.results |
|
|
|
|
|
|
|
s = ImageTextGenerator("red Cow").generate_images_text() |
|
print("sssssssssssssssssss", s) |