diff --git a/fastAPI_tarot.py b/fastAPI_tarot.py index 3ac180e..da7d319 100644 --- a/fastAPI_tarot.py +++ b/fastAPI_tarot.py @@ -70,7 +70,8 @@ HISTORY_FILE = "history.json" # Dashscope (Qwen-VL) 配置 dashscope.api_key = 'sk-ce2404f55f744a1987d5ece61c6bac58' -QWEN_MODEL = 'qwen-vl-max' +QWEN_MODEL = 'qwen-vl-max' # Default model +AVAILABLE_QWEN_MODELS = ["qwen-vl-max", "qwen-vl-plus"] # API Tags (用于文档分类) TAG_GENERAL = "General Segmentation (通用分割)" @@ -1019,7 +1020,8 @@ async def segment_face( processor=processor, image=image, prompt=final_prompt, - output_base_dir=RESULT_IMAGE_DIR + output_base_dir=RESULT_IMAGE_DIR, + qwen_model=QWEN_MODEL ) except Exception as e: import traceback @@ -1222,9 +1224,23 @@ async def get_config(request: Request): "device": device, "cleanup_enabled": os.getenv("AUTO_CLEANUP_ENABLED"), "file_lifetime": os.getenv("FILE_LIFETIME_SECONDS"), - "cleanup_interval": os.getenv("CLEANUP_INTERVAL_SECONDS") + "cleanup_interval": os.getenv("CLEANUP_INTERVAL_SECONDS"), + "current_qwen_model": QWEN_MODEL, + "available_qwen_models": AVAILABLE_QWEN_MODELS } +@app.post("/admin/api/config/model", dependencies=[Depends(verify_admin)]) +async def set_model(model: str = Form(...)): + """ + Set the Qwen model + """ + global QWEN_MODEL + if model not in AVAILABLE_QWEN_MODELS: + raise HTTPException(status_code=400, detail="Invalid model") + + QWEN_MODEL = model + return {"status": "success", "message": f"Model switched to {model}", "current_model": QWEN_MODEL} + # ========================================== # 10. Main Entry Point (启动入口) # ========================================== diff --git a/human_analysis_service.py b/human_analysis_service.py index d61e537..925252f 100644 --- a/human_analysis_service.py +++ b/human_analysis_service.py @@ -95,7 +95,7 @@ def create_highlighted_visualization(image: Image.Image, masks, output_path: str # Save Image.fromarray(result_np).save(output_path) -def analyze_demographics_with_qwen(image_path: str) -> dict: +def analyze_demographics_with_qwen(image_path: str, model_name: str = 'qwen-vl-max') -> dict: """ 调用 Qwen-VL 模型分析人物的年龄和性别 """ @@ -122,7 +122,7 @@ def analyze_demographics_with_qwen(image_path: str) -> dict: ] # 调用模型 - response = MultiModalConversation.call(model=QWEN_MODEL, messages=messages) + response = MultiModalConversation.call(model=model_name, messages=messages) if response.status_code == 200: content = response.output.choices[0].message.content[0]['text'] @@ -143,7 +143,8 @@ def process_face_segmentation_and_analysis( processor, image: Image.Image, prompt: str = "head", - output_base_dir: str = "static/results" + output_base_dir: str = "static/results", + qwen_model: str = "qwen-vl-max" ) -> dict: """ 核心处理逻辑: @@ -208,7 +209,7 @@ def process_face_segmentation_and_analysis( cropped_img.save(save_path) # 3. 识别 - analysis = analyze_demographics_with_qwen(save_path) + analysis = analyze_demographics_with_qwen(save_path, model_name=qwen_model) # 构造返回结果 # 注意:URL 生成需要依赖外部的 request context,这里只返回相对路径或文件名 diff --git a/static/admin.html b/static/admin.html index 8048226..cfcca57 100644 --- a/static/admin.html +++ b/static/admin.html @@ -200,9 +200,15 @@ 模型 SAM3 -