diff --git a/chunk_text.py b/chunk_text.py index 4f06be1..9a8c9cb 100644 --- a/chunk_text.py +++ b/chunk_text.py @@ -16,25 +16,10 @@ import threading import aiofiles import httpx import logging -from config import SHIP_MODEL_NAME +from config import SHIP_MODEL_NAME,API_URLS logger = logging.getLogger(__name__) -API_URLS = [ - "http://192.168.1.108:9988/analyze-pdf", - # "http://192.168.0.111:9977/analyze-pdf", - # "http://192.168.0.111:9978/analyze-pdf", - #"http://192.168.0.111:9979/analyze-pdf", - #"http://192.168.0.111:9980/analyze-pdf", - # "http://192.168.0.111:9975/analyze-pdf", -] -API_other_URLS = [ - "http://192.168.1.108:59988/analyze-otherfile", - # "http://192.168.0.111:9977/analyze-otherfile", - # "http://192.168.0.111:9978/analyze-otherfile", - #"http://192.168.0.111:9979/analyze-otherfile", - #"http://192.168.0.111:9980/analyze-otherfile", - # "http://192.168.0.111:9975/analyze-otherfile", -] + _api_url_inflight = [0] * len(API_URLS) _api_url_lock = threading.Lock() @@ -75,7 +60,7 @@ def get_api_url(task_id: str = "") -> tuple: idx = _api_url_inflight.index(min(_api_url_inflight)) _api_url_inflight[idx] += 1 base = API_URLS[idx] - return base, base.replace("/analyze-pdf", "/analyze-otherfile") + return base def release_api_url(url: str): @@ -1040,7 +1025,7 @@ async def process_pdf_file(pdf_path: Path, image_prefix: str,filename:str) -> Op slices_check = merge_short_slices(slices_check, min_length=30,filename=filename) return {"slices": slices_check, "images": images} - api_url, _ = get_api_url() + api_url = get_api_url() try: async with aiofiles.open(pdf_path, "rb") as f: file_content = await f.read() @@ -1086,7 +1071,7 @@ async def process_other_file(pdf_path: Path, image_prefix: str, filename: str) - slices_check = chunk_check(slices, 8000) return {"slices": slices_check, "images": images} - api_url, _ = get_api_url() + api_url = get_api_url() analyze_other_url = api_url.replace("/analyze-pdf", "/analyze-otherfile") mime_type, _ = mimetypes.guess_type(pdf_path.name) @@ -1126,6 +1111,7 @@ async def process_other_file(pdf_path: Path, image_prefix: str, filename: str) - return None finally: release_api_url(api_url) + if __name__ == "__main__": filepath = r"E:\ZKYNLP\Hjunproject\project0506\kgrag\122-06A0014-B01001_发动机-维修手册_content_list.json"