pseudotheos
commited on
Commit
·
50ea979
1
Parent(s):
131d087
Update app.py
Browse files
app.py
CHANGED
@@ -274,10 +274,10 @@ async def generate_image(
|
|
274 |
image: UploadFile = File(...),
|
275 |
background_tasks: BackgroundTasks = BackgroundTasks()
|
276 |
):
|
277 |
-
async def generate_image_task():
|
278 |
try:
|
279 |
# Save the uploaded image to a temporary file
|
280 |
-
temp_image_path = f"/tmp/{
|
281 |
with open(temp_image_path, "wb") as temp_image:
|
282 |
temp_image.write(image.file.read())
|
283 |
|
@@ -302,8 +302,8 @@ async def generate_image(
|
|
302 |
return "Failed to generate image"
|
303 |
|
304 |
try:
|
305 |
-
|
306 |
-
|
307 |
# Total queue size is still async
|
308 |
total_queue_size = await queue_manager.get_total_queue_size() # Implement this function
|
309 |
|
|
|
274 |
image: UploadFile = File(...),
|
275 |
background_tasks: BackgroundTasks = BackgroundTasks()
|
276 |
):
|
277 |
+
async def generate_image_task(position_in_queue):
|
278 |
try:
|
279 |
# Save the uploaded image to a temporary file
|
280 |
+
temp_image_path = f"/tmp/{position_in_queue}_{image.filename}"
|
281 |
with open(temp_image_path, "wb") as temp_image:
|
282 |
temp_image.write(image.file.read())
|
283 |
|
|
|
302 |
return "Failed to generate image"
|
303 |
|
304 |
try:
|
305 |
+
position_in_queue = queue_manager.queue.qsize() + 1
|
306 |
+
queue_manager.add_task(lambda _: generate_image_task(position_in_queue))
|
307 |
# Total queue size is still async
|
308 |
total_queue_size = await queue_manager.get_total_queue_size() # Implement this function
|
309 |
|