aksj commited on
Commit
d4e3eb1
·
1 Parent(s): 8c12b21

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py CHANGED
@@ -3,6 +3,21 @@ from sklearn.feature_extraction.text import TfidfVectorizer
3
  from sklearn.metrics.pairwise import cosine_similarity
4
  import spacy
5
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  # def find_closest(query):
7
  # files_contents = []
8
  # files_names = []
@@ -33,6 +48,7 @@ import gradio as gr
33
  # return files_names[max_similarity_idx]
34
 
35
  def find_closest(query):
 
36
  nlp = spacy.load('en_core_web_md')
37
  files_names = []
38
  files_vectors = []
 
3
  from sklearn.metrics.pairwise import cosine_similarity
4
  import spacy
5
  import gradio as gr
6
+ import subprocess
7
+
8
+ def download_spacy_model(model_name):
9
+ command = f"python -m spacy download {model_name}"
10
+ process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
11
+ stdout, stderr = process.communicate()
12
+
13
+ # Check if the command executed successfully
14
+ if process.returncode != 0:
15
+ print(f"An error occurred while downloading the model: {stderr.decode('utf-8')}")
16
+ else:
17
+ print(f"Successfully downloaded the model: {stdout.decode('utf-8')}")
18
+
19
+ # Call the function to download the model
20
+
21
  # def find_closest(query):
22
  # files_contents = []
23
  # files_names = []
 
48
  # return files_names[max_similarity_idx]
49
 
50
  def find_closest(query):
51
+ download_spacy_model('en_core_web_md')
52
  nlp = spacy.load('en_core_web_md')
53
  files_names = []
54
  files_vectors = []