Repository navigation
Expand file tree
/
Copy pathdeploy.py
More file actions
58 lines (46 loc) · 1.66 KB
/
Copy pathdeploy.py
File metadata and controls
58 lines (46 loc) · 1.66 KB
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
# -*- coding: utf-8 -*-
"""Hugging Face Space deployment utilities."""
import json
import os
from config import HF_TOKEN, SPACE_NAME, BASE_DIR
def create_space_files(base_dir=None):
base_dir = base_dir or BASE_DIR
files = {
"app.py": "app.py",
"corpus.json": "corpus.json",
"requirements.txt": "requirements.txt",
}
return files
def upload_to_hf_space(files=None, token=None, repo_id=None):
from huggingface_hub import HfApi
token = token or HF_TOKEN
repo_id = repo_id or SPACE_NAME
api = HfApi()
base_dir = BASE_DIR
files = files or create_space_files()
for local_name, remote_name in files.items():
local_path = os.path.join(base_dir, local_name)
if os.path.exists(local_path):
api.upload_file(
path_or_fileobj=local_path,
path_in_repo=remote_name,
repo_id=repo_id,
repo_type="space",
token=token,
)
print(f"Uploaded {local_name} → {remote_name}")
else:
print(f"⚠️ File not found: {local_path}")
print(f"Deployed! Visit: https://huggingface.co/spaces/{repo_id}")
def check_api_key_in_file(filepath):
if not os.path.exists(filepath):
print(f"File not found: {filepath}")
return
with open(filepath, "r", encoding="utf-8") as f:
code = f.read()
has_key = "gsk_" in code or "GROQ_API_KEY" in code
print(f"{filepath}: Contains API key = {has_key}")
if has_key:
for i, line in enumerate(code.splitlines(), 1):
if "gsk_" in line or "GROQ_API_KEY" in line:
print(f" Line {i}: {line}")