shivanis14
commited on
Commit
•
3629144
1
Parent(s):
ae048b2
Update app.py
Browse files
app.py
CHANGED
@@ -272,11 +272,15 @@ def get_files_with_ingredient_info(ingredient, N=1):
|
|
272 |
#Find embedding for title of all files
|
273 |
global embeddings_titles
|
274 |
#Apply cosine similarity between embedding of ingredient name and title of all files
|
275 |
-
|
276 |
#Fine top N titles that are the most similar to the ingredient's name
|
277 |
#Find file names for those titles
|
278 |
-
if len(
|
279 |
file_paths.append("Ingredients.docx")
|
|
|
|
|
|
|
|
|
280 |
return file_paths
|
281 |
|
282 |
def get_assistant_for_ingredient(ingredient, N=2):
|
@@ -297,6 +301,8 @@ def get_assistant_for_ingredient(ingredient, N=2):
|
|
297 |
|
298 |
# Ready the files for upload to OpenAI.
|
299 |
file_paths = get_files_with_ingredient_info(ingredient, N)
|
|
|
|
|
300 |
file_streams = [open(path, "rb") for path in file_paths]
|
301 |
|
302 |
# Use the upload and poll SDK helper to upload the files, add them to the vector store,
|
|
|
272 |
#Find embedding for title of all files
|
273 |
global embeddings_titles
|
274 |
#Apply cosine similarity between embedding of ingredient name and title of all files
|
275 |
+
file_paths_abs = find_relevant_file_paths(ingredient, embeddings_titles)
|
276 |
#Fine top N titles that are the most similar to the ingredient's name
|
277 |
#Find file names for those titles
|
278 |
+
if len(file_paths_abs) == 0:
|
279 |
file_paths.append("Ingredients.docx")
|
280 |
+
else:
|
281 |
+
for file_path in file_paths_abs:
|
282 |
+
file_paths.append(f"articles/{file_path}")
|
283 |
+
|
284 |
return file_paths
|
285 |
|
286 |
def get_assistant_for_ingredient(ingredient, N=2):
|
|
|
301 |
|
302 |
# Ready the files for upload to OpenAI.
|
303 |
file_paths = get_files_with_ingredient_info(ingredient, N)
|
304 |
+
print(f"DEBUG : Creating vector store for files {file_paths}")
|
305 |
+
|
306 |
file_streams = [open(path, "rb") for path in file_paths]
|
307 |
|
308 |
# Use the upload and poll SDK helper to upload the files, add them to the vector store,
|