Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,22 +9,21 @@ import json
|
|
9 |
# Load the model once outside of the function
|
10 |
model = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo")
|
11 |
|
12 |
-
|
13 |
def generate_image(prompt):
|
14 |
try:
|
15 |
-
#
|
16 |
-
output = model(prompt=prompt, num_inference_steps=1, guidance_scale=0.0)
|
17 |
print(f"Model output: {output}")
|
18 |
|
19 |
-
#
|
20 |
-
if output
|
21 |
-
image = output
|
22 |
buffered = BytesIO()
|
23 |
image.save(buffered, format="JPEG")
|
24 |
image_bytes = buffered.getvalue()
|
25 |
return image_bytes
|
26 |
else:
|
27 |
-
raise Exception("No
|
28 |
|
29 |
except Exception as e:
|
30 |
print(f"Error generating image: {e}")
|
@@ -38,7 +37,7 @@ def inference(sentence_mapping, character_dict, selected_style):
|
|
38 |
# Generate prompts for each paragraph
|
39 |
for paragraph_number, sentences in sentence_mapping.items():
|
40 |
combined_sentence = " ".join(sentences)
|
41 |
-
prompt = generate_prompt(combined_sentence, sentence_mapping, character_dict, selected_style)
|
42 |
prompts.append((paragraph_number, prompt))
|
43 |
print(f"Generated prompt for paragraph {paragraph_number}: {prompt}")
|
44 |
|
|
|
9 |
# Load the model once outside of the function
|
10 |
model = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo")
|
11 |
|
|
|
12 |
def generate_image(prompt):
|
13 |
try:
|
14 |
+
# Generate the image
|
15 |
+
output = model(prompt=prompt, num_inference_steps=1, guidance_scale=0.0)
|
16 |
print(f"Model output: {output}")
|
17 |
|
18 |
+
# The model returns a PIL image
|
19 |
+
if output:
|
20 |
+
image = output[0] # Extract the PIL image from the output
|
21 |
buffered = BytesIO()
|
22 |
image.save(buffered, format="JPEG")
|
23 |
image_bytes = buffered.getvalue()
|
24 |
return image_bytes
|
25 |
else:
|
26 |
+
raise Exception("No image 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 |
|