From e43145a4e0af2a7facdd952d5a4ac6a94b01ce38 Mon Sep 17 00:00:00 2001 From: Sudhendra Date: Thu, 17 Oct 2024 03:01:48 -0400 Subject: [PATCH] tracking --- .gitignore | 1 + medapp.py | 31 +++++++++++++++++++++++++++++-- requirements.txt | 3 ++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 4c49bd7..e06ec21 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .env +firebase-key.json \ No newline at end of file diff --git a/medapp.py b/medapp.py index d6d9c17..1d26866 100644 --- a/medapp.py +++ b/medapp.py @@ -166,9 +166,32 @@ def build_mindmap(query: str, answer: str, related_topics: List[str]) -> Tuple[L return nodes, edges +# Get Firebase credentials +def get_firebase_key(): + # Try to get the key from Streamlit secrets first (for deployed app) + if 'firebase_key' in st.secrets: + return json.loads(st.secrets['firebase_key']) + + # If not in secrets, try to get from environment variable (for local development) + firebase_key_path = os.getenv("FIREBASE_KEY_PATH") + if firebase_key_path and os.path.exists(firebase_key_path): + with open(firebase_key_path, 'r') as f: + return json.load(f) + + # If neither method works, raise an error + raise ValueError("Firebase key not found in secrets or local file.") + # Main Streamlit app def main(): - streamlit_analytics.start_tracking() + # Get Firebase credentials + firebase_key = get_firebase_key() + firebase_collection = os.getenv("FIREBASE_COLLECTION", "counts") + + # Start tracking with Firebase Firestore + streamlit_analytics.start_tracking( + firestore_key_json=firebase_key, + firestore_collection_name=firebase_collection + ) st.title("Step 1 Buddy") @@ -264,7 +287,11 @@ def main(): disclosures_content = f.read() st.markdown(disclosures_content) - streamlit_analytics.stop_tracking(save_to_json=os.path.join("tracking", "tracking_data.json")) + # Stop tracking at the end of the main function + streamlit_analytics.stop_tracking( + firestore_key_json=firebase_key, + firestore_collection_name=firebase_collection + ) if __name__ == "__main__": main() diff --git a/requirements.txt b/requirements.txt index a4c48b0..7e465bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,5 @@ sentence-transformers faiss-cpu streamlit_analytics python-dotenv -streamlit-agraph \ No newline at end of file +streamlit-agraph +firebase-admin \ No newline at end of file