File size: 1,196 Bytes
14589fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import sys

# Force UTF-8 output for Windows terminals
sys.stdout.reconfigure(encoding='utf-8')

# 1. Update .env
env_path = ".env"
key = "GOOGLE_API_KEY"
value = "AIzaSyDgIkagGBciWNZDTn07OlfY9tVPvo6KJ1on"

print(f"Updating {key} in .env...")

lines = []
if os.path.exists(env_path):
    with open(env_path, "r", encoding="utf-8") as f:
        lines = f.readlines()

found = False
new_lines = []
for line in lines:
    if line.startswith(f"{key}="):
        new_lines.append(f"{key}={value}\n")
        found = True
    else:
        new_lines.append(line)

if not found:
    if new_lines and not new_lines[-1].endswith('\n'):
        new_lines.append('\n')
    new_lines.append(f"{key}={value}\n")

with open(env_path, "w", encoding="utf-8") as f:
    f.writelines(new_lines)

print(f"βœ… Updated {key} in .env")

# 2. Upload to Cloud
print("Syncing secrets to Hugging Face Space...")
try:
    # Build path to ensure we can import upload_secrets
    sys.path.append(os.getcwd())
    from upload_secrets import upload_secrets
    
    upload_secrets()
    print("βœ… Google Key saved locally and uploaded to Hugging Face!")
except Exception as e:
    print(f"❌ Failed to sync: {e}")