Spaces:
Sleeping
Sleeping
Update image_gen.py
Browse files- image_gen.py +5 -7
image_gen.py
CHANGED
|
@@ -183,19 +183,17 @@ def generate_image(prompt_text, style, model="hf"):
|
|
| 183 |
# Call Pexels search endpoint
|
| 184 |
# e.g. GET https://api.pexels.com/v1/search?query={prompt_text}&per_page=1
|
| 185 |
|
| 186 |
-
|
| 187 |
headers_pexels = {
|
| 188 |
"Authorization": pexels_api_key
|
| 189 |
}
|
| 190 |
new_prompt = model_g.generate_content(f"Generate keywords or a phrase to search for an appropriate image on the pexels API based on this prompt: {prompt_text}")
|
| 191 |
pexel_prompt = str(new_prompt.text)
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
}
|
| 196 |
-
response = requests.get(search_url, headers=headers_pexels, params=params)
|
| 197 |
if response.status_code != 200:
|
| 198 |
-
logger.error(f"Pexels API error: {response.status_code}, {response.text}")
|
| 199 |
print(f"Error from Pexels API: {response.status_code}")
|
| 200 |
return None, None
|
| 201 |
|
|
|
|
| 183 |
# Call Pexels search endpoint
|
| 184 |
# e.g. GET https://api.pexels.com/v1/search?query={prompt_text}&per_page=1
|
| 185 |
|
| 186 |
+
|
| 187 |
headers_pexels = {
|
| 188 |
"Authorization": pexels_api_key
|
| 189 |
}
|
| 190 |
new_prompt = model_g.generate_content(f"Generate keywords or a phrase to search for an appropriate image on the pexels API based on this prompt: {prompt_text}")
|
| 191 |
pexel_prompt = str(new_prompt.text)
|
| 192 |
+
|
| 193 |
+
search_url = f"https://api.pexels.com/v1/search?query={pexel_prompt}&per_page=1"
|
| 194 |
+
response = requests.get(search_url, headers=headers_pexels)
|
|
|
|
|
|
|
| 195 |
if response.status_code != 200:
|
| 196 |
+
logger.error(f"Pexels API error: {response.status_code}, {response.text} from {pexel_prompt}")
|
| 197 |
print(f"Error from Pexels API: {response.status_code}")
|
| 198 |
return None, None
|
| 199 |
|