rafmacalaba commited on
Commit
586ccc0
·
0 Parent(s):

Initial bootstrap setup

Browse files
Files changed (3) hide show
  1. .gitignore +3 -0
  2. README.md +14 -0
  3. app.py +50 -0
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ monitoring_of_datause/
2
+ __pycache__/
3
+ *.pyc
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Data Use Extractor
3
+ emoji: 📊
4
+ colorFrom: blue
5
+ colorTo: slate
6
+ sdk: gradio
7
+ sdk_version: 5.15.0
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ # Data Use Extractor Bootstrap Space
13
+
14
+ This Hugging Face Space acts as a bootstrap launcher that clones the private repository and executes the Gradio application.
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+ import subprocess
4
+ from pathlib import Path
5
+
6
+ # 1. Retrieve the GitHub token
7
+ token = os.environ.get("GITHUB_TOKEN") or os.environ.get("PAT")
8
+ if not token:
9
+ raise ValueError("Please set the GITHUB_TOKEN or PAT secret in Space settings.")
10
+
11
+ # 2. Clone/Pull private repository
12
+ repo_url = f"https://oauth2:{token}@github.com/rafmacalaba/monitoring_of_datause.git"
13
+ repo_dir = Path("monitoring_of_datause")
14
+
15
+ if not repo_dir.exists():
16
+ print("Cloning private repository...")
17
+ try:
18
+ subprocess.run(["git", "clone", repo_url, str(repo_dir)], check=True, capture_output=True, text=True)
19
+ except subprocess.CalledProcessError as e:
20
+ stderr_clean = e.stderr.replace(token, "********") if token else e.stderr
21
+ raise RuntimeError(f"Failed to clone repository: {stderr_clean}") from None
22
+ else:
23
+ print("Repository exists. Pulling updates...")
24
+ try:
25
+ subprocess.run(["git", "-C", str(repo_dir), "pull"], check=True, capture_output=True, text=True)
26
+ except subprocess.CalledProcessError as e:
27
+ stderr_clean = e.stderr.replace(token, "********") if token else e.stderr
28
+ raise RuntimeError(f"Failed to pull repository: {stderr_clean}") from None
29
+
30
+ # 3. Explicitly install local gliner2 first (since standard pip doesn't read uv.sources)
31
+ gliner2_path = repo_dir / "gliner2-src"
32
+ if gliner2_path.exists():
33
+ print("Installing local gliner2 library...")
34
+ subprocess.run([sys.executable, "-m", "pip", "install", "-e", str(gliner2_path)], check=True)
35
+
36
+ # 4. Install other dependencies and project package
37
+ requirements_file = repo_dir / "requirements.txt"
38
+ if requirements_file.exists():
39
+ print("Installing dependencies...")
40
+ subprocess.run([sys.executable, "-m", "pip", "install", "-r", str(requirements_file)], check=True)
41
+
42
+ # 5. Add to Python path and launch the app
43
+ sys.path.insert(0, str(repo_dir))
44
+ sys.path.insert(0, str(repo_dir / "src"))
45
+ sys.path.insert(0, str(repo_dir / "datause_extract"))
46
+
47
+ from app import demo
48
+
49
+ if __name__ == "__main__":
50
+ demo.launch()