208 lines
5.9 KiB
Python
208 lines
5.9 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Anti-AI Detector - IT资讯系统集成模块
|
|
用于AI处理器的去AI化后处理
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
|
|
# 添加技能目录到路径
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from humanize import AntiAIDetector
|
|
|
|
|
|
class ITContentHumanizer:
|
|
"""IT资讯内容人性化处理器"""
|
|
|
|
def __init__(self):
|
|
self.detector = AntiAIDetector()
|
|
|
|
def process_translation(self, text: str, source_lang: str = 'en') -> str:
|
|
"""
|
|
处理翻译后的内容
|
|
|
|
Args:
|
|
text: AI翻译后的文本
|
|
source_lang: 源语言 ('en' 或 'zh')
|
|
|
|
Returns:
|
|
去AI化后的文本
|
|
"""
|
|
# 检测并去除AI痕迹
|
|
if source_lang == 'en':
|
|
# 英文文章翻译成中文后
|
|
result = self.detector.humanize_cn(text)
|
|
else:
|
|
# 中文文章保持中文优化
|
|
result = self.detector.humanize_cn(text)
|
|
|
|
return result
|
|
|
|
def process_summary(self, text: str, platform: str = 'default') -> str:
|
|
"""
|
|
处理总结内容
|
|
|
|
Args:
|
|
text: AI总结后的文本
|
|
platform: 目标平台 ('default', 'xiaohongshu', 'email')
|
|
|
|
Returns:
|
|
优化后的文本
|
|
"""
|
|
if platform == 'xiaohongshu':
|
|
# 小红书风格优化
|
|
result = self.detector.humanize_xhs(text)
|
|
# 再进行中文去AI化
|
|
result = self.detector.humanize_cn(result)
|
|
elif platform == 'email':
|
|
# 邮件风格 - 只去AI化
|
|
result = self.detector.humanize_cn(text)
|
|
else:
|
|
# 默认处理
|
|
result = self.detector.humanize_cn(text)
|
|
|
|
return result
|
|
|
|
def process_title(self, title: str) -> str:
|
|
"""
|
|
优化标题
|
|
|
|
Args:
|
|
title: 原标题
|
|
|
|
Returns:
|
|
优化后的标题
|
|
"""
|
|
# 去除标题中的AI痕迹
|
|
result = self.detector.humanize_cn(title)
|
|
|
|
# 去除常见的AI标题套路
|
|
result = result.replace("值得一提的是", "")
|
|
result = result.replace("不得不说", "")
|
|
result = result.replace("揭秘", "")
|
|
result = result.replace("深度解析", "")
|
|
|
|
return result.strip()
|
|
|
|
def full_pipeline(self, content: dict) -> dict:
|
|
"""
|
|
完整处理管道
|
|
|
|
Args:
|
|
content: {
|
|
'title': '原标题',
|
|
'translated': '翻译内容',
|
|
'summary': '总结内容',
|
|
'platform': 'xiaohongshu' 或 'email'
|
|
}
|
|
|
|
Returns:
|
|
处理后的内容
|
|
"""
|
|
return {
|
|
'title': self.process_title(content.get('title', '')),
|
|
'translated': self.process_translation(
|
|
content.get('translated', ''),
|
|
content.get('source_lang', 'en')
|
|
),
|
|
'summary': self.process_summary(
|
|
content.get('summary', ''),
|
|
content.get('platform', 'default')
|
|
),
|
|
}
|
|
|
|
def analyze_risk(self, text: str) -> dict:
|
|
"""
|
|
分析AI痕迹风险
|
|
|
|
Returns:
|
|
{
|
|
'risk_level': 'low'|'medium'|'high',
|
|
'score': int,
|
|
'suggestions': list
|
|
}
|
|
"""
|
|
analysis = self.detector.analyze(text)
|
|
total = analysis['total_risk']
|
|
|
|
if total < 3:
|
|
level = 'low'
|
|
elif total < 8:
|
|
level = 'medium'
|
|
else:
|
|
level = 'high'
|
|
|
|
suggestions = []
|
|
if analysis['cn_score'] > 0:
|
|
suggestions.append(f"发现 {analysis['cn_score']} 处中文AI痕迹")
|
|
if analysis['en_score'] > 0:
|
|
suggestions.append(f"发现 {analysis['en_score']} 处英文AI痕迹")
|
|
if analysis['xhs_score'] > 0:
|
|
suggestions.append(f"发现 {analysis['xhs_score']} 处小红书风格问题")
|
|
|
|
return {
|
|
'risk_level': level,
|
|
'score': total,
|
|
'suggestions': suggestions,
|
|
'details': analysis
|
|
}
|
|
|
|
|
|
# 便捷函数,供IT项目直接调用
|
|
def humanize_for_it_news(text: str, content_type: str = 'translation') -> str:
|
|
"""
|
|
IT资讯项目的便捷调用函数
|
|
|
|
Args:
|
|
text: AI生成的文本
|
|
content_type: 'translation'|'summary'|'title'
|
|
|
|
Returns:
|
|
去AI化后的文本
|
|
"""
|
|
humanizer = ITContentHumanizer()
|
|
|
|
if content_type == 'translation':
|
|
return humanizer.process_translation(text)
|
|
elif content_type == 'summary':
|
|
return humanizer.process_summary(text, platform='default')
|
|
elif content_type == 'title':
|
|
return humanizer.process_title(text)
|
|
else:
|
|
return humanizer.detector.humanize_cn(text)
|
|
|
|
|
|
# 小红书专用函数
|
|
def humanize_for_xiaohongshu(text: str) -> str:
|
|
"""
|
|
小红书内容专用去AI化
|
|
"""
|
|
humanizer = ITContentHumanizer()
|
|
return humanizer.process_summary(text, platform='xiaohongshu')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
# 测试
|
|
test_text = """
|
|
值得注意的是,这项技术非常重要。我们可以看到,随着AI的发展,
|
|
越来越多的应用场景被开发出来。首先,它提高了效率;其次,
|
|
它降低了成本;最后,它改变了工作方式。综上所述,
|
|
这项技术毫无疑问具有极其重要的意义。
|
|
"""
|
|
|
|
humanizer = ITContentHumanizer()
|
|
|
|
print("原文:")
|
|
print(test_text)
|
|
print("\n去AI化后:")
|
|
result = humanizer.process_translation(test_text)
|
|
print(result)
|
|
|
|
print("\n风险分析:")
|
|
risk = humanizer.analyze_risk(test_text)
|
|
print(f"风险等级: {risk['risk_level']}")
|
|
print(f"得分: {risk['score']}")
|
|
print("建议:", risk['suggestions'])
|