|
@@ -1,22 +1,22 @@
|
|
|
import gradio as gr
|
|
import gradio as gr
|
|
|
-from db import MongoDao
|
|
|
|
|
-import requests
|
|
|
|
|
-from PIL import Image
|
|
|
|
|
-from io import BytesIO
|
|
|
|
|
-from agent.agent import Agent
|
|
|
|
|
import json
|
|
import json
|
|
|
|
|
+import os
|
|
|
import pandas as pd
|
|
import pandas as pd
|
|
|
-from utils import Service
|
|
|
|
|
|
|
+from utils import Service, load_image_from_url
|
|
|
|
|
+
|
|
|
|
|
+# 手动设置 Gradio 临时目录
|
|
|
|
|
+os.environ["GRADIO_TEMP_DIR"] = "/home/yangzeyu/gradio_temp/brand"
|
|
|
|
|
+GRADIO_TEMP_DIR = os.environ["GRADIO_TEMP_DIR"]
|
|
|
|
|
|
|
|
brand_list = Service.get_brand_list()
|
|
brand_list = Service.get_brand_list()
|
|
|
-init_product_list = Service.get_init_state_product_list(brand_list[0])
|
|
|
|
|
|
|
+init_product_list, init_product = Service.get_init_state_product_list(brand_list[0])
|
|
|
|
|
|
|
|
with gr.Blocks() as demo:
|
|
with gr.Blocks() as demo:
|
|
|
gr.Markdown("## 侵权识别系统", elem_id="header")
|
|
gr.Markdown("## 侵权识别系统", elem_id="header")
|
|
|
-
|
|
|
|
|
|
|
+ selected_product = gr.State(value=init_product)
|
|
|
with gr.Row():
|
|
with gr.Row():
|
|
|
with gr.Column(): # 左侧控制面板
|
|
with gr.Column(): # 左侧控制面板
|
|
|
- brand_state = gr.State(value=brand_list[0])
|
|
|
|
|
|
|
+
|
|
|
brand_dropdown = gr.Dropdown(
|
|
brand_dropdown = gr.Dropdown(
|
|
|
brand_list,
|
|
brand_list,
|
|
|
label="品牌选择",
|
|
label="品牌选择",
|
|
@@ -25,7 +25,7 @@ with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
product_dropdown = gr.Dropdown(
|
|
product_dropdown = gr.Dropdown(
|
|
|
init_product_list,
|
|
init_product_list,
|
|
|
- value=init_product_list[0],
|
|
|
|
|
|
|
+ value=init_product.title,
|
|
|
label="商品列表",
|
|
label="商品列表",
|
|
|
interactive=True
|
|
interactive=True
|
|
|
)
|
|
)
|
|
@@ -38,45 +38,48 @@ with gr.Blocks() as demo:
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
with gr.Column(): # 右侧展示面板
|
|
with gr.Column(): # 右侧展示面板
|
|
|
- # 1. 图片展示区(顶部)
|
|
|
|
|
- image_display = gr.Gallery(
|
|
|
|
|
- label="商品图片",
|
|
|
|
|
- columns=3, # 每行显示3张图片
|
|
|
|
|
- height="auto",
|
|
|
|
|
- object_fit="contain", # 保持图片比例
|
|
|
|
|
- interactive=False,
|
|
|
|
|
- show_share_button=False
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- # # 2. 商品信息区(中部)
|
|
|
|
|
- # product_info = gr.Textbox(
|
|
|
|
|
- # label="商品信息",
|
|
|
|
|
- # interactive=False,
|
|
|
|
|
- # lines=5 # 增加显示行数
|
|
|
|
|
- # )
|
|
|
|
|
product_info = gr.Dataframe(
|
|
product_info = gr.Dataframe(
|
|
|
headers=["", ""],
|
|
headers=["", ""],
|
|
|
row_count=5,
|
|
row_count=5,
|
|
|
col_count=2,
|
|
col_count=2,
|
|
|
value=[
|
|
value=[
|
|
|
- ["商户名称", "某某专卖店"],
|
|
|
|
|
- ["商品ID", "SP20230001"],
|
|
|
|
|
- ["上架时间", "2023-05-15"],
|
|
|
|
|
- ["价格", "¥299"],
|
|
|
|
|
- ["销量", "1,208件"]
|
|
|
|
|
|
|
+ ["商品链接", init_product.url],
|
|
|
|
|
+ ["平台", init_product.platFormName],
|
|
|
|
|
+ ["商户名称", init_product.shopTitle],
|
|
|
|
|
+ ["颜色", init_product.colors],
|
|
|
|
|
+ ["尺寸", init_product.sizes],
|
|
|
|
|
+ ["价格", init_product.price],
|
|
|
],
|
|
],
|
|
|
interactive=False # 设为True可允许编辑
|
|
interactive=False # 设为True可允许编辑
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ image_display = gr.Gallery(
|
|
|
|
|
+ label="商品图片",
|
|
|
|
|
+ columns=2, # 每行显示2张图片
|
|
|
|
|
+ height="auto",
|
|
|
|
|
+ object_fit="contain", # 保持图片比例
|
|
|
|
|
+ value=[load_image_from_url(image_url) for image_url in init_product.images],
|
|
|
|
|
+ interactive=False,
|
|
|
|
|
+ show_share_button=False
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
- # 事件绑定(保持不变)
|
|
|
|
|
|
|
+ # 事件绑定
|
|
|
brand_dropdown.change(
|
|
brand_dropdown.change(
|
|
|
fn=Service.on_brand_change,
|
|
fn=Service.on_brand_change,
|
|
|
inputs=brand_dropdown,
|
|
inputs=brand_dropdown,
|
|
|
outputs=product_dropdown
|
|
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)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ product_dropdown.change(
|
|
|
|
|
+ fn=Service.on_product_change,
|
|
|
|
|
+ inputs=[product_dropdown, brand_dropdown],
|
|
|
|
|
+ outputs=[image_display, product_info, selected_product]
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ check_button.click(
|
|
|
|
|
+ Service.infringement_judgement,
|
|
|
|
|
+ inputs=[brand_dropdown, selected_product],
|
|
|
|
|
+ outputs=infringement_result
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
demo.launch(server_name="0.0.0.0", server_port=7860)
|