Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,41 +8,44 @@ from langchain import OpenAI, LLMChain
|
|
8 |
from cachetools import cached, TTLCache
|
9 |
import openai
|
10 |
|
|
|
|
|
11 |
s3 = boto3.resource('s3')
|
12 |
bucket_name = "notesinendocrinology"
|
13 |
combo_index_path = "comboindex.json"
|
14 |
nafld_path = "nafld.json"
|
15 |
osteoporosis_path = "osteoporosis.json"
|
16 |
|
17 |
-
for prefix in [combo_index_path, nafld_path, osteoporosis_path]:
|
18 |
-
for obj in s3.Bucket(bucket_name).objects.filter(Prefix=prefix):
|
19 |
-
file_path = obj.key
|
20 |
-
s3.Bucket(bucket_name).download_file(file_path, file_path.split("/")[-1])
|
21 |
-
print(f"Downloaded {file_path}")
|
22 |
|
23 |
-
@cached(cache=TTLCache(maxsize=1, ttl=3600)) # cache for 1 hour
|
24 |
def keywords(query2):
|
25 |
-
index1 = GPTSimpleVectorIndex.load_from_disk(combo_index_path)
|
26 |
-
prefix_answer1 = 'According to NIE:'
|
27 |
-
suffix_answer1 = 'Citation: NIE'
|
28 |
-
if 'NASH' in query2 or 'NAFLD' in query2 or 'Non-alcoholic fatty live disease' in query2:
|
29 |
-
index1 = GPTSimpleVectorIndex.load_from_disk(nafld_path)
|
30 |
-
prefix_answer1 = "Here is the answer based on Notes in Endocrinology and American Association of Clinical Endocrinology Clinical Practice Guideline for the Diagnosis and Management of Nonalcoholic Fatty Liver Disease in Primary Care and Endocrinology Clinical Settings:"
|
31 |
-
suffix_answer1 = """Citation: \n
|
32 |
|
33 |
-
|
|
|
|
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
"""
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
"""
|
|
|
|
|
43 |
|
44 |
-
|
|
|
|
|
|
|
45 |
|
|
|
46 |
|
47 |
|
48 |
def send_message(message_log):
|
8 |
from cachetools import cached, TTLCache
|
9 |
import openai
|
10 |
|
11 |
+
|
12 |
+
|
13 |
s3 = boto3.resource('s3')
|
14 |
bucket_name = "notesinendocrinology"
|
15 |
combo_index_path = "comboindex.json"
|
16 |
nafld_path = "nafld.json"
|
17 |
osteoporosis_path = "osteoporosis.json"
|
18 |
|
|
|
|
|
|
|
|
|
|
|
19 |
|
|
|
20 |
def keywords(query2):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
index1 = None
|
23 |
+
prefix_answer1 = 'According to NIE:'
|
24 |
+
suffix_answer1 = 'Lakhani OJ. EndoAI Answer [Internet]. Notes in Endocrinology. [cited 2023Mar31]. Available from: endocrinology.co.in'
|
25 |
|
26 |
+
if 'NASH' in query2 or 'NAFLD' in query2 or 'Non-alcoholic fatty liver disease' in query2:
|
27 |
+
index_path = nafld_path
|
28 |
+
prefix_answer1 = "Here is the answer based on Notes in Endocrinology and American Association of Clinical Endocrinology Clinical Practice Guideline for the Diagnosis and Management of Nonalcoholic Fatty Liver Disease in Primary Care and Endocrinology Clinical Settings:"
|
29 |
+
suffix_answer1 = """Citation: \n
|
30 |
+
1. Cusi, Kenneth, Scott Isaacs, Diana Barb, Rita Basu, Sonia Caprio, W. Timothy Garvey, Sangeeta Kashyap et al. "American Association of Clinical Endocrinology clinical practice guideline for the diagnosis and management of nonalcoholic fatty liver disease in primary care and endocrinology clinical settings: co-sponsored by the American Association for the Study of Liver Diseases (AASLD)." Endocrine Practice 28, no. 5 (2022): 528-562.
|
31 |
+
2. Lakhani OJ. EndoAI Answer [Internet]. Notes in Endocrinology. [cited 2023Mar31]. Available from: endocrinology.co.in
|
32 |
"""
|
33 |
+
elif 'osteoporosis' in query2 or 'osteopenia' in query2 or 'low bone mass' in query2 or 'DEXA-BMD' in query2 or 'BMD' in query2 or 'Osteoporosis' in query2:
|
34 |
+
index_path = osteoporosis_path
|
35 |
+
prefix_answer1 = "According to : Pharmacological Management of Osteoporosis in Postmenopausal Women: An Endocrine Society* Clinical Practice Guideline & Notes in Endocrinology"
|
36 |
+
suffix_answer1 = """Citation: \n
|
37 |
+
1. Eastell R, Rosen CJ, Black DM, Cheung AM, Murad MH, Shoback D. Pharmacological management of osteoporosis in postmenopausal women: an Endocrine Society clinical practice guideline. The Journal of Clinical Endocrinology & Metabolism. 2019 May;104(5):1595-622.
|
38 |
+
2. Lakhani OJ. EndoAI Answer [Internet]. Notes in Endocrinology. [cited 2023Mar31]. Available from: endocrinology.co.in
|
39 |
"""
|
40 |
+
else:
|
41 |
+
index_path = combo_index_path
|
42 |
|
43 |
+
if index1 is None:
|
44 |
+
s3.Bucket(bucket_name).download_file(index_path, index_path.split("/")[-1])
|
45 |
+
print(f"Downloaded {index_path}")
|
46 |
+
index1 = GPTSimpleVectorIndex.load_from_disk(index_path)
|
47 |
|
48 |
+
return index1, prefix_answer1, suffix_answer1
|
49 |
|
50 |
|
51 |
def send_message(message_log):
|