| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- """
- 上传预设数字人头像到OSS
- 运行: python -m scripts.upload_avatars
- """
- import os
- import sys
- from pathlib import Path
- sys.path.insert(0, str(Path(__file__).parent.parent))
- from dotenv import load_dotenv
- load_dotenv()
- from app.services.oss_service import get_oss_service
- AVATARS_DIR = Path(__file__).parent.parent.parent / "frontend" / "assets" / "avatars"
- AVATAR_FILES = [
- "职场精英-陆远.png",
- "科技达人-艾达.png",
- "亲和主持-佳莹.png",
- "青春活力-小星.png",
- ]
- def upload_avatars():
- oss_service = get_oss_service()
- results = {}
-
- for filename in AVATAR_FILES:
- filepath = AVATARS_DIR / filename
- if not filepath.exists():
- print(f"文件不存在: {filepath}")
- continue
-
- with open(filepath, "rb") as f:
- file_data = f.read()
-
- url = oss_service.upload_file(file_data, "preset-avatars", filename)
- results[filename] = url
- print(f"已上传: {filename} -> {url}")
-
- print("\n请将以下URL配置到前端代码中:")
- for filename, url in results.items():
- print(f' "{filename}": "{url}"')
- if __name__ == "__main__":
- upload_avatars()
|