File size: 1,922 Bytes
b5339bd
16fb0f1
 
 
b5339bd
16fb0f1
 
b5339bd
16fb0f1
 
 
afd7991
16fb0f1
b5339bd
16fb0f1
 
 
 
 
 
 
afd7991
16fb0f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
afd7991
16fb0f1
 
 
afd7991
16fb0f1
 
 
 
 
 
 
b5339bd
 
16fb0f1
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
import os
from huggingface_hub import hf_hub_download
import importlib.util
import sys

# Get HF token from environment (set in Space secrets)
HF_TOKEN = os.environ.get("HF_TOKEN")

# Your private model/repo details
REPO_ID = "limitedonly41/cv_all_src"
FILENAME = "semrush_scraper_code.py"

def load_and_run():
    try:
        # Download the code file from private repo
        file_path = hf_hub_download(
            repo_id=REPO_ID,
            filename=FILENAME,
            token=HF_TOKEN,
            repo_type="model"
        )
        
        # Load the module dynamically
        spec = importlib.util.spec_from_file_location("semrush_scraper_module", file_path)
        module = importlib.util.module_from_spec(spec)
        sys.modules["semrush_scraper_module"] = module
        spec.loader.exec_module(module)
        
        # Try to find and launch the interface
        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()