增加了NSFW阈值配置

This commit is contained in:
梦凌汐 2025-06-05 11:55:19 +08:00
parent 92dc523cd1
commit 84d9b7f157
3 changed files with 4 additions and 2 deletions

View File

@ -47,6 +47,7 @@ CatismImage 是一个基于Web的图片存储和管理系统提供用户友
# NSFW过滤配置(目前支持NSFWPY) # NSFW过滤配置(目前支持NSFWPY)
ENABLE_NSFW_FILTER=true/false ENABLE_NSFW_FILTER=true/false
NSFWPY_ENDPOINT=your_nsfwpy_endpoint NSFWPY_ENDPOINT=your_nsfwpy_endpoint
NSFWPY_THRESHOLD=0.5
``` ```
6. 运行后端服务: 6. 运行后端服务:

View File

@ -18,6 +18,7 @@ class Config:
ENABLE_NSFW_FILTER = os.getenv('ENABLE_NSFW_FILTER') ENABLE_NSFW_FILTER = os.getenv('ENABLE_NSFW_FILTER')
NSFWPY_ENDPOINT = os.getenv('NSFWPY_ENDPOINT') NSFWPY_ENDPOINT = os.getenv('NSFWPY_ENDPOINT')
NSFWPY_THRESHOLD = os.getenv('NSFWPY_THRESHOLD')
if(S3_ACCESS_KEY == None or S3_SECRET_KEY == None or S3_BUCKET == None or S3_ENDPOINT == None): if(S3_ACCESS_KEY == None or S3_SECRET_KEY == None or S3_BUCKET == None or S3_ENDPOINT == None):
print("错误缺少必需的S3环境变量") print("错误缺少必需的S3环境变量")

View File

@ -77,8 +77,8 @@ def upload_image():
nsfw_data = response.json() nsfw_data = response.json()
# 检查NSFW评分 # 检查NSFW评分
if nsfw_data.get('neutral', 0) + nsfw_data.get('drawing', 0) < 0.5: if nsfw_data.get('neutral', 0) + nsfw_data.get('drawing', 0) < 1 - AppConfig.NSFWPY_THRESHOLD:
return jsonify({'error': '图片内容不符合安全标准'}), 403 return jsonify({'error': '图片内容未通过NSFW检查'}), 403
file.seek(0) file.seek(0)
except Exception as e: except Exception as e: