Tamil Eniyan commited on
Commit
1d9b2c2
·
1 Parent(s): bd4d03b

Updated app to use fire base

Browse files
Files changed (2) hide show
  1. app.py +26 -2
  2. curated_qa_pairs.json +1 -0
app.py CHANGED
@@ -7,6 +7,21 @@ import torch
7
  from sentence_transformers import SentenceTransformer
8
  from transformers import pipeline, RagTokenizer, RagRetriever, RagSequenceForGeneration
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # ========================
11
  # File Names & Model Names
12
  # ========================
@@ -90,9 +105,18 @@ if user_query:
90
  if user_query.lower() in pair["question"].lower():
91
  answer = pair["answer"]
92
  break
93
-
 
94
  if not answer:
95
- # Retrieve relevant context
 
 
 
 
 
 
 
 
96
  query_embedding = embed_model.encode([user_query]).astype("float32")
97
  distances, indices = index.search(query_embedding, 3)
98
  pdf_context = "\n".join(chunks[idx] for idx in indices[0])
 
7
  from sentence_transformers import SentenceTransformer
8
  from transformers import pipeline, RagTokenizer, RagRetriever, RagSequenceForGeneration
9
 
10
+ # -----------------------------
11
+ # Firebase Initialization
12
+ # -----------------------------
13
+ import firebase_admin
14
+ from firebase_admin import credentials, firestore
15
+
16
+ @st.cache_resource
17
+ def init_firestore():
18
+ # Replace with the path to your Firebase service account key
19
+ cred = credentials.Certificate("path/to/serviceAccountKey.json")
20
+ firebase_admin.initialize_app(cred)
21
+ return firestore.client()
22
+
23
+ db = init_firestore()
24
+
25
  # ========================
26
  # File Names & Model Names
27
  # ========================
 
105
  if user_query.lower() in pair["question"].lower():
106
  answer = pair["answer"]
107
  break
108
+
109
+ # If no curated answer found, save the question to Firebase and generate an answer.
110
  if not answer:
111
+ try:
112
+ db.collection('llmquestions').add({
113
+ "question": user_query,
114
+ "timestamp": firestore.SERVER_TIMESTAMP
115
+ })
116
+ except Exception as e:
117
+ st.error(f"Error saving question to Firebase: {e}")
118
+
119
+ # Retrieve relevant context from FAISS index
120
  query_embedding = embed_model.encode([user_query]).astype("float32")
121
  distances, indices = index.search(query_embedding, 3)
122
  pdf_context = "\n".join(chunks[idx] for idx in indices[0])
curated_qa_pairs.json CHANGED
@@ -19,6 +19,7 @@
19
  "question": "How does Adagrasib compare to immune checkpoint inhibitors?",
20
  "answer": "The analysis suggests that comparisons between Adagrasib and immune checkpoint inhibitors (or Docetaxel) should account for patients’ prior treatment lines. Direct comparisons may not be relevant in certain subgroups, especially in patients with only one prior line of systemic therapy."
21
  },
 
22
  {
23
  "question": "Why were the PICO exercises carried out by the JCA subgroup in Spring 2024?",
24
  "answer": "They were conducted to test and improve the content of the Guidance on the scoping process by applying it to real cases, ensuring that the resulting guidance would be practical and refined for future assessments."
 
19
  "question": "How does Adagrasib compare to immune checkpoint inhibitors?",
20
  "answer": "The analysis suggests that comparisons between Adagrasib and immune checkpoint inhibitors (or Docetaxel) should account for patients’ prior treatment lines. Direct comparisons may not be relevant in certain subgroups, especially in patients with only one prior line of systemic therapy."
21
  },
22
+
23
  {
24
  "question": "Why were the PICO exercises carried out by the JCA subgroup in Spring 2024?",
25
  "answer": "They were conducted to test and improve the content of the Guidance on the scoping process by applying it to real cases, ensuring that the resulting guidance would be practical and refined for future assessments."