Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ from huggingface_hub import HfApi
|
|
| 8 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
| 9 |
MODEL_REPO = os.environ.get("MODEL_REPO", None)
|
| 10 |
LORA_REPO = os.environ.get("LORA_REPO", None)
|
|
|
|
| 11 |
|
| 12 |
api = HfApi()
|
| 13 |
|
|
@@ -16,6 +17,9 @@ def download_and_upload(url, repo_type):
|
|
| 16 |
return "URLまたはタイプが未指定です。"
|
| 17 |
|
| 18 |
headers = {}
|
|
|
|
|
|
|
|
|
|
| 19 |
try:
|
| 20 |
response = requests.get(url, headers=headers)
|
| 21 |
response.raise_for_status()
|
|
@@ -35,7 +39,11 @@ def download_and_upload(url, repo_type):
|
|
| 35 |
with open(filename, "wb") as f:
|
| 36 |
f.write(response.content)
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
if not target_repo:
|
| 40 |
return f"{repo_type}用リポジトリが環境変数で設定されていません。"
|
| 41 |
|
|
@@ -73,7 +81,7 @@ def apply_reorder_to_repo(data, repo_type):
|
|
| 73 |
if not target_repo:
|
| 74 |
return "エラー: リポジトリが設定されていません。"
|
| 75 |
|
| 76 |
-
# 並び替えられたファイルリストをリポジトリに反映 (
|
| 77 |
reordered_files = sorted(data, key=lambda x: int(x[0])) # No.列の順序に基づいて並び替え
|
| 78 |
reordered_filenames = [file[1] for file in reordered_files]
|
| 79 |
|
|
|
|
| 8 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
| 9 |
MODEL_REPO = os.environ.get("MODEL_REPO", None)
|
| 10 |
LORA_REPO = os.environ.get("LORA_REPO", None)
|
| 11 |
+
CIVITAI_TOKEN = os.environ.get("CIVITAI_TOKEN", None) # Civitai用トークン
|
| 12 |
|
| 13 |
api = HfApi()
|
| 14 |
|
|
|
|
| 17 |
return "URLまたはタイプが未指定です。"
|
| 18 |
|
| 19 |
headers = {}
|
| 20 |
+
if CIVITAI_TOKEN:
|
| 21 |
+
headers["Authorization"] = f"Bearer {CIVITAI_TOKEN}"
|
| 22 |
+
|
| 23 |
try:
|
| 24 |
response = requests.get(url, headers=headers)
|
| 25 |
response.raise_for_status()
|
|
|
|
| 39 |
with open(filename, "wb") as f:
|
| 40 |
f.write(response.content)
|
| 41 |
|
| 42 |
+
if repo_type == "model":
|
| 43 |
+
target_repo = MODEL_REPO
|
| 44 |
+
else:
|
| 45 |
+
target_repo = LORA_REPO
|
| 46 |
+
|
| 47 |
if not target_repo:
|
| 48 |
return f"{repo_type}用リポジトリが環境変数で設定されていません。"
|
| 49 |
|
|
|
|
| 81 |
if not target_repo:
|
| 82 |
return "エラー: リポジトリが設定されていません。"
|
| 83 |
|
| 84 |
+
# 並び替えられたファイルリストをリポジトリに反映 (例としてMockで結果を出力)
|
| 85 |
reordered_files = sorted(data, key=lambda x: int(x[0])) # No.列の順序に基づいて並び替え
|
| 86 |
reordered_filenames = [file[1] for file in reordered_files]
|
| 87 |
|