Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,16 +10,16 @@ import json
|
|
10 |
model = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo")
|
11 |
|
12 |
# Helper function to truncate prompt to fit the model's maximum sequence length
|
13 |
-
def truncate_prompt(prompt, max_length=77):
|
14 |
-
|
15 |
|
16 |
def generate_image(text, sentence_mapping, character_dict, selected_style):
|
17 |
try:
|
18 |
prompt = generate_prompt(text, sentence_mapping, character_dict, selected_style)
|
19 |
print(f"Generated prompt: {prompt}")
|
20 |
# Truncate prompt if necessary
|
21 |
-
prompt = truncate_prompt(prompt)
|
22 |
-
print(f"truncate_prompt: {prompt}")
|
23 |
output = model(prompt=prompt, num_inference_steps=1, guidance_scale=0.0)
|
24 |
print(f"Model output: {output}")
|
25 |
print("len of output:", len(output))
|
@@ -50,8 +50,8 @@ def inference(sentence_mapping, character_dict, selected_style):
|
|
50 |
combined_sentence = " ".join(sentences)
|
51 |
futures[paragraph_number] = executor.submit(generate_image, combined_sentence, sentence_mapping, character_dict, selected_style)
|
52 |
|
53 |
-
|
54 |
-
|
55 |
|
56 |
return images
|
57 |
|
|
|
10 |
model = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo")
|
11 |
|
12 |
# Helper function to truncate prompt to fit the model's maximum sequence length
|
13 |
+
# def truncate_prompt(prompt, max_length=77):
|
14 |
+
# return prompt[:max_length]
|
15 |
|
16 |
def generate_image(text, sentence_mapping, character_dict, selected_style):
|
17 |
try:
|
18 |
prompt = generate_prompt(text, sentence_mapping, character_dict, selected_style)
|
19 |
print(f"Generated prompt: {prompt}")
|
20 |
# Truncate prompt if necessary
|
21 |
+
# prompt = truncate_prompt(prompt)
|
22 |
+
# print(f"truncate_prompt: {prompt}")
|
23 |
output = model(prompt=prompt, num_inference_steps=1, guidance_scale=0.0)
|
24 |
print(f"Model output: {output}")
|
25 |
print("len of output:", len(output))
|
|
|
50 |
combined_sentence = " ".join(sentences)
|
51 |
futures[paragraph_number] = executor.submit(generate_image, combined_sentence, sentence_mapping, character_dict, selected_style)
|
52 |
|
53 |
+
for paragraph_number, future in futures.items():
|
54 |
+
images[paragraph_number] = future.result()
|
55 |
|
56 |
return images
|
57 |
|