Spaces:
Running
Running
Upload 3 files
Browse files- requirements.txt +2 -1
- 数据库连接.py +21 -1
requirements.txt
CHANGED
|
@@ -2,4 +2,5 @@ fastapi
|
|
| 2 |
uvicorn
|
| 3 |
pydantic
|
| 4 |
huggingface_hub
|
| 5 |
-
datasets
|
|
|
|
|
|
| 2 |
uvicorn
|
| 3 |
pydantic
|
| 4 |
huggingface_hub
|
| 5 |
+
datasets
|
| 6 |
+
python-multipart
|
数据库连接.py
CHANGED
|
@@ -54,4 +54,24 @@ def save_data(file_name: str, data):
|
|
| 54 |
commit_message=f"Auto-update {file_name}"
|
| 55 |
)
|
| 56 |
except Exception as e:
|
| 57 |
-
print(f"同步到 HF Dataset 失败: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
commit_message=f"Auto-update {file_name}"
|
| 55 |
)
|
| 56 |
except Exception as e:
|
| 57 |
+
print(f"同步到 HF Dataset 失败: {e}")
|
| 58 |
+
|
| 59 |
+
# --- 【新增】:保存真实的二进制文件 ---
|
| 60 |
+
def save_file(file_path_in_repo: str, content: bytes):
|
| 61 |
+
local_full_path = os.path.join(LOCAL_DB_DIR, file_path_in_repo)
|
| 62 |
+
|
| 63 |
+
# 自动创建子目录(如 avatars/, tools/)
|
| 64 |
+
os.makedirs(os.path.dirname(local_full_path), exist_ok=True)
|
| 65 |
+
|
| 66 |
+
with open(local_full_path, "wb") as f:
|
| 67 |
+
f.write(content)
|
| 68 |
+
|
| 69 |
+
if HF_TOKEN:
|
| 70 |
+
try:
|
| 71 |
+
api.upload_file(
|
| 72 |
+
path_or_fileobj=local_full_path, path_in_repo=file_path_in_repo,
|
| 73 |
+
repo_id=DATASET_REPO_ID, repo_type="dataset",
|
| 74 |
+
token=HF_TOKEN, commit_message=f"Upload File: {file_path_in_repo}"
|
| 75 |
+
)
|
| 76 |
+
except Exception as e:
|
| 77 |
+
print(f"同步文件到 HF Dataset 失败: {e}")
|