rafmacalaba commited on
Commit
1baa73a
·
verified ·
1 Parent(s): 9aed41d

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py CHANGED
@@ -40,6 +40,17 @@ if requirements_file.exists():
40
  print("Installing dependencies...")
41
  subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"], cwd=str(repo_dir), check=True)
42
 
 
 
 
 
 
 
 
 
 
 
 
43
  # 5. Add to Python path and launch the app
44
  sys.path.insert(0, str(repo_dir))
45
  sys.path.insert(0, str(repo_dir / "src"))
@@ -49,6 +60,17 @@ import gradio as gr
49
  from app import demo, CUSTOM_CSS
50
 
51
  if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
52
  theme = gr.themes.Base(
53
  primary_hue="slate",
54
  neutral_hue="slate",
 
40
  print("Installing dependencies...")
41
  subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"], cwd=str(repo_dir), check=True)
42
 
43
+ # 4.5. Pre-download models to cache during startup
44
+ print("Pre-downloading models to local cache...")
45
+ try:
46
+ from huggingface_hub import snapshot_download
47
+ snapshot_download(repo_id="fastino/gliner2-large-v1")
48
+ snapshot_download(repo_id="ai4data/datause-extraction-v1")
49
+ snapshot_download(repo_id="ai4data-use/bert-base-uncased-data-use")
50
+ print("Models pre-downloaded successfully.")
51
+ except Exception as e:
52
+ print(f"Warning: Failed to pre-download models: {e}")
53
+
54
  # 5. Add to Python path and launch the app
55
  sys.path.insert(0, str(repo_dir))
56
  sys.path.insert(0, str(repo_dir / "src"))
 
60
  from app import demo, CUSTOM_CSS
61
 
62
  if __name__ == "__main__":
63
+ # Pre-load models into RAM to avoid first-use delay
64
+ print("Pre-loading models into RAM...")
65
+ try:
66
+ from ai4data import DatasetExtractor
67
+ extractor = DatasetExtractor()
68
+ _ = extractor.model
69
+ _ = extractor.classifier
70
+ print("Models successfully pre-loaded into RAM.")
71
+ except Exception as e:
72
+ print(f"Warning: Failed to pre-load models: {e}")
73
+
74
  theme = gr.themes.Base(
75
  primary_hue="slate",
76
  neutral_hue="slate",