open_test / app.py
wintergw's picture
Update app.py
c22c000 verified
Raw
History Blame Contribute Delete
1.88 kB
from huggingface_hub import hf_hub_download, snapshot_download
import pandas as pd
import importlib
import importlib.util
import streamlit as st
import sys
import os
from pathlib import Path
# USER_NAME = os.getenv("USER_NAME", "").strip().strip('"')
# PRIVATE_SPACE_NAME = os.getenv("PRIVATE_SPACE_NAME", "").strip().strip('"')
# # Construct the repo ID
# REPO_ID = f"{USER_NAME}/{PRIVATE_SPACE_NAME}"
REPO_ID ="wintergw/assignment_opt_gurobi"
REPO_TYPE = "space"
# def setup_cache_directory():
# """Set up and return cache directory for private space files"""
# cache_dir = Path("private_space_cache")
# cache_dir.mkdir(exist_ok=True)
# return cache_dir
# def download_private_assets(cache_dir):
# """Download necessary files from private space"""
# try:
# snapshot_download(
# repo_id=REPO_ID,
# repo_type=REPO_TYPE,
# local_dir=cache_dir,
# )
# return True
# except Exception as e:
# print(f"Error downloading private assets: {str(e)}")
# return False
# # Setup cache directory and download assets
# cache_dir = setup_cache_directory()
# download_private_assets(cache_dir)
# Download the entire space (optional, if needed)
repo_dir = snapshot_download(
repo_id=REPO_ID,
repo_type=REPO_TYPE,
cache_dir="private_space_cache"
)
# Add repo directory to sys.path so Python can find modules inside it
sys.path.append(repo_dir)
# Download specific files (if snapshot_download wasn't used)
app_path = hf_hub_download(
repo_id=REPO_ID,
filename="app.py",
repo_type=REPO_TYPE
)
# Load and execute `app.py`
spec_app = importlib.util.spec_from_file_location("*", app_path)
app_module = importlib.util.module_from_spec(spec_app)
spec_app.loader.exec_module(app_module)
# Now you can use functions from utils_module
result = app_module.main()