smarter_chart / app.py
paavan
Updated app.py
c662cd5
import os
import shutil
import subprocess
from huggingface_hub import snapshot_download
PRIVATE_REPO = "sigma16/PHART_Chart"
HF_TOKEN = os.getenv("HF_TOKEN")
if not HF_TOKEN:
raise Exception("HF_TOKEN secret missing")
print("Downloading private repo (including LFS files)...")
download_path = snapshot_download(
repo_id=PRIVATE_REPO,
repo_type="space",
token=HF_TOKEN,
ignore_patterns=["*.git", ".git/*"],
)
print(f"Downloaded to: {download_path}")
# Log what was actually downloaded so we can debug
print("=== Files in downloaded repo ===")
for root, dirs, files in os.walk(download_path):
dirs[:] = [d for d in dirs if d != ".git"]
for f in files:
full = os.path.join(root, f)
rel = os.path.relpath(full, download_path)
size = os.path.getsize(full)
print(f" {rel} ({size} bytes)")
print("=== End file listing ===")
# Clean and copy runtime directory
RUNTIME_DIR = "/app/private_runtime"
if os.path.exists(RUNTIME_DIR):
shutil.rmtree(RUNTIME_DIR)
shutil.copytree(download_path, RUNTIME_DIR)
print(f"Copied private app to: {RUNTIME_DIR}")
# Verify data files landed
data_dir = os.path.join(RUNTIME_DIR, "data")
if os.path.exists(data_dir):
data_files = os.listdir(data_dir)
print(f"data/ contents: {data_files}")
else:
print("WARNING: data/ directory not found in runtime!")
# Run private Home.py
subprocess.run([
"streamlit", "run",
f"{RUNTIME_DIR}/Home.py",
"--server.port=7860",
"--server.address=0.0.0.0",
"--server.headless=true",
])