g4f0204 / g4f /s.py
mfoud444's picture
app1
1199274
raw
history blame contribute delete
No virus
1.18 kB
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)