detect floorplan using asyncio
This commit is contained in:
parent
68cc70bd11
commit
b1e0ed170b
3 changed files with 22 additions and 9 deletions
|
|
@ -1,15 +1,25 @@
|
|||
import asyncio
|
||||
import pathlib
|
||||
from data_access import Listing
|
||||
from tqdm import tqdm
|
||||
from tqdm.asyncio import tqdm
|
||||
import multiprocessing
|
||||
|
||||
|
||||
def detect_floorplan(listing_paths: list[str]):
|
||||
async def detect_floorplan(listing_paths: list[str]):
|
||||
listings = Listing.get_all_listings(listing_paths)
|
||||
cpu_count = multiprocessing.cpu_count() / 4
|
||||
semaphore = asyncio.Semaphore(cpu_count)
|
||||
|
||||
for listing in tqdm(listings):
|
||||
tqdm.write(str(listing.identifier))
|
||||
# listing.calculate_sqm_model() # using google/deplot model. Too slow, rather use tesseract
|
||||
listing.calculate_sqm_ocr(recalculate=False)
|
||||
await tqdm.gather(
|
||||
*[_detect_floorplan_with_semaphore(listing, semaphore) for listing in listings]
|
||||
)
|
||||
|
||||
|
||||
async def _detect_floorplan_with_semaphore(
|
||||
listing: Listing, semaphore: asyncio.Semaphore
|
||||
):
|
||||
async with semaphore:
|
||||
return await listing.calculate_sqm_ocr(recalculate=False)
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue