Files
huhan3000/tools/ai-tools/scripts/image_analyzer.py
ben b6105b6770 🔥 重大突破:完整的日本阳具崇拜北魏起源论
- 🔤 文字学证据:𥘵字(示+旦)揭示祖先崇拜=生殖崇拜
- 🌋 地理学证据:大同火山→昊天寺→平城→奈良→富士山崇拜传播链
- 🏛️ 建筑学证据:应县木塔承载寇谦之静轮天宫的生殖象征
- 📜 制度学证据:北魏→日本完整政治文化传播机制

核心发现:
 四重证据相互印证的完整理论体系
 从一个汉字解开东亚文化千年之谜
 首次系统解释日本阳具崇拜历史起源
 为'胡汉三千年'理论提供核心实证支撑

学术价值:
- 创新'纯逻辑考古'研究方法论
- 建立跨学科文化传播理论
- 填补东亚文化研究重要空白
- 为中华文明世界影响提供科学证据
2025-10-16 13:48:12 +00:00

80 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""
图片分析工具 - 使用月之暗面 API 分析图片内容
"""
import base64
import os
from openai import OpenAI
def encode_image(image_path):
"""将图片编码为 base64"""
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')
def analyze_image(image_path, prompt="请详细描述这张图片的内容"):
"""分析图片内容"""
# 月之暗面配置
client = OpenAI(
api_key="sk-lEk0pAIZ1EDgUkflq2is5uT2VbhuoKGpO5sNOSnuuccsD68r",
base_url="https://api.moonshot.cn/v1"
)
# 编码图片
base64_image = encode_image(image_path)
try:
response = client.chat.completions.create(
model="moonshot-v1-8k",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": prompt},
{
"type": "image_url",
"image_url": {
"url": f"data:image/png;base64,{base64_image}"
}
}
]
}
],
max_tokens=1000
)
return response.choices[0].message.content
except Exception as e:
return f"分析失败: {e}"
def batch_analyze_images(image_dir, output_file="image_analysis.md"):
"""批量分析图片"""
results = []
# 获取所有 PNG 图片
png_files = [f for f in os.listdir(image_dir) if f.endswith('.png')]
png_files.sort() # 按文件名排序
for filename in png_files:
image_path = os.path.join(image_dir, filename)
print(f"正在分析: {filename}")
analysis = analyze_image(
image_path,
"请详细描述这张图片的内容,包括文字、图表、人物、建筑等所有可见元素"
)
results.append(f"## {filename}\n\n{analysis}\n\n---\n")
# 保存结果
with open(output_file, 'w', encoding='utf-8') as f:
f.write("# 图片分析结果\n\n")
f.writelines(results)
print(f"分析完成,结果保存到: {output_file}")
if __name__ == "__main__":
# 示例:分析序章的图片
image_dir = "images/0 序令人又敬又畏的_忽里勒台_大会"
batch_analyze_images(image_dir, "序章图片分析.md")