bhaskartripathi commited on
Commit
1605348
1 Parent(s): 69aad3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py CHANGED
@@ -91,14 +91,33 @@ class SemanticSearch:
91
 
92
 
93
 
 
 
 
 
 
 
 
 
94
  def load_recommender(path, start_page=1):
95
  global recommender
 
 
 
 
 
 
 
 
 
96
  texts = pdf_to_text(path, start_page=start_page)
97
  chunks = text_to_chunks(texts, start_page=start_page)
98
  recommender.fit(chunks)
 
99
  return 'Corpus Loaded.'
100
 
101
 
 
102
  def generate_text(openAI_key,prompt, engine="text-davinci-003"):
103
  openai.api_key = openAI_key
104
  completions = openai.Completion.create(
 
91
 
92
 
93
 
94
+ #def load_recommender(path, start_page=1):
95
+ # global recommender
96
+ # texts = pdf_to_text(path, start_page=start_page)
97
+ # chunks = text_to_chunks(texts, start_page=start_page)
98
+ # recommender.fit(chunks)
99
+ # return 'Corpus Loaded.'
100
+
101
+ # The modified function generates embeddings based on PDF file name and page number and checks if the embeddings file exists before loading or generating it.
102
  def load_recommender(path, start_page=1):
103
  global recommender
104
+ pdf_file = os.path.basename(path)
105
+ embeddings_file = f"{pdf_file}_{start_page}.npy"
106
+
107
+ if os.path.isfile(embeddings_file):
108
+ embeddings = np.load(embeddings_file)
109
+ recommender.embeddings = embeddings
110
+ recommender.fitted = True
111
+ return "Embeddings loaded from file"
112
+
113
  texts = pdf_to_text(path, start_page=start_page)
114
  chunks = text_to_chunks(texts, start_page=start_page)
115
  recommender.fit(chunks)
116
+ np.save(embeddings_file, recommender.embeddings)
117
  return 'Corpus Loaded.'
118
 
119
 
120
+
121
  def generate_text(openAI_key,prompt, engine="text-davinci-003"):
122
  openai.api_key = openAI_key
123
  completions = openai.Completion.create(