Update main.py
Browse files
main.py
CHANGED
@@ -64,23 +64,28 @@ def send_it1(inputs, noise_level, proc=proc1):
|
|
64 |
output = proc(prompt_with_noise)
|
65 |
return output
|
66 |
|
67 |
-
def generate_image(
|
68 |
try:
|
69 |
global request_counter
|
70 |
request_counter += 1
|
71 |
timestamp = f"{time.time()}_{request_counter}"
|
72 |
-
prompt_with_noise = add_random_noise(inputs
|
73 |
payload = {"inputs": prompt_with_noise}
|
74 |
response = requests.post(API_URL, headers=headers, json=payload)
|
75 |
response.raise_for_status() # Raise an exception for HTTP errors
|
76 |
image_bytes = response.content
|
77 |
image = Image.open(io.BytesIO(image_bytes))
|
78 |
return image
|
|
|
|
|
|
|
|
|
79 |
except Exception as e:
|
80 |
-
# Handle
|
81 |
-
|
82 |
-
return "
|
83 |
-
|
|
|
84 |
|
85 |
def get_prompts(prompt_text):
|
86 |
if not prompt_text:
|
|
|
64 |
output = proc(prompt_with_noise)
|
65 |
return output
|
66 |
|
67 |
+
def generate_image(inputs):
|
68 |
try:
|
69 |
global request_counter
|
70 |
request_counter += 1
|
71 |
timestamp = f"{time.time()}_{request_counter}"
|
72 |
+
prompt_with_noise = add_random_noise(inputs) + f" - {timestamp}"
|
73 |
payload = {"inputs": prompt_with_noise}
|
74 |
response = requests.post(API_URL, headers=headers, json=payload)
|
75 |
response.raise_for_status() # Raise an exception for HTTP errors
|
76 |
image_bytes = response.content
|
77 |
image = Image.open(io.BytesIO(image_bytes))
|
78 |
return image
|
79 |
+
except requests.exceptions.HTTPError as e:
|
80 |
+
# Handle any HTTP errors
|
81 |
+
print(f"HTTP Error: {e}")
|
82 |
+
return "An unexpected error occurred while generating the image."
|
83 |
except Exception as e:
|
84 |
+
# Handle other exceptions
|
85 |
+
print(f"Error generating image: {e}")
|
86 |
+
return "An unexpected error occurred while generating the image. Please try again later."
|
87 |
+
|
88 |
+
|
89 |
|
90 |
def get_prompts(prompt_text):
|
91 |
if not prompt_text:
|