Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,9 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
from diffusers import
|
4 |
from io import BytesIO
|
5 |
import asyncio
|
6 |
-
from generate_propmts import generate_prompt
|
7 |
-
from concurrent.futures import ThreadPoolExecutor, as_completed
|
8 |
|
9 |
# Load the model once outside of the function
|
10 |
model = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo")
|
@@ -12,7 +11,7 @@ model = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo")
|
|
12 |
async def generate_image(prompt):
|
13 |
try:
|
14 |
# Generate an image based on the prompt
|
15 |
-
output = await asyncio.to_thread(model, prompt=prompt, num_inference_steps=
|
16 |
print(f"Model output: {output}")
|
17 |
|
18 |
# Check if the model returned images
|
@@ -49,10 +48,15 @@ async def process_prompt(sentence_mapping, character_dict, selected_style):
|
|
49 |
if i < len(results):
|
50 |
images[paragraph_number] = results[i]
|
51 |
else:
|
52 |
-
print(f"Error: No
|
53 |
|
54 |
return images
|
55 |
|
|
|
|
|
|
|
|
|
|
|
56 |
# Gradio interface with high concurrency limit
|
57 |
gradio_interface = gr.Interface(
|
58 |
fn=process_prompt,
|
@@ -62,8 +66,9 @@ gradio_interface = gr.Interface(
|
|
62 |
gr.Dropdown(["oil painting", "sketch", "watercolor"], label="Selected Style")
|
63 |
],
|
64 |
outputs="json",
|
65 |
-
|
66 |
)
|
67 |
|
68 |
if __name__ == "__main__":
|
69 |
gradio_interface.launch() # No need for share=True for local testing
|
|
|
|
1 |
+
from generate_propmts import generate_prompt
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
+
from diffusers import AutoPipelineForText2Image
|
5 |
from io import BytesIO
|
6 |
import asyncio
|
|
|
|
|
7 |
|
8 |
# Load the model once outside of the function
|
9 |
model = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo")
|
|
|
11 |
async def generate_image(prompt):
|
12 |
try:
|
13 |
# Generate an image based on the prompt
|
14 |
+
output = await asyncio.to_thread(model, prompt=prompt, num_inference_steps=1, guidance_scale=0.0)
|
15 |
print(f"Model output: {output}")
|
16 |
|
17 |
# Check if the model returned images
|
|
|
48 |
if i < len(results):
|
49 |
images[paragraph_number] = results[i]
|
50 |
else:
|
51 |
+
print(f"Error: No result for paragraph {paragraph_number}")
|
52 |
|
53 |
return images
|
54 |
|
55 |
+
# Helper function to generate a prompt based on the input
|
56 |
+
def generate_prompt(combined_sentence, sentence_mapping, character_dict, selected_style):
|
57 |
+
characters = " ".join(character_dict.values())
|
58 |
+
return f"Make an illustration in {selected_style} style from: {characters}. {combined_sentence}"
|
59 |
+
|
60 |
# Gradio interface with high concurrency limit
|
61 |
gradio_interface = gr.Interface(
|
62 |
fn=process_prompt,
|
|
|
66 |
gr.Dropdown(["oil painting", "sketch", "watercolor"], label="Selected Style")
|
67 |
],
|
68 |
outputs="json",
|
69 |
+
concurrency_limit=20 # Set a high concurrency limit
|
70 |
)
|
71 |
|
72 |
if __name__ == "__main__":
|
73 |
gradio_interface.launch() # No need for share=True for local testing
|
74 |
+
|