Sfoglia il codice sorgente

界面功能更新

Sherlock 11 mesi fa
parent
commit
ea143dfa59
3 ha cambiato i file con 57 aggiunte e 15 eliminazioni
  1. 1 1
      data/bean/ProductInfo.py
  2. 40 4
      utils/service.py
  3. 16 10
      webui.py

+ 1 - 1
data/bean/ProductInfo.py

@@ -5,7 +5,7 @@ class ProductInfo:
         self.sizes = record.get("sizes", "null")
         self.colors = record.get("colors", "null")
         self.url = record.get("url", "null")
-        self.image = record.get("image", [])
+        self.images = record.get("image", [])
         self.price = record.get("price", "null")
         self.shopTitle = record.get("shopTitle", "null")
         self.platFormName = record.get("platFormName", "null")

+ 40 - 4
utils/service.py

@@ -1,9 +1,11 @@
 from db import MongoDao
 from data import BrandInfo, ProductInfo
+import gradio as gr
 
 product_dao = MongoDao("vbrand-ec")
 
 class Service:
+    product_map = {}
     @staticmethod
     def get_brand_list():
         """获取数据库中存储的品牌列表"""
@@ -13,12 +15,46 @@ class Service:
         return brand_list
     
     @staticmethod
-    def load_products_by_brand(brand_name):
+    def get_init_state_product_list(brand_name):
+        """获取初始状态下的产品列表"""
+        brand_info = BrandInfo(brand_name)
+        prodct_titles = [p.title for p in brand_info.product_list]
+        Service.product_map[brand_name] = brand_info.product_list
+        return prodct_titles
+    
+    @staticmethod
+    def on_brand_change(brand_name):
         """加载选定品牌的所有商品"""
         brand_info = BrandInfo(brand_name)
-        return [product.title for product in brand_info.product_list], brand_info
-
+        produt_titles = [p.title for p in brand_info.product_list]
+        Service.product_map[brand_name] = brand_info.product_list
+        return gr.update(choices=produt_titles, value=produt_titles[0])
+    
+    @staticmethod
+    def on_product_change(title, brand_name):
+        product_list = Service.product_map.get(brand_name, [])
+        product = next((p for p in product_list if p.title == title), None)
+        if not product:
+            return [], [["商品未找到", ""]]
+        
+        # 加载图片
+        images = [image_url for image_url in product.iamges]
+        
+        # 产品信息
+        info = [
+            ["商品链接", product.url],
+            ["平台", product.platFormName],
+            ["商户名称", product.shopTitle],
+            ["颜色", product.colors],
+            ["尺寸", product.sizes],
+            ["价格", product.price],
+        ]
+        
+        return images, info
+    
 
 if __name__ == "__main__":
     brand_list = Service.get_brand_list()
-    print(brand_list)
+    print(brand_list)
+    
+    

+ 16 - 10
webui.py

@@ -9,6 +9,7 @@ import pandas as pd
 from utils import Service
 
 brand_list = Service.get_brand_list()
+init_product_list = Service.get_init_state_product_list(brand_list[0])
 
 with gr.Blocks() as demo:
     gr.Markdown("## 侵权识别系统", elem_id="header")
@@ -22,9 +23,19 @@ with gr.Blocks() as demo:
                 value=brand_list[0],
                 interactive=True)
             
-            search_box = gr.Textbox(label="搜索商户")
-            search_button = gr.Button("搜索")
+            product_dropdown = gr.Dropdown(
+                init_product_list,
+                value=init_product_list[0],
+                label="商品列表",
+                interactive=True
+            )
+            
             check_button = gr.Button("查询侵权")
+            infringement_result = gr.Textbox(
+                label="侵权识别结果",
+                interactive=False,
+                lines=3
+            )
         
         with gr.Column():  # 右侧展示面板
             # 1. 图片展示区(顶部)
@@ -57,18 +68,13 @@ with gr.Blocks() as demo:
                 interactive=False  # 设为True可允许编辑
             )
             
-            # 3. 侵权结果区(底部)
-            infringement_result = gr.Textbox(
-                label="侵权识别结果",
-                interactive=False,
-                lines=3
-            )
+
     
     # 事件绑定(保持不变)
     brand_dropdown.change(
-        fn=lambda x: x,
+        fn=Service.on_brand_change,
         inputs=brand_dropdown,
-        outputs=brand_state
+        outputs=product_dropdown
     )
     # search_button.click(search_by_cust_id, inputs=search_box, outputs=[product_info, image_display])
     # check_button.click(check_infringement, inputs=[...], outputs=infringement_result)