Spaces:
Sleeping
Sleeping
Update tools.py
Browse files
tools.py
CHANGED
@@ -3,22 +3,12 @@ from sefaria import get_text as sefaria_get_text, get_commentaries as sefaria_ge
|
|
3 |
from tantivy_search import TantivySearch
|
4 |
from typing import Optional
|
5 |
from pydantic import BaseModel, Field
|
|
|
|
|
|
|
6 |
|
7 |
from app import INDEX_PATH
|
8 |
|
9 |
-
def download_index_from_gdrive() :
|
10 |
-
zip_path = "index.zip"
|
11 |
-
url = f"https://drive.google.com/uc?id={self.gdrive_index_id}"
|
12 |
-
gdown.download(url, zip_path, quiet=False)
|
13 |
-
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
14 |
-
zip_ref.extractall(".")
|
15 |
-
os.remove(zip_path)
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
if not os.path.exists(INDEX_PATH):
|
20 |
-
download_index_from_gdrive():
|
21 |
-
|
22 |
|
23 |
class ReadTextArgs(BaseModel):
|
24 |
reference: str = Field(description="The reference to retrieve the text for. examples: 讘专讗砖讬转 讗 驻专拽 讗, Genesis 1:1")
|
@@ -89,6 +79,17 @@ class SearchArgs(BaseModel):
|
|
89 |
|
90 |
|
91 |
index_path = INDEX_PATH
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
try:
|
93 |
tantivy = TantivySearch(index_path)
|
94 |
tantivy.validate_index()
|
|
|
3 |
from tantivy_search import TantivySearch
|
4 |
from typing import Optional
|
5 |
from pydantic import BaseModel, Field
|
6 |
+
import os
|
7 |
+
import gdown
|
8 |
+
import zipfile
|
9 |
|
10 |
from app import INDEX_PATH
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
class ReadTextArgs(BaseModel):
|
14 |
reference: str = Field(description="The reference to retrieve the text for. examples: 讘专讗砖讬转 讗 驻专拽 讗, Genesis 1:1")
|
|
|
79 |
|
80 |
|
81 |
index_path = INDEX_PATH
|
82 |
+
if not os.path.exists(index_path):
|
83 |
+
try:
|
84 |
+
zip_path = "index.zip"
|
85 |
+
url = f"https://drive.google.com/uc?id={self.gdrive_index_id}"
|
86 |
+
gdown.download(url, zip_path, quiet=False)
|
87 |
+
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
88 |
+
zip_ref.extractall(".")
|
89 |
+
os.remove(zip_path)
|
90 |
+
except Exception as e:
|
91 |
+
raise Exception(e)
|
92 |
+
|
93 |
try:
|
94 |
tantivy = TantivySearch(index_path)
|
95 |
tantivy.validate_index()
|