Spaces:
Paused
Paused
File size: 2,412 Bytes
5a81b95 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
import os
from huggingface_hub import HfApi
import sys
# Configuration
HF_TOKEN = os.environ.get("HF_TOKEN")
SPACE_NAME = "Kraft102/widgetdc-cortex"
# Update to verify .env.production
ENV_FILE = ".env.production"
def parse_env_file(filepath):
"""Parse .env file manually to avoid dependencies"""
env_vars = {}
try:
if not os.path.exists(filepath):
return None
with open(filepath, 'r', encoding='utf-8') as f:
for line in f:
line = line.strip()
if not line or line.startswith('#'):
continue
if '=' in line:
key, value = line.split('=', 1)
key = key.strip()
value = value.strip()
if (value.startswith('"') and value.endswith('"')) or \
(value.startswith("'") and value.endswith("'")):
value = value[1:-1]
env_vars[key] = value
except Exception as e:
print(f"Error reading {filepath}: {e}")
return None
return env_vars
def main():
print(f"🔍 Checking {ENV_FILE} for production secrets...")
env_vars = parse_env_file(ENV_FILE)
if not env_vars:
print(f"⚠️ {ENV_FILE} not found or empty. Falling back to .env checking...")
env_vars = parse_env_file(".env")
if not env_vars:
print("❌ No .env files found!")
sys.exit(1)
# Check for localhost
localhost_keys = [k for k, v in env_vars.items() if 'localhost' in v or '127.0.0.1' in v]
if localhost_keys:
print(f"⚠️ WARNING: Found localhost values in {ENV_FILE}:")
for k in localhost_keys:
print(f" - {k}")
print(" These will NOT work in Hugging Face Spaces!")
# We will still upload because the user asked us to "gennemfær dette" (execute this)
# But we will verify API keys at least.
print(f"🚀 Uploading {len(env_vars)} secrets to {SPACE_NAME}...")
try:
api = HfApi(token=HF_TOKEN)
for key, value in env_vars.items():
api.add_space_secret(repo_id=SPACE_NAME, key=key, value=value, token=HF_TOKEN)
print(f" ✅ Uploaded {key}")
except Exception as e:
print(f"❌ Upload failed: {e}")
if __name__ == "__main__":
main()
|