api.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from fastapi import FastAPI, Request, status, BackgroundTasks, HTTPException
  2. import json
  3. from pydantic import BaseModel
  4. from utils import Service
  5. import uvicorn
  6. app = FastAPI()
  7. # 定义请求体
  8. class KeyWordRequest(BaseModel):
  9. brand_name: str # 判定品牌名称
  10. shop_detail_info_brand_name: str # 商品详情页的品牌名称
  11. title: str # 商品名称
  12. class LicenseRequest(BaseModel):
  13. brand_name: str # 判定品牌名称
  14. title: str # 商品名称
  15. class LogoRequest(BaseModel):
  16. brand_name: str # 判定品牌名称
  17. image_url: str # 图片链接
  18. @app.post("/brandanalysis/api/v1/keyword")
  19. async def brand_key_word_judgement(request: KeyWordRequest):
  20. """关键词引流判定api"""
  21. if request.shop_detail_info_brand_name not in request.title:
  22. title = request.shop_detail_info_brand_name + request.title
  23. else:
  24. title = request.title
  25. judgement_res = Service.agent.brand_key_word_judgement(request.brand_name, title)
  26. result = json.loads(judgement_res)
  27. return {"code": 200, "message": "success", "data": {"judgement_info": result}}
  28. @app.post("/brandanalysis/api/v1/license")
  29. async def license_judgement(request: LicenseRequest):
  30. license_list = Service.get_license_list(request.brand_name)
  31. license_judgement = json.loads(Service.agent.license_product_judgement(request.title, license_list))
  32. return {"code": 200, "message": "success", "data": {"judgement_info": license_judgement}}
  33. @app.post("/brandanalysis/api/v1/logo")
  34. async def logo_judgement(request: LogoRequest):
  35. logo_path_map = {
  36. "李宁": "./logo/lining.jpg"
  37. }
  38. logo_path = logo_path_map[request.brand_name]
  39. logo_judgement_res = json.loads(Service.agent.image_logo_judgement(logo_path, request.image_url))
  40. return {"code": 200, "message": "success", "data": {"judgement_info": logo_judgement_res}}
  41. if __name__ == "__main__":
  42. uvicorn.run(app, host="0.0.0.0", port=7860)