Spaces:
Sleeping
Sleeping
| import os, base64, zipfile, io, sys, tempfile, subprocess | |
| from pathlib import Path | |
| from dotenv import load_dotenv | |
| # .env νμΌ λ‘λ (λ‘컬 κ°λ°μ©) | |
| load_dotenv() | |
| def prepare_wallet_dir(): | |
| """ | |
| Wallet μ€λΉ: | |
| - λ°°ν¬ νκ²½: WALLET_ZIP_B64μμ λμ½λ© | |
| - λ‘컬 νκ²½: WALLET_DIR κ²½λ‘ μ¬μ© | |
| """ | |
| # λ‘컬 κ°λ°: WALLET_DIRμ΄ μ΄λ―Έ μ€μ λμ΄ μλ κ²½μ° | |
| if "WALLET_DIR" in os.environ: | |
| wallet_dir = os.environ["WALLET_DIR"] | |
| if Path(wallet_dir).exists(): | |
| print(f"π λ‘컬 Wallet μ¬μ©: {wallet_dir}") | |
| return wallet_dir | |
| # λ°°ν¬ νκ²½: WALLET_ZIP_B64μμ λμ½λ© | |
| if "WALLET_ZIP_B64" not in os.environ: | |
| raise RuntimeError( | |
| "β WALLET_ZIP_B64 λλ WALLET_DIR νκ²½ λ³μκ° νμν©λλ€.\n" | |
| " λ‘컬: .env νμΌμ WALLET_DIR μ€μ \n" | |
| " λ°°ν¬: Hugging Face Secretsμ WALLET_ZIP_B64 μ€μ " | |
| ) | |
| print("π Wallet Base64 λμ½λ© μμ...") | |
| b64 = os.environ["WALLET_ZIP_B64"] | |
| wallet_password = os.environ["WALLET_PASSWORD"] | |
| # walletμ λ©λͺ¨λ¦¬->μμλλ ν λ¦¬λ‘ λ³΅μ | |
| wallet_dir = tempfile.mkdtemp(prefix="wallet_") | |
| print(f"π μμ λλ ν 리: {wallet_dir}") | |
| zip_bytes = base64.b64decode(b64) | |
| with zipfile.ZipFile(io.BytesIO(zip_bytes)) as z: | |
| z.extractall(wallet_dir) | |
| # μμ μ μν΄ κΆν μΆμ | |
| for root, _, files in os.walk(wallet_dir): | |
| for f in files: | |
| os.chmod(os.path.join(root, f), 0o600) | |
| print("β Wallet μμΆ ν΄μ μλ£") | |
| # μ§κ° λΉλ°λ²νΈλ oracledbμμ μ¬μ© | |
| os.environ["WALLET_DIR"] = wallet_dir | |
| os.environ["WALLET_PASSWORD"] = wallet_password | |
| return wallet_dir | |
| if __name__ == "__main__": | |
| print("=" * 60) | |
| print("π MuscleCare FastAPI μλ² μμ") | |
| print("=" * 60) | |
| # Wallet μ€λΉ | |
| try: | |
| prepare_wallet_dir() | |
| except Exception as e: | |
| print(f"β Wallet μ€λΉ μ€ν¨: {e}") | |
| sys.exit(1) | |
| # Uvicorn κΈ°λ | |
| print("\nπ FastAPI μλ² μ€ν...") | |
| print("=" * 60) | |
| subprocess.run([sys.executable, "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]) | |