Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files
db.py
CHANGED
|
@@ -129,7 +129,7 @@ class SanatanDatabase:
|
|
| 129 |
}
|
| 130 |
Or a dict with "error" key if something went wrong.
|
| 131 |
"""
|
| 132 |
-
logger.info("fetching
|
| 133 |
collection = self.chroma_client.get_or_create_collection(name=collection_name)
|
| 134 |
|
| 135 |
try:
|
|
@@ -160,6 +160,7 @@ class SanatanDatabase:
|
|
| 160 |
result.update(metadatas[0])
|
| 161 |
return result
|
| 162 |
else:
|
|
|
|
| 163 |
return {"error": "No data available."}
|
| 164 |
|
| 165 |
|
|
|
|
| 129 |
}
|
| 130 |
Or a dict with "error" key if something went wrong.
|
| 131 |
"""
|
| 132 |
+
logger.info("fetching %s #%d from [%s]", unit_name, index, collection_name)
|
| 133 |
collection = self.chroma_client.get_or_create_collection(name=collection_name)
|
| 134 |
|
| 135 |
try:
|
|
|
|
| 160 |
result.update(metadatas[0])
|
| 161 |
return result
|
| 162 |
else:
|
| 163 |
+
print("No data available")
|
| 164 |
return {"error": "No data available."}
|
| 165 |
|
| 166 |
|
server.py
CHANGED
|
@@ -214,7 +214,7 @@ async def get_scripture(req: ScriptureRequest):
|
|
| 214 |
raw_doc = SanatanDatabase().fetch_document_by_index(
|
| 215 |
collection_name=config["collection_name"],
|
| 216 |
index=req.unit_index,
|
| 217 |
-
unit_name=config.get("unit_field", config.get("unit"))
|
| 218 |
)
|
| 219 |
|
| 220 |
if not raw_doc or isinstance(raw_doc, str):
|
|
@@ -239,16 +239,15 @@ async def get_scripture(req: ScriptureRequest):
|
|
| 239 |
async def get_scripture_configs():
|
| 240 |
scriptures = []
|
| 241 |
for s in SanatanConfig().scriptures:
|
| 242 |
-
num_units = SanatanDatabase().count(
|
| 243 |
-
collection_name=s["collection_name"]
|
| 244 |
-
)
|
| 245 |
-
|
| 246 |
scriptures.append(
|
| 247 |
{
|
| 248 |
"name": s["name"], # e.g. "bhagavad_gita"
|
| 249 |
"title": s["title"], # e.g. "Bhagavad Gita"
|
| 250 |
"unit": s["unit"], # e.g. "verse" or "page"
|
| 251 |
-
"total"
|
|
|
|
|
|
|
| 252 |
}
|
| 253 |
)
|
| 254 |
-
return {"scriptures": scriptures}
|
|
|
|
| 214 |
raw_doc = SanatanDatabase().fetch_document_by_index(
|
| 215 |
collection_name=config["collection_name"],
|
| 216 |
index=req.unit_index,
|
| 217 |
+
unit_name=config.get("unit_field", config.get("unit")),
|
| 218 |
)
|
| 219 |
|
| 220 |
if not raw_doc or isinstance(raw_doc, str):
|
|
|
|
| 239 |
async def get_scripture_configs():
|
| 240 |
scriptures = []
|
| 241 |
for s in SanatanConfig().scriptures:
|
| 242 |
+
num_units = SanatanDatabase().count(collection_name=s["collection_name"])
|
|
|
|
|
|
|
|
|
|
| 243 |
scriptures.append(
|
| 244 |
{
|
| 245 |
"name": s["name"], # e.g. "bhagavad_gita"
|
| 246 |
"title": s["title"], # e.g. "Bhagavad Gita"
|
| 247 |
"unit": s["unit"], # e.g. "verse" or "page"
|
| 248 |
+
"total": num_units,
|
| 249 |
+
"enabled": s["name"]
|
| 250 |
+
in ("divya_prabandham", "chathusloki", "vishnu_sahasranamam"),
|
| 251 |
}
|
| 252 |
)
|
| 253 |
+
return {"scriptures": sorted(scriptures, key=lambda s: s["title"])}
|