Spaces:
Runtime error
Runtime error
Commit Β·
e1d454c
1
Parent(s): 8eb436c
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,33 +13,42 @@ import joblib
|
|
| 13 |
|
| 14 |
from huggingface_hub import hf_hub_download
|
| 15 |
|
| 16 |
-
encoder_text_path = hf_hub_download(repo_id=os.environ['REPO_ID'], repo_type="space", filename=os.environ['ENCODER_TEXT'],
|
| 17 |
-
use_auth_token=os.environ['TOKEN'])
|
| 18 |
-
print("DEBUG ", encoder_text_path)
|
| 19 |
# NO GPU
|
| 20 |
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
|
| 21 |
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
|
| 22 |
|
| 23 |
# Cacher le nom du repo
|
| 24 |
-
python_path = hf_hub_download(repo_id=os.environ['REPO_ID'], repo_type="space", filename=os.environ['MODEL_FILE'],
|
| 25 |
-
use_auth_token=os.environ['TOKEN'])
|
| 26 |
-
print(python_path)
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
sys.path.append(os.environ['PRIVATE_DIR'])
|
| 29 |
from models import *
|
| 30 |
preprocess_model, model = get_models()
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
use_auth_token=os.environ['TOKEN'])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
#catalog_path = hf_hub_download(repo_id=os.environ['REPO_ID'], repo_type="space", filename=os.environ['CATALOG'],
|
| 36 |
# use_auth_token=os.environ['TOKEN']) ###############
|
| 37 |
-
catalog_path = get_catalog()
|
| 38 |
|
| 39 |
-
url_dict=get_durl(catalog_path) ############
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
def process(prompt, lang):
|
| 45 |
now = datetime.datetime.now()
|
|
@@ -52,12 +61,13 @@ def process(prompt, lang):
|
|
| 52 |
|
| 53 |
# Embed text
|
| 54 |
embed_query = get_predict(encoder_text, prompt, preprocess_model, model)
|
| 55 |
-
|
| 56 |
-
|
|
|
|
| 57 |
print(" text embed computed.")
|
| 58 |
|
| 59 |
# distance computing
|
| 60 |
-
D, I = index.search(embed_query, TOP)
|
| 61 |
|
| 62 |
# output : top N audio file names
|
| 63 |
print(I)
|
|
|
|
| 13 |
|
| 14 |
from huggingface_hub import hf_hub_download
|
| 15 |
|
| 16 |
+
#encoder_text_path = hf_hub_download(repo_id=os.environ['REPO_ID'], repo_type="space", filename=os.environ['ENCODER_TEXT'],
|
| 17 |
+
# use_auth_token=os.environ['TOKEN'])
|
| 18 |
+
#print("DEBUG ", encoder_text_path)
|
| 19 |
# NO GPU
|
| 20 |
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
|
| 21 |
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
|
| 22 |
|
| 23 |
# Cacher le nom du repo
|
| 24 |
+
#python_path = hf_hub_download(repo_id=os.environ['REPO_ID'], repo_type="space", filename=os.environ['MODEL_FILE'],
|
| 25 |
+
# use_auth_token=os.environ['TOKEN'])
|
| 26 |
+
#print(python_path)
|
| 27 |
+
|
| 28 |
+
#os.system('ls -la')
|
| 29 |
+
|
| 30 |
sys.path.append(os.environ['PRIVATE_DIR'])
|
| 31 |
from models import *
|
| 32 |
preprocess_model, model = get_models()
|
| 33 |
+
|
| 34 |
+
#index_path = get_index_path()
|
| 35 |
+
#hf_hub_download(repo_id=os.environ['REPO_ID'], repo_type="space", filename=os.environ['INDEX'],
|
| 36 |
+
# use_auth_token=os.environ['TOKEN'])
|
| 37 |
+
|
| 38 |
+
#indexnames_path = get_indexnames_path()
|
| 39 |
+
#hf_hub_download(repo_id=os.environ['REPO_ID'], repo_type="space", filename=os.environ['INDEX_NAMES'],
|
| 40 |
+
# use_auth_token=os.environ['TOKEN']) #########
|
| 41 |
#catalog_path = hf_hub_download(repo_id=os.environ['REPO_ID'], repo_type="space", filename=os.environ['CATALOG'],
|
| 42 |
# use_auth_token=os.environ['TOKEN']) ###############
|
| 43 |
+
#catalog_path = get_catalog()
|
| 44 |
|
| 45 |
+
#url_dict=get_durl(catalog_path) ############
|
| 46 |
+
url_dict = get_durl()
|
| 47 |
+
audio_names = get_audio_names() #joblib.load(open(indexnames_path, 'rb')) ############
|
| 48 |
+
index = get_index() #faiss.read_index(index_path)
|
| 49 |
+
|
| 50 |
+
#encoder_text = tf.keras.models.load_model(encoder_text_path)
|
| 51 |
+
encoder_text = get_encoder_text()
|
| 52 |
|
| 53 |
def process(prompt, lang):
|
| 54 |
now = datetime.datetime.now()
|
|
|
|
| 61 |
|
| 62 |
# Embed text
|
| 63 |
embed_query = get_predict(encoder_text, prompt, preprocess_model, model)
|
| 64 |
+
|
| 65 |
+
do_normalize(embed_query)
|
| 66 |
+
#faiss.normalize_L2(embed_query)
|
| 67 |
print(" text embed computed.")
|
| 68 |
|
| 69 |
# distance computing
|
| 70 |
+
D, I = get_distance(index, embed_query, TOP) #index.search(embed_query, TOP)
|
| 71 |
|
| 72 |
# output : top N audio file names
|
| 73 |
print(I)
|