Spaces:
Paused
Paused
pseudotheos
commited on
Commit
•
207e6fb
1
Parent(s):
5ce9f2c
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import socket
|
|
5 |
import requests
|
6 |
import sys
|
7 |
import logging
|
8 |
-
from fastapi import FastAPI, File, UploadFile, Form
|
9 |
from fastapi.responses import FileResponse, StreamingResponse
|
10 |
from fastapi.middleware.cors import CORSMiddleware
|
11 |
from PIL import Image
|
@@ -272,8 +272,9 @@ async def generate_image(
|
|
272 |
seed: int = Form(...),
|
273 |
sampler_type: str = Form(...),
|
274 |
image: UploadFile = File(...)
|
|
|
275 |
):
|
276 |
-
def generate_image_task():
|
277 |
try:
|
278 |
# Save the uploaded image to a temporary file
|
279 |
temp_image_path = f"/tmp/{int(time.time())}_{image.filename}"
|
@@ -301,7 +302,7 @@ async def generate_image(
|
|
301 |
return "Failed to generate image"
|
302 |
|
303 |
try:
|
304 |
-
|
305 |
position_in_queue = queue_manager.queue.qsize()
|
306 |
# Total queue size is still async
|
307 |
total_queue_size = await queue_manager.get_total_queue_size() # Implement this function
|
|
|
5 |
import requests
|
6 |
import sys
|
7 |
import logging
|
8 |
+
from fastapi import FastAPI, File, UploadFile, Form, BackgroundTasks
|
9 |
from fastapi.responses import FileResponse, StreamingResponse
|
10 |
from fastapi.middleware.cors import CORSMiddleware
|
11 |
from PIL import Image
|
|
|
272 |
seed: int = Form(...),
|
273 |
sampler_type: str = Form(...),
|
274 |
image: UploadFile = File(...)
|
275 |
+
background_tasks: 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/{int(time.time())}_{image.filename}"
|
|
|
302 |
return "Failed to generate image"
|
303 |
|
304 |
try:
|
305 |
+
background_tasks.add_task(generate_image_task)
|
306 |
position_in_queue = queue_manager.queue.qsize()
|
307 |
# Total queue size is still async
|
308 |
total_queue_size = await queue_manager.get_total_queue_size() # Implement this function
|