13.01.26
This commit is contained in:
29
app.py
29
app.py
@@ -832,9 +832,29 @@ def detect_template(text):
|
||||
async def metadata(text: str = Body(..., embed=True)):
|
||||
return extract_report_metadata(text)
|
||||
|
||||
import httpx
|
||||
from io import BytesIO
|
||||
|
||||
async def call_extractor(text: str, lab: str = "AHK"):
|
||||
url = "http://62.72.36.116:8090/extract"
|
||||
params = {"lab": lab}
|
||||
|
||||
fake_file = BytesIO(text.encode("utf-8"))
|
||||
|
||||
files = {
|
||||
"file": ("document.txt", fake_file, "text/plain")
|
||||
}
|
||||
|
||||
async with httpx.AsyncClient(timeout=60) as client:
|
||||
r = await client.post(url, params=params, files=files)
|
||||
r.raise_for_status()
|
||||
return r.json()
|
||||
|
||||
@app.post("/parse")
|
||||
async def parse_endpoint(text: str = Body(..., embed=True)):
|
||||
return parse_report(text)
|
||||
lab = parse_report(text)
|
||||
result = await call_extractor(text, lab=lab)
|
||||
return result
|
||||
|
||||
PARSERS = {
|
||||
"AHK": AHKParser(),
|
||||
@@ -862,6 +882,7 @@ def empty_weight_report(lab):
|
||||
|
||||
def parse_report(text):
|
||||
template=detect_template(text)
|
||||
if template not in PARSERS:
|
||||
return {"template":"UNKNOWN"}
|
||||
return PARSERS[template].parse(text)
|
||||
# if template not in PARSERS:
|
||||
# return {"template":"UNKNOWN"}
|
||||
# return PARSERS[template].parse(text)
|
||||
return template
|
||||
Reference in New Issue
Block a user