Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,10 @@ def run_command(command):
|
|
| 12 |
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
|
| 13 |
return True, result.stdout
|
| 14 |
except subprocess.CalledProcessError as e:
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# تابع ساخت فایل زیپ در حافظه
|
| 18 |
def create_zip_buffer(source_dir, flatten=False):
|
|
@@ -96,7 +99,6 @@ with tab1:
|
|
| 96 |
st.error(f"خطا در دانلود: {msg}")
|
| 97 |
st.stop()
|
| 98 |
else:
|
| 99 |
-
# اطمینان از دانلود کامل فایلهای LFS
|
| 100 |
run_command(f"git -C {temp_dir} lfs pull")
|
| 101 |
else:
|
| 102 |
status_area.info("📥 در حال استخراج فایل ZIP...")
|
|
@@ -122,7 +124,8 @@ with tab1:
|
|
| 122 |
shutil.rmtree(".git", ignore_errors=True)
|
| 123 |
|
| 124 |
run_command("git init")
|
| 125 |
-
run_command("git lfs install")
|
|
|
|
| 126 |
run_command("git add .")
|
| 127 |
run_command('git config user.email "bot@transfer.com"')
|
| 128 |
run_command('git config user.name "Transfer Bot"')
|
|
@@ -130,7 +133,7 @@ with tab1:
|
|
| 130 |
run_command("git branch -M main")
|
| 131 |
|
| 132 |
status_area.info("📤 در حال آپلود به گیتهاب...")
|
| 133 |
-
push_success, push_msg = run_command(
|
| 134 |
|
| 135 |
if push_success:
|
| 136 |
st.success("✅ تمام شد! فایلها دقیقاً در روت ریپازیتوری منتقل شدند.")
|
|
@@ -196,7 +199,18 @@ with tab2:
|
|
| 196 |
shutil.rmtree(temp_dir_hf, ignore_errors=True)
|
| 197 |
|
| 198 |
try:
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
# مرحله 1: آمادهسازی فایلها (دانلود یا استخراج زیپ)
|
| 202 |
if source_type_hf == "لینک ریپازیتوری (گیتهاب و غیره)":
|
|
@@ -231,7 +245,8 @@ with tab2:
|
|
| 231 |
shutil.rmtree(".git", ignore_errors=True)
|
| 232 |
|
| 233 |
run_command("git init")
|
| 234 |
-
run_command("git lfs install") # فعالسازی محلی LFS
|
|
|
|
| 235 |
run_command("git add .")
|
| 236 |
run_command('git config user.email "bot@transfer.com"')
|
| 237 |
run_command('git config user.name "Transfer Bot"')
|
|
@@ -239,14 +254,14 @@ with tab2:
|
|
| 239 |
run_command("git branch -M main")
|
| 240 |
|
| 241 |
status_area_hf.info("📤 در حال آپلود فایلها به اسپیس هاگینگفیس...")
|
| 242 |
-
push_success, push_msg = run_command(
|
| 243 |
|
| 244 |
if push_success:
|
| 245 |
st.success("✅ انتقال موفقیتآمیز بود! فرآیند بیلد (Build) اسپیس شما در هاگینگفیس آغاز شد.")
|
| 246 |
st.balloons()
|
| 247 |
else:
|
| 248 |
clean_error = push_msg.replace(hf_token, "***")
|
| 249 |
-
st.error(f"خطا در آپلود به هاگینگفیس:
|
| 250 |
|
| 251 |
os.chdir("..")
|
| 252 |
|
|
|
|
| 12 |
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
|
| 13 |
return True, result.stdout
|
| 14 |
except subprocess.CalledProcessError as e:
|
| 15 |
+
# ترکیب خروجی استاندارد و خطای ترمینال برای گزارش دقیق خطایابی
|
| 16 |
+
err_msg = e.stderr if e.stderr else ""
|
| 17 |
+
out_msg = e.stdout if e.stdout else ""
|
| 18 |
+
return False, f"{err_msg}\n{out_msg}"
|
| 19 |
|
| 20 |
# تابع ساخت فایل زیپ در حافظه
|
| 21 |
def create_zip_buffer(source_dir, flatten=False):
|
|
|
|
| 99 |
st.error(f"خطا در دانلود: {msg}")
|
| 100 |
st.stop()
|
| 101 |
else:
|
|
|
|
| 102 |
run_command(f"git -C {temp_dir} lfs pull")
|
| 103 |
else:
|
| 104 |
status_area.info("📥 در حال استخراج فایل ZIP...")
|
|
|
|
| 124 |
shutil.rmtree(".git", ignore_errors=True)
|
| 125 |
|
| 126 |
run_command("git init")
|
| 127 |
+
run_command("git lfs install")
|
| 128 |
+
run_command(f"git remote add origin {auth_gh_url}")
|
| 129 |
run_command("git add .")
|
| 130 |
run_command('git config user.email "bot@transfer.com"')
|
| 131 |
run_command('git config user.name "Transfer Bot"')
|
|
|
|
| 133 |
run_command("git branch -M main")
|
| 134 |
|
| 135 |
status_area.info("📤 در حال آپلود به گیتهاب...")
|
| 136 |
+
push_success, push_msg = run_command("git push -f origin main")
|
| 137 |
|
| 138 |
if push_success:
|
| 139 |
st.success("✅ تمام شد! فایلها دقیقاً در روت ریپازیتوری منتقل شدند.")
|
|
|
|
| 199 |
shutil.rmtree(temp_dir_hf, ignore_errors=True)
|
| 200 |
|
| 201 |
try:
|
| 202 |
+
# استخراج هوشمند نامکاربری مقصد از آدرس وارد شده جهت احراز هویت بدون مشکل
|
| 203 |
+
username = "user"
|
| 204 |
+
try:
|
| 205 |
+
cleaned_url = hf_target_url.replace("https://", "").replace("http://", "")
|
| 206 |
+
parts = cleaned_url.split("huggingface.co/spaces/")[-1].strip("/").split("/")
|
| 207 |
+
if len(parts) >= 1 and parts[0] != "":
|
| 208 |
+
username = parts[0]
|
| 209 |
+
except Exception:
|
| 210 |
+
pass
|
| 211 |
+
|
| 212 |
+
# ایجاد آدرس با الگوی معتبر نامکاربری و توکن به جای __token__
|
| 213 |
+
auth_hf_url = hf_target_url.replace("https://", f"https://{username}:{hf_token}@")
|
| 214 |
|
| 215 |
# مرحله 1: آمادهسازی فایلها (دانلود یا استخراج زیپ)
|
| 216 |
if source_type_hf == "لینک ریپازیتوری (گیتهاب و غیره)":
|
|
|
|
| 245 |
shutil.rmtree(".git", ignore_errors=True)
|
| 246 |
|
| 247 |
run_command("git init")
|
| 248 |
+
run_command("git lfs install") # فعالسازی و راهاندازی محلی LFS
|
| 249 |
+
run_command(f"git remote add origin {auth_hf_url}") # ایجاد ریموت رسمی جهت شناسایی آپلودهای LFS
|
| 250 |
run_command("git add .")
|
| 251 |
run_command('git config user.email "bot@transfer.com"')
|
| 252 |
run_command('git config user.name "Transfer Bot"')
|
|
|
|
| 254 |
run_command("git branch -M main")
|
| 255 |
|
| 256 |
status_area_hf.info("📤 در حال آپلود فایلها به اسپیس هاگینگفیس...")
|
| 257 |
+
push_success, push_msg = run_command("git push -f origin main")
|
| 258 |
|
| 259 |
if push_success:
|
| 260 |
st.success("✅ انتقال موفقیتآمیز بود! فرآیند بیلد (Build) اسپیس شما در هاگینگفیس آغاز شد.")
|
| 261 |
st.balloons()
|
| 262 |
else:
|
| 263 |
clean_error = push_msg.replace(hf_token, "***")
|
| 264 |
+
st.error(f"خطا در آپلود به هاگینگفیس:\n{clean_error}")
|
| 265 |
|
| 266 |
os.chdir("..")
|
| 267 |
|