Skip to content

Commit 50de0a1

Browse files
authored
fix config hot update
fix config hot update
2 parents 8a65cc1 + 7fa21df commit 50de0a1

File tree

4 files changed

+94
-55
lines changed

4 files changed

+94
-55
lines changed

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM dataelement/bisheng-unstructured-runtime:0.0.1
2-
MAINTAINER "Dataelem inc."
2+
LABEL org.opencontainers.image.authors="Dataelem inc."
33

44
ARG BISHENG_UNS_VER=0.0.2
55

src/bisheng_unstructured/api/main.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import tempfile
55

66
import requests
7-
from fastapi import Depends, FastAPI, Header, HTTPException, Request, status
7+
from fastapi import FastAPI, HTTPException, Request
88
from fastapi.middleware.cors import CORSMiddleware
99
from fastapi.responses import ORJSONResponse
1010

@@ -15,7 +15,6 @@
1515

1616
logger = get_logger("BishengUns", "/app/log/bisheng-uns.log")
1717

18-
1918
# Fastapi App
2019

2120

@@ -71,6 +70,8 @@ async def update_config(inp: ConfigInput):
7170
}
7271

7372
if inp.rt_ep is not None:
73+
# update environment
74+
os.environ['rt_server'] = inp.rt_ep
7475
pdf_model_params = {}
7576
for k, v in pdf_model_params_temp.items():
7677
pdf_model_params[k] = v.format(inp.rt_ep)
@@ -79,6 +80,10 @@ async def update_config(inp: ConfigInput):
7980
else:
8081
config_dict = inp.dict()
8182

83+
# update persist data
84+
with open(config_file, 'wb') as file:
85+
file.write(json.loads(config_dict))
86+
8287
pipeline.update_config(config_dict)
8388
return {"status": "OK"}
8489

@@ -90,6 +95,7 @@ async def config():
9095

9196
@app.post("/v1/etl4llm/predict", response_model=UnstructuredOutput)
9297
async def etl4_llm(inp: UnstructuredInput):
98+
9399
filename = inp.filename
94100
b64_data = inp.b64_data
95101
file_type = filename.rsplit(".", 1)[1].lower()

src/bisheng_unstructured/api/pipeline.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import Dict
2+
import os
33

44
from bisheng_unstructured.common import get_logger
55
from bisheng_unstructured.documents.html_utils import save_to_txt, visualize_html
@@ -57,8 +57,22 @@ def partition_image(filename, model_params, **kwargs):
5757

5858

5959
class Pipeline(object):
60+
6061
def __init__(self, config_file: str):
61-
self.config = json.load(open(config_file))
62+
''' k8s 使用cm 创建环境变量'''
63+
tmp_dict = json.load(open(config_file))
64+
rt_ep = os.getenv("rt_server")
65+
if rt_ep:
66+
pdf_model_params_temp = {
67+
"layout_ep": f"http://{rt_ep}/v2.1/models/elem_layout_v1/infer",
68+
"cell_model_ep": f"http://{rt_ep}/v2.1/models/elem_table_cell_detect_v1/infer",
69+
"rowcol_model_ep": f"http://{rt_ep}/v2.1/models/elem_table_rowcol_detect_v1/infer",
70+
"table_model_ep": f"http://{rt_ep}/v2.1/models/elem_table_detect_v1/infer",
71+
"ocr_model_ep": f"http://{rt_ep}/v2.1/models/elem_ocr_collection_v3/infer",
72+
}
73+
self.config = {"pdf_model_params": pdf_model_params_temp}
74+
else:
75+
self.config = tmp_dict
6276
self.pdf_model_params = self.config.get("pdf_model_params")
6377
topdf_model_params = self.config.get("topdf_model_params", {})
6478
self.pdf_creator = Any2PdfCreator(topdf_model_params)

0 commit comments

Comments
 (0)