Procházet zdrojové kódy

获取授权列表

Sherlock1011 před 1 rokem
rodič
revize
1710c94c44
3 změnil soubory, kde provedl 30 přidání a 15 odebrání
  1. 4 0
      agent/agent.py
  2. 1 11
      db/dao/dao.py
  3. 25 4
      webui.py

+ 4 - 0
agent/agent.py

@@ -14,6 +14,7 @@ class Agent:
             self._initialized = True
             
     def brand_key_word_judgement(self, brandname, title):
+        """判断是否为关键词引流"""
         self.glm.set_modelname("glm-4-plus")
         prompt = KeyWordPrompt.EXTRACT_INFO_FROM_TITLE + f"""
             请根据上述逻辑,分析以下商品标题,并输出结果:
@@ -22,6 +23,9 @@ class Agent:
             
         response = self.glm.text_response(prompt)
         return response.content
+    
+    def license_product_judgement(self, brandname, title):
+        pass
 
 if __name__ == "__main__":
     agent = Agent()

+ 1 - 11
db/dao/dao.py

@@ -1,18 +1,9 @@
 from db import MongoClientHelper
 
 class MongoDao:
-    _instance = None
-    
-    def __new__(cls, collection_name):
-        if not cls._instance:
-            cls._instance = super(MongoDao, cls).__new__(cls)
-            cls._instance._initialized = False
-        return cls._instance
     
     def __init__(self, collection_name):
-        if not self._initialized:
-            self.db_client = MongoClientHelper()
-            self._initialized = True
+        self.db_client = MongoClientHelper()
         self.collection_name = collection_name
             
     def get_one_record_by_query(self, query):
@@ -38,7 +29,6 @@ class MongoDao:
         records = self.db_client.find_all(self.collection_name)
         return [record for record in records]
 
-        
 
 if __name__ == '__main__':
     collection_name = "obrand-ec"

+ 25 - 4
webui.py

@@ -14,11 +14,12 @@ headers = {
     "Accept-Language": "en-US,en;q=0.9",
 }
 
-dao = MongoDao("vbrand-ec")
+products_dao = MongoDao("vbrand-ec")
+license_dao = MongoDao("ProductStandard")
 
 def get_merchant_list():
     """ 返回商户列表,显示 title,存储 outId """
-    merchant_data = [item["title"] for item in dao.get_fields_data(["title"])]
+    merchant_data = [item["title"] for item in products_dao.get_fields_data(["title"])]
     # merchant_dict = {m["title"]: m["outId"] for m in merchant_data}
     return merchant_data
 
@@ -37,7 +38,7 @@ def load_image(image_url):
     return image
 
 def get_cust_info(title):
-    record = dao.get_one_record_by_query({"title": title})
+    record = products_dao.get_one_record_by_query({"title": title})
     if record == None:
         return "title不正确", None
     res = f"""
@@ -51,10 +52,28 @@ def get_cust_info(title):
     image = load_image(image_url)
     return res, image
 
+def get_license_list():
+    """获取品牌方授权商品列表"""
+    license_list = []
+    records = license_dao.get_records_by_query({"BrandName":"李宁"})
+    for record in records:
+        if "ProductSeries" not in record.keys():
+            record["ProductSeries"] = "无"
+        license_list.append(
+            {
+                "产品名称":record["ProductTitle"],
+                "产品分类":record["Category"],
+                "产品分类":record["ProductSeries"]
+            }
+        )
+    
+    return license_list
+    
+
 def check_infringement(title, brandname):
     """ 模拟侵权检测逻辑 """
     if brandname not in title:
-        record = dao.get_one_record_by_query({"title": title})
+        record = products_dao.get_one_record_by_query({"title": title})
         actual_brandname = record["brandName"]
         if actual_brandname not in brandname:
             key_word_falg = True
@@ -83,6 +102,8 @@ merchant_list_titles = get_merchant_list()
 default_merchant = merchant_list_titles[0] if merchant_list_titles else None
 default_cust_info, default_image = get_cust_info(default_merchant)
 
+license_list = get_license_list()
+# print(license_list)
 with gr.Blocks() as demo:
     gr.Markdown("## 侵权识别系统", elem_id="header")