Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -588,17 +588,18 @@ async def resources_endpoint(profile: MedicalProfile):
|
|
588 |
title = get_page_title(original_url) or "Unknown Title"
|
589 |
resources.append({"file_name": file_name, "title": title, "url": original_url})
|
590 |
else:
|
591 |
-
resources.append({"file_name": file_name, "title": "Unknown", "url": None})
|
592 |
document_texts = retrieve_document_texts(document_ids, folder_path)
|
593 |
if not document_texts:
|
594 |
-
raise ValueError("Failed to retrieve document texts.")
|
595 |
cross_encoder = models['cross_encoder']
|
596 |
scores = cross_encoder.predict([(query_text, doc) for doc in document_texts])
|
597 |
-
scores = [float(score) for score in scores]
|
598 |
for i, resource in enumerate(resources):
|
599 |
-
resource["score"] = scores[i] if i < len(scores) else 0.0
|
600 |
-
resources.sort(key=lambda x: x["score"], reverse=True)
|
601 |
-
|
|
|
602 |
except ValueError as ve:
|
603 |
raise HTTPException(status_code=400, detail=str(ve))
|
604 |
except Exception as e:
|
@@ -630,10 +631,16 @@ async def recipes_endpoint(profile: MedicalProfile):
|
|
630 |
metadata_path = 'recipes_metadata.xlsx'
|
631 |
metadata = retrieve_metadata(document_indices, metadata_path=metadata_path)
|
632 |
print(f"Retrieved Metadata: {metadata}")
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
637 |
except ValueError as ve:
|
638 |
raise HTTPException(status_code=400, detail=str(ve))
|
639 |
except Exception as e:
|
|
|
588 |
title = get_page_title(original_url) or "Unknown Title"
|
589 |
resources.append({"file_name": file_name, "title": title, "url": original_url})
|
590 |
else:
|
591 |
+
resources.append({"file_name": file_name, "title": "Unknown", "url": None})
|
592 |
document_texts = retrieve_document_texts(document_ids, folder_path)
|
593 |
if not document_texts:
|
594 |
+
raise ValueError("Failed to retrieve document texts.")
|
595 |
cross_encoder = models['cross_encoder']
|
596 |
scores = cross_encoder.predict([(query_text, doc) for doc in document_texts])
|
597 |
+
scores = [float(score) for score in scores]
|
598 |
for i, resource in enumerate(resources):
|
599 |
+
resource["score"] = scores[i] if i < len(scores) else 0.0
|
600 |
+
resources.sort(key=lambda x: x["score"], reverse=True)
|
601 |
+
output = [{"title": resource["title"], "url": resource["url"]} for resource in resources]
|
602 |
+
return output
|
603 |
except ValueError as ve:
|
604 |
raise HTTPException(status_code=400, detail=str(ve))
|
605 |
except Exception as e:
|
|
|
631 |
metadata_path = 'recipes_metadata.xlsx'
|
632 |
metadata = retrieve_metadata(document_indices, metadata_path=metadata_path)
|
633 |
print(f"Retrieved Metadata: {metadata}")
|
634 |
+
recipes = []
|
635 |
+
for item in metadata:
|
636 |
+
recipes.append({
|
637 |
+
"title": item.get("original_file_name", "Unknown Title"),
|
638 |
+
"url": item.get("url", "")
|
639 |
+
})
|
640 |
+
response = {
|
641 |
+
"recipes": recipes
|
642 |
+
}
|
643 |
+
return response
|
644 |
except ValueError as ve:
|
645 |
raise HTTPException(status_code=400, detail=str(ve))
|
646 |
except Exception as e:
|