| import os |
| from huggingface_hub import hf_hub_download |
| import importlib.util |
| import sys |
|
|
| |
| HF_TOKEN = os.environ.get("HF_TOKEN") |
|
|
| |
| REPO_ID = "limitedonly41/cv_all_src" |
| FILENAME = "website_classifier_code.py" |
|
|
| def load_and_run(): |
| try: |
| |
| file_path = hf_hub_download( |
| repo_id=REPO_ID, |
| filename=FILENAME, |
| token=HF_TOKEN, |
| repo_type="model" |
| ) |
| |
| |
| spec = importlib.util.spec_from_file_location("website_classifier_module", file_path) |
| module = importlib.util.module_from_spec(spec) |
| sys.modules["website_classifier_module"] = module |
| spec.loader.exec_module(module) |
| |
| |
| if hasattr(module, 'interface'): |
| print("Found 'interface' object, launching...") |
| module.interface.launch() |
| elif hasattr(module, 'demo'): |
| print("Found 'demo' object, launching...") |
| module.demo.launch() |
| elif hasattr(module, 'create_interface'): |
| print("Found 'create_interface' function, creating and launching...") |
| interface = module.create_interface() |
| interface.launch() |
| else: |
| print("Error: Could not find 'interface', 'demo', or 'create_interface' in the loaded module") |
| print("Available attributes:", dir(module)) |
| |
| except Exception as e: |
| print(f"Error loading code: {e}") |
| import traceback |
| traceback.print_exc() |
| print("\nMake sure:") |
| print("1. HF_TOKEN is set in Space secrets") |
| print("2. REPO_ID points to your private repository") |
| print("3. The code file exists in the repository") |
|
|
| if __name__ == "__main__": |
| load_and_run() |