Spaces:
Running
Running
Stanislav
commited on
Commit
·
c5c4408
1
Parent(s):
09d572d
feat: await pooling
Browse files- run_fastapi.py +10 -1
run_fastapi.py
CHANGED
|
@@ -6,6 +6,7 @@ import uuid
|
|
| 6 |
import shutil
|
| 7 |
import os
|
| 8 |
import asyncio
|
|
|
|
| 9 |
|
| 10 |
from pipeline.process_session import process_session_image
|
| 11 |
from database.db import init_db
|
|
@@ -15,8 +16,15 @@ from models.dino import DinoWrapper
|
|
| 15 |
|
| 16 |
from huggingface_hub import hf_hub_download
|
| 17 |
|
|
|
|
| 18 |
process_lock = asyncio.Lock()
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
app = FastAPI()
|
| 21 |
|
| 22 |
# --- Mount static files and templates
|
|
@@ -126,7 +134,8 @@ async def process_image(request: Request, image: UploadFile = Form(...), prompt:
|
|
| 126 |
shutil.copyfileobj(image.file, buffer)
|
| 127 |
|
| 128 |
# 2. Run main pipeline
|
| 129 |
-
|
|
|
|
| 130 |
session_id=session_id,
|
| 131 |
image_path=image_path,
|
| 132 |
prompt_text=prompt,
|
|
|
|
| 6 |
import shutil
|
| 7 |
import os
|
| 8 |
import asyncio
|
| 9 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 10 |
|
| 11 |
from pipeline.process_session import process_session_image
|
| 12 |
from database.db import init_db
|
|
|
|
| 16 |
|
| 17 |
from huggingface_hub import hf_hub_download
|
| 18 |
|
| 19 |
+
|
| 20 |
process_lock = asyncio.Lock()
|
| 21 |
|
| 22 |
+
executor = ThreadPoolExecutor(max_workers=1)
|
| 23 |
+
|
| 24 |
+
async def run_in_thread(func, *args, **kwargs):
|
| 25 |
+
loop = asyncio.get_running_loop()
|
| 26 |
+
return await loop.run_in_executor(executor, lambda: func(*args, **kwargs))
|
| 27 |
+
|
| 28 |
app = FastAPI()
|
| 29 |
|
| 30 |
# --- Mount static files and templates
|
|
|
|
| 134 |
shutil.copyfileobj(image.file, buffer)
|
| 135 |
|
| 136 |
# 2. Run main pipeline
|
| 137 |
+
await run_in_thread(
|
| 138 |
+
process_session_image,
|
| 139 |
session_id=session_id,
|
| 140 |
image_path=image_path,
|
| 141 |
prompt_text=prompt,
|