Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,19 +11,19 @@ model = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo")
|
|
11 |
|
12 |
def generate_image(prompt):
|
13 |
try:
|
14 |
-
#
|
15 |
output = model(prompt=prompt, num_inference_steps=1, guidance_scale=0.0)
|
16 |
print(f"Model output: {output}")
|
17 |
|
18 |
-
#
|
19 |
-
if output:
|
20 |
-
image = output[0]
|
21 |
buffered = BytesIO()
|
22 |
image.save(buffered, format="JPEG")
|
23 |
image_bytes = buffered.getvalue()
|
24 |
return image_bytes
|
25 |
else:
|
26 |
-
raise Exception("No
|
27 |
|
28 |
except Exception as e:
|
29 |
print(f"Error generating image: {e}")
|
@@ -37,7 +37,7 @@ def inference(sentence_mapping, character_dict, selected_style):
|
|
37 |
# Generate prompts for each paragraph
|
38 |
for paragraph_number, sentences in sentence_mapping.items():
|
39 |
combined_sentence = " ".join(sentences)
|
40 |
-
prompt= generate_prompt(combined_sentence, sentence_mapping, character_dict, selected_style)
|
41 |
prompts.append((paragraph_number, prompt))
|
42 |
print(f"Generated prompt for paragraph {paragraph_number}: {prompt}")
|
43 |
|
|
|
11 |
|
12 |
def generate_image(prompt):
|
13 |
try:
|
14 |
+
# Truncate prompt if necessary
|
15 |
output = model(prompt=prompt, num_inference_steps=1, guidance_scale=0.0)
|
16 |
print(f"Model output: {output}")
|
17 |
|
18 |
+
# Check if the model returned images
|
19 |
+
if isinstance(output.images, list) and len(output.images) > 0:
|
20 |
+
image = output.images[0]
|
21 |
buffered = BytesIO()
|
22 |
image.save(buffered, format="JPEG")
|
23 |
image_bytes = buffered.getvalue()
|
24 |
return image_bytes
|
25 |
else:
|
26 |
+
raise Exception("No images returned by the model.")
|
27 |
|
28 |
except Exception as e:
|
29 |
print(f"Error generating image: {e}")
|
|
|
37 |
# Generate prompts for each paragraph
|
38 |
for paragraph_number, sentences in sentence_mapping.items():
|
39 |
combined_sentence = " ".join(sentences)
|
40 |
+
prompt = generate_prompt(combined_sentence, sentence_mapping, character_dict, selected_style)
|
41 |
prompts.append((paragraph_number, prompt))
|
42 |
print(f"Generated prompt for paragraph {paragraph_number}: {prompt}")
|
43 |
|