awacke1 commited on
Commit
a625e7e
1 Parent(s): 3c275e5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import firebase_admin
3
+ from firebase_admin import credentials
4
+ from firebase_admin import firestore
5
+
6
+ st.write("singleton stateful connection to cloud firestore")
7
+ @st.experimental_singleton
8
+ def get_db_firestore():
9
+ cred = credentials.Certificate('test.json')
10
+ firebase_admin.initialize_app(cred, {'projectId': u'clinical-nlp-b9117',})
11
+ db = firestore.client()
12
+ return db
13
+
14
+ st.write(u"spin up some awesome 🤯 - episodic and semantic memory 🧠 for AI - here we come")
15
+ db = get_db_firestore()
16
+
17
+ #add data to the beastie with a generic reusable upsert function
18
+ def upsert(collection, document, firefield, first, last, born):
19
+ doc_ref = db.collection(collection).document(document)
20
+ doc_ref.set({u'firefield': firefield, u'first': first, u'last': last, u'born': born
21
+ })
22
+
23
+ # perceptual system processing agent that can store model
24
+ upsert(u'firecollection', u'firedocument', u'users1', u'Ada', u'Lovelace', 1815)
25
+ upsert(u'firecollection', u'firedocument', u'users2', u'Aaron', u'Wacker', 1971)
26
+ upsert(u'firecollection1', u'firedocument3', u'users1', u'2022 - AI, Cognitive and Neuroscience to Assist and Augment Behavioral and Medical Health', u'https://www.youtube.com/watch?v=lvh3g7eszVQ&list=PLHgX2IExbFouJoqEr8JMF5MbZSbyC91-L', 2022)
27
+ upsert(u'firecollection2', u'firedocument2', u'users2', u'2022 - AI art sci-fi movies and stories 🎭🎞️🍿 by Aaron Wacker 🎬 🧠 🎨', u'https://www.youtube.com/playlist?list=PLHgX2IExbFotUCOCZgpj-5HZBzXOpFMYc', 2022)
28
+ upsert(u'firecollection3', u'firedocument3', u'users3', u'😶‍🌫️ 🤯Engineering Consciousness🧠 😶‍🌫️', u'https://youtu.be/rIpUf-Vy2JA?list=PLHgX2IExbFouJoqEr8JMF5MbZSbyC91-L&t=3622', 2022)
29
+ upsert(u'firecollection4', u'firedocument4', u'users4', u'🧠🌳Yggdrasil🌳🧠', u'https://github.com/AaronCWacker/Yggdrasil', 2022)
30
+
31
+ # its all stored here: https://console.firebase.google.com/u/0/project/clinical-nlp-b9117/firestore/data/~2FStreamlitSpaces
32
+
33
+ #read data back in firecollection
34
+ def selectCollection(collection):
35
+ users_ref = db.collection(collection)
36
+ docs = users_ref.stream()
37
+ for doc in docs:
38
+ st.write(f'{doc.id} => {doc.to_dict()}')
39
+ selectCollection(u'firecollection')
40
+ selectCollection(u'firecollection1')
41
+ selectCollection(u'firecollection2')
42
+ selectCollection(u'firecollection3')
43
+ selectCollection(u'firecollection4')
44
+
45
+ def selectCollectionDocument(collection, document):
46
+ doc_ref = db.collection(collection).document(document)
47
+ doc = doc_ref.get()
48
+ st.write("The id is: ", doc.id)
49
+ st.write("The contents are: ", doc.to_dict())
50
+
51
+ selectCollectionDocument(u"firecollection", u"firedocument")
52
+ selectCollectionDocument(u"firecollection1", u"firedocument3")
53
+ selectCollectionDocument(u"firecollection3", u"firedocument3")
54
+