m7n commited on
Commit
6fb2f1c
·
1 Parent(s): 2c40bdd

Add GPU-aware function to create embeddings for input texts in app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -0
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import time
2
  print(f"Starting up: {time.strftime('%Y-%m-%d %H:%M:%S')}")
3
  # source openalex_env_map/bin/activate
@@ -95,6 +96,12 @@ from spaces.zero.client import _get_token
95
  @spaces.GPU(duration=1) # ← forces the detector to see a GPU-aware fn
96
  def _warmup(): pass
97
 
 
 
 
 
 
 
98
  #if is_running_in_hf_space():
99
  #import spaces # necessary to run on Zero.
100
  #print(f"Spaces version: {spaces.__version__}")
 
1
+ import spaces #
2
  import time
3
  print(f"Starting up: {time.strftime('%Y-%m-%d %H:%M:%S')}")
4
  # source openalex_env_map/bin/activate
 
96
  @spaces.GPU(duration=1) # ← forces the detector to see a GPU-aware fn
97
  def _warmup(): pass
98
 
99
+ @spaces.GPU(duration=30)
100
+ def create_embeddings_30(texts_to_embedd):
101
+ """Create embeddings for the input texts using the loaded model."""
102
+ return model.encode(texts_to_embedd, show_progress_bar=True, batch_size=192)
103
+
104
+
105
  #if is_running_in_hf_space():
106
  #import spaces # necessary to run on Zero.
107
  #print(f"Spaces version: {spaces.__version__}")