Blessmore commited on
Commit
2105cf1
·
verified ·
1 Parent(s): 94a4017

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -17
app.py CHANGED
@@ -9,7 +9,6 @@ import io
9
  import tempfile
10
  import numpy as np
11
  from concurrent.futures import ThreadPoolExecutor
12
- from huggingface_hub import hf_hub_download
13
  from sklearn.metrics.pairwise import cosine_similarity
14
 
15
  # Function to preprocess text
@@ -67,20 +66,15 @@ def clean_text_multithreaded(text):
67
  cleaned_chunks = list(executor.map(clean_text_chunk, chunks))
68
  return '\n'.join(cleaned_chunks)
69
 
70
- # Function to load the FastText model from Hugging Face
71
  @st.cache_resource
72
- def load_fasttext_model(model_path):
73
- #model_path = os.path.join(model_dir, "fasttext_model.model")
74
- #vectors_path = os.path.join(model_dir, "fasttext_model_vectors.kv")
75
- #vectors_ngrams_path = os.path.join(model_dir, "fasttext_model.model.wv.vectors_ngrams.npy")
76
-
77
- model = FastText.load(model_path)
78
- #model.wv = KeyedVectors.load(vectors_path, mmap='r')
79
- #model.wv.vectors_ngrams = np.load(vectors_ngrams_path, mmap_mode='r')
80
-
81
  return model
82
 
83
-
84
  # Function to generate embeddings for a given word
85
  def generate_word_embedding(word, model):
86
  return model.wv.get_vector(word, norm=True) if word in model.wv else None
@@ -206,12 +200,11 @@ def main():
206
  elif option == "Generate Embeddings":
207
  st.header("Generate Embeddings with Pretrained FastText Model")
208
 
209
- repo_id = "Blessmore/Fasttext_embeddings/Fast_text_50_dim"
210
- model_path = "Fast_text_50_dim"
211
- vectors_file = "fasttext_model_vectors.kv"
212
- vectors_ngrams_file = "fasttext_model.model.wv.vectors_ngrams.npy"
213
 
214
- model = load_fasttext_model(model_path)
 
215
 
216
  st.subheader("Generate Word Embedding")
217
  word = st.text_input("Enter a word:")
 
9
  import tempfile
10
  import numpy as np
11
  from concurrent.futures import ThreadPoolExecutor
 
12
  from sklearn.metrics.pairwise import cosine_similarity
13
 
14
  # Function to preprocess text
 
66
  cleaned_chunks = list(executor.map(clean_text_chunk, chunks))
67
  return '\n'.join(cleaned_chunks)
68
 
69
+ # Function to load the FastText model from the specified folder
70
  @st.cache_resource
71
+ def load_fasttext_model(model_folder):
72
+ model_file = os.path.join(model_folder, "fasttext_model.model")
73
+ vectors_file = os.path.join(model_folder, "fasttext_model_vectors.kv")
74
+ model = FastText.load(model_file)
75
+ model.wv = KeyedVectors.load(vectors_file)
 
 
 
 
76
  return model
77
 
 
78
  # Function to generate embeddings for a given word
79
  def generate_word_embedding(word, model):
80
  return model.wv.get_vector(word, norm=True) if word in model.wv else None
 
200
  elif option == "Generate Embeddings":
201
  st.header("Generate Embeddings with Pretrained FastText Model")
202
 
203
+ # Specify the path to the model folder
204
+ model_folder = "Fast_text_50_dim"
 
 
205
 
206
+ # Load the model from the specified folder
207
+ model = load_fasttext_model(model_folder)
208
 
209
  st.subheader("Generate Word Embedding")
210
  word = st.text_input("Enter a word:")