本项目使用了开源模型,通过 FastApi 提供了一个地址标准化接口
使用了模型MGeo门址地址结构化要素解析-中文-地址领域-base,然后本地化部署了fastapi 服务
from fastapi import FastAPI
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
from pydantic import BaseModel
import pandas as pd
class Item(BaseModel):
address_row: str
task = Tasks.token_classification
model = "iic/mgeo_geographic_elements_tagging_chinese_base"
# Initialize the pipeline with the specified task and model
pipeline_ins = pipeline(task=task, model=model, model_revision="master")
app = FastAPI()
# Example endpoint
@app.post("/api/address_standardization")
async def hello(item: Item):
inputs = item.address_row
res = pipeline_ins(input=inputs)
print(res)
df = pd.DataFrame(res.get("output", []))
print(df)
# For now, we just return a placeholder response
return { row['type']: row['span'] for index, row in df.iterrows()}
if __name__ == "__main__":
# test run model
print("Testing model run 浙江省杭州市余杭区五常街道文一西路969号淘宝城5号楼,放前台")
res = pipeline_ins(input="浙江省杭州市余杭区五常街道文一西路969号淘宝城5号楼,放前台")
print(res)docker build . -t address_modeldocker compose up -d
