sun-pc-linux 1 сар өмнө
parent
commit
f126f88d50

+ 2 - 8
imgsearchimg/api/Dockerfile

@@ -1,13 +1,6 @@
-# 使用Python 3.11.11作为基础镜像
 FROM python:3.11.11-slim
-# FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/wallies/python-cuda:3.11-cuda11.8-runtime
-# FROM registry.cn-hangzhou.aliyuncs.com/serverless_devs/pytorch:22.12-py3
 
 RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
-# RUN sed -i 's|http://archive.ubuntu.com/ubuntu|http://mirrors.aliyun.com/ubuntu|g' /etc/apt/sources.list && \
-#     sed -i 's|http://security.ubuntu.com/ubuntu|http://mirrors.aliyun.com/ubuntu|g' /etc/apt/sources.list
-# 设置环境变量,避免交互式安装时的提示
-
 
 # 设置工作目录
 WORKDIR /app
@@ -26,7 +19,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
 # 复制项目文件
 COPY . .
 
-ENV MONGODB=mongodb://root:root@172.31.69.25:37018/
+# ENV MONGODB=mongodb://root:root@172.31.69.25:37018/
+# ENV ALIYUN_FUNCTION_URL=https://imagefeature-hauveswkcf.cn-hangzhou.fcapp.run
 
 # 安装Python依赖
 RUN pip install --no-cache-dir -r requirements.txt

+ 6 - 8
imgsearchimg/api/app.py

@@ -53,13 +53,13 @@ def search():
         data = request.get_json()
         if not data:
             return jsonify({'error': '请求必须包含JSON数据'}), 400
-        
         image_url = data.get('url')
         if not image_url:
             return jsonify({'error': '缺少url参数'}), 400
         if not isinstance(image_url, str) or not (image_url.startswith('http://') or image_url.startswith('https://')):
             return jsonify({'error': '无效的图片URL'}), 400
             
+        print(f"search payload, type:{type(data)}, data: {data}")
         # 获取可选参数
         limit = data.get('limit', config.TOP_K)
         min_score = data.get('min_score', config.MIN_SCORE)
@@ -73,17 +73,15 @@ def search():
             
             if limit <= 0:
                 return jsonify({'error': 'limit必须大于0'}), 400
-            if min_score < 0 or min_score > 100:
-                return jsonify({'error': 'min_score必须在0到100之间'}), 400
-            if max_score < 0 or max_score > 100:
-                return jsonify({'error': 'max_score必须在0到100之间'}), 400
+            if min_score < 0 or min_score > 1.0:
+                return jsonify({'error': 'min_score必须在0到1之间'}), 400
+            if max_score < 0 or max_score > 1.0:
+                return jsonify({'error': 'max_score必须在0到1之间'}), 400
             if min_score > max_score:
                 return jsonify({'error': 'min_score不能大于max_score'}), 400
         except ValueError:
             return jsonify({'error': '参数类型错误'}), 400
-        
-     
-      
+        print(f"search apply limit:{limit} min_score:{min_score} max_score:{max_score}")
 
         start_search_time = time.time()
 

+ 6 - 2
imgsearchimg/api/config.py

@@ -1,7 +1,11 @@
+import os
+
+
 UPLOAD_FOLDER = 'static/images'
 ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif', 'bmp'}
-ALIYUN_FUNCTION_URL = "https://imagefeature-hauveswkcf.cn-hangzhou.fcapp.run"
+# ALIYUN_FUNCTION_URL = "https://imagefeature-hauveswkcf.cn-hangzhou.fcapp.run"
+ALIYUN_FUNCTION_URL  = os.getenv("ALIYUN_FUNCTION_URL")
 
 TOP_K = 5
 MIN_SCORE = 0.0
-MAX_SCORE = 100.0
+MAX_SCORE = 1.0

+ 2 - 2
imgsearchimg/api/image_search.py

@@ -15,6 +15,7 @@ import os
 def RequestAliyunFc(url):
     # 定义URL
     api = config.ALIYUN_FUNCTION_URL  # 替换为实际的URL
+    print("func api:",api)
     # 定义参数
     payload = {'url': url}
 
@@ -30,7 +31,6 @@ def RequestAliyunFc(url):
     if response.status_code == 200:
         # 获取返回的JSON数据
         json_data = response.json()
-        print(json_data)
         return json_data.get("vector")
     
     print(f'请求失败,状态码: {response.text}')
@@ -42,7 +42,7 @@ class ImageSearchEngine:
 
         mongodburi = os.getenv("MONGODB")
         if not mongodburi:
-            mongodburi = "mongodb://root:root@localhost:37018/"
+            mongodburi = "mongodb://root:hangzhou_manage_mat_2025@localhost:37018/"
         # 添加mongodb
         self.mongo_client = MongoClient(mongodburi)  # MongoDB 连接字符串
         self.mongo_db = self.mongo_client["faiss_index"]  # 数据库名称