Spaces:
Runtime error
Runtime error
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -47,19 +47,15 @@ def split_story_to_pages(story_text):
|
|
| 47 |
return eval(story_data)
|
| 48 |
|
| 49 |
def generate_image(prompt):
|
| 50 |
-
|
| 51 |
-
"Authorization": f"Bearer {LEONARDO_API_KEY}",
|
| 52 |
-
"Content-Type": "application/json"
|
| 53 |
-
}
|
| 54 |
-
data = {
|
| 55 |
-
"prompt": prompt,
|
| 56 |
-
"num_images": 1,
|
| 57 |
-
"modelId": "REPLACE_WITH_MODEL_ID"
|
| 58 |
-
}
|
| 59 |
|
| 60 |
response = requests.post(
|
| 61 |
-
"https://
|
| 62 |
-
|
| 63 |
-
|
| 64 |
)
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
return eval(story_data)
|
| 48 |
|
| 49 |
def generate_image(prompt):
|
| 50 |
+
api_key = os.getenv("DEEPAI_API_KEY")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
response = requests.post(
|
| 53 |
+
"https://api.deepai.org/api/text2img",
|
| 54 |
+
data={'text': prompt},
|
| 55 |
+
headers={'api-key': api_key}
|
| 56 |
)
|
| 57 |
+
|
| 58 |
+
if response.status_code == 200:
|
| 59 |
+
return response.json().get('output_url')
|
| 60 |
+
else:
|
| 61 |
+
return "https://via.placeholder.com/512?text=Image+Error"
|