Update app.py
Browse files
app.py
CHANGED
|
@@ -91,33 +91,14 @@ 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 |
-
# 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(
|
|
@@ -235,4 +216,4 @@ demo.launch()
|
|
| 235 |
# # Define the button action
|
| 236 |
# if btn:
|
| 237 |
# answer_value = question_answer(url, file, question)
|
| 238 |
-
# answer.value = answer_value
|
|
|
|
| 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(
|
|
|
|
| 216 |
# # Define the button action
|
| 217 |
# if btn:
|
| 218 |
# answer_value = question_answer(url, file, question)
|
| 219 |
+
# answer.value = answer_value
|