rairo commited on
Commit
2756581
·
verified ·
1 Parent(s): 4e22b17

Update image_gen.py

Browse files
Files changed (1) hide show
  1. image_gen.py +6 -6
image_gen.py CHANGED
@@ -103,7 +103,7 @@ def generate_image(prompt_text, style, model="hf"):
103
  response = requests.get(api_url)
104
  if response.status_code != 200:
105
  logger.error(f"Pollinations API error: {response.status_code}, {response.text}")
106
- st.error(f"Error from image generation API: {response.status_code}")
107
  return None, None
108
  image_bytes = response.content
109
 
@@ -115,7 +115,7 @@ def generate_image(prompt_text, style, model="hf"):
115
  g_api_key = os.getenv("GEMINI")
116
  if not g_api_key:
117
  logger.error("GEMINI_API_KEY not found in environment variables")
118
- st.error("Google Gemini API key is missing. Please set the GEMINI_API_KEY environment variable.")
119
  return None, None
120
 
121
  # Initialize Gemini client
@@ -145,7 +145,7 @@ def generate_image(prompt_text, style, model="hf"):
145
 
146
  # If no image was found in the response
147
  logger.error("No image was found in the Gemini API response")
148
- st.error("Gemini API didn't return an image")
149
  return None, None
150
 
151
  except ImportError:
@@ -155,7 +155,7 @@ def generate_image(prompt_text, style, model="hf"):
155
 
156
  except Exception as e:
157
  logger.error(f"Gemini API error: {str(e)}")
158
- st.error(f"Error from Gemini image generation: {str(e)}")
159
  return None, None
160
 
161
  else: # Default to Hugging Face model
@@ -167,7 +167,7 @@ def generate_image(prompt_text, style, model="hf"):
167
  response = requests.post(api_url, headers=headers, json=payload)
168
  if response.status_code != 200:
169
  logger.error(f"Hugging Face API error: {response.status_code}, {response.text}")
170
- st.error(f"Error from image generation API: {response.status_code}")
171
  return None, None
172
  image_bytes = response.content
173
 
@@ -180,7 +180,7 @@ def generate_image(prompt_text, style, model="hf"):
180
  return image, img_str
181
 
182
  except Exception as e:
183
- st.error(f"Error generating image: {e}")
184
  logger.error(f"Image generation error: {str(e)}")
185
 
186
  # Return a placeholder image in case of failure
 
103
  response = requests.get(api_url)
104
  if response.status_code != 200:
105
  logger.error(f"Pollinations API error: {response.status_code}, {response.text}")
106
+ print(f"Error from image generation API: {response.status_code}")
107
  return None, None
108
  image_bytes = response.content
109
 
 
115
  g_api_key = os.getenv("GEMINI")
116
  if not g_api_key:
117
  logger.error("GEMINI_API_KEY not found in environment variables")
118
+ print("Google Gemini API key is missing. Please set the GEMINI_API_KEY environment variable.")
119
  return None, None
120
 
121
  # Initialize Gemini client
 
145
 
146
  # If no image was found in the response
147
  logger.error("No image was found in the Gemini API response")
148
+ print("Gemini API didn't return an image")
149
  return None, None
150
 
151
  except ImportError:
 
155
 
156
  except Exception as e:
157
  logger.error(f"Gemini API error: {str(e)}")
158
+ print(f"Error from Gemini image generation: {str(e)}")
159
  return None, None
160
 
161
  else: # Default to Hugging Face model
 
167
  response = requests.post(api_url, headers=headers, json=payload)
168
  if response.status_code != 200:
169
  logger.error(f"Hugging Face API error: {response.status_code}, {response.text}")
170
+ print(f"Error from image generation API: {response.status_code}")
171
  return None, None
172
  image_bytes = response.content
173
 
 
180
  return image, img_str
181
 
182
  except Exception as e:
183
+ print(f"Error generating image: {e}")
184
  logger.error(f"Image generation error: {str(e)}")
185
 
186
  # Return a placeholder image in case of failure