-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_to_hf.py
More file actions
94 lines (85 loc) · 3.5 KB
/
deploy_to_hf.py
File metadata and controls
94 lines (85 loc) · 3.5 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""
Deploy FinSight to Hugging Face Spaces.
Run from D:\finsight\ with venv active.
"""
import sys
import shutil
from pathlib import Path
from huggingface_hub import HfApi
REPO_ID = "Rajveer234/finsight"
LOCAL_DIR = Path(".")
api = HfApi()
# ── Files to upload ────────────────────────────────────────────────────────────
uploads = [
# (local path, path in Space)
("src/dashboard/app.py", "app.py"),
("config.py", "config.py"),
("data/processed/feature_matrix.parquet", "data/processed/feature_matrix.parquet"),
("data/processed/finbert_features.parquet", "data/processed/finbert_features.parquet"),
("data/processed/rag_features.parquet", "data/processed/rag_features.parquet"),
("experiments/model_results.csv", "experiments/model_results.csv"),
("experiments/backtest_results.csv", "experiments/backtest_results.csv"),
("experiments/shap_values.parquet", "experiments/shap_values.parquet"),
]
# ── requirements.txt for Spaces ────────────────────────────────────────────────
REQUIREMENTS = """streamlit==1.41.1
plotly==5.24.1
pandas==2.2.3
numpy==1.26.4
pyarrow==18.1.0
scikit-learn==1.5.2
lightgbm==4.5.0
"""
# ── config.py for Spaces (uses relative paths) ────────────────────────────────
CONFIG = """from pathlib import Path
ROOT_DIR = Path(__file__).resolve().parent
DATA_DIR = ROOT_DIR / "data"
RAW_DIR = DATA_DIR / "raw"
PROCESSED_DIR = DATA_DIR / "processed"
EXPERIMENTS_DIR = ROOT_DIR / "experiments"
START_YEAR = 2018
END_YEAR = 2024
FINBERT_MODEL = "ProsusAI/finbert"
EMBED_MODEL = "all-MiniLM-L6-v2"
BATCH_SIZE = 16
DEVICE = "cpu"
TRANSACTION_COST_BPS = 10
REBALANCE_FREQ = "Q"
"""
print("Writing requirements.txt and config.py for Spaces...")
Path("hf_deploy/requirements.txt").parent.mkdir(exist_ok=True)
Path("hf_deploy/requirements.txt").write_text(REQUIREMENTS)
Path("hf_deploy/config.py").write_text(CONFIG)
print(f"\nUploading to {REPO_ID}...")
# Upload requirements and config
for local, remote in [
("hf_deploy/requirements.txt", "requirements.txt"),
("hf_deploy/config.py", "config.py"),
]:
api.upload_file(
path_or_fileobj=local,
path_in_repo=remote,
repo_id=REPO_ID,
repo_type="space",
)
print(f" ✅ {remote}")
# Upload all data and source files
for local, remote in uploads:
p = Path(local)
if not p.exists():
print(f" ⚠️ MISSING: {local} — skipping")
continue
api.upload_file(
path_or_fileobj=str(p),
path_in_repo=remote,
repo_id=REPO_ID,
repo_type="space",
)
print(f" ✅ {remote}")
print(f"""
╔══════════════════════════════════════════════════════╗
║ DEPLOYMENT COMPLETE ║
║ Your app: https://huggingface.co/spaces/Rajveer234/finsight ║
║ Wait ~2 minutes for Space to rebuild ║
╚══════════════════════════════════════════════════════╝
""")