File size: 1,179 Bytes
1199274
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)

                # Collect results in a list
                self.results.extend(result_generator)

                # Successful execution, break the loop
                break

            except (RuntimeError, Exception) as e:
                print(f"Error: {e}")
                print(f"Error during image creation (Attempt {attempts + 1}/{self.max_attempts})")
                attempts += 1

                # For the first attempt, add a delay
                if attempts == 1:
                    time.sleep(1)  # Add a delay between attempts if needed

        return self.results



s = ImageTextGenerator("red Cow").generate_images_text()
print("sssssssssssssssssss", s)