Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import firebase_admin
|
|
3 |
from firebase_admin import credentials
|
4 |
from firebase_admin import firestore
|
5 |
|
6 |
-
|
7 |
@st.experimental_singleton
|
8 |
def get_db_firestore():
|
9 |
cred = credentials.Certificate('test.json')
|
@@ -11,15 +11,32 @@ def get_db_firestore():
|
|
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)
|
@@ -30,27 +47,16 @@ upsert(u'firecollection4', u'firedocument4', u'users4', u'🧠🌳Yggdrasil🌳
|
|
30 |
|
31 |
# its all stored here: https://console.firebase.google.com/u/0/project/clinical-nlp-b9117/firestore/data/~2FStreamlitSpaces
|
32 |
|
33 |
-
|
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 |
|
|
|
55 |
# from https://huggingface.co/spaces/awacke1/RealTimeVoiceASR
|
56 |
selectCollectionDocument(u"ASRCollection", u"ASRDocument")
|
|
|
3 |
from firebase_admin import credentials
|
4 |
from firebase_admin import firestore
|
5 |
|
6 |
+
|
7 |
@st.experimental_singleton
|
8 |
def get_db_firestore():
|
9 |
cred = credentials.Certificate('test.json')
|
|
|
11 |
db = firestore.client()
|
12 |
return db
|
13 |
|
|
|
|
|
|
|
14 |
#add data to the beastie with a generic reusable upsert function
|
15 |
def upsert(collection, document, firefield, first, last, born):
|
16 |
doc_ref = db.collection(collection).document(document)
|
17 |
doc_ref.set({u'firefield': firefield, u'first': first, u'last': last, u'born': born
|
18 |
})
|
19 |
|
20 |
+
#read data back in firecollection
|
21 |
+
def selectCollection(collection):
|
22 |
+
users_ref = db.collection(collection)
|
23 |
+
docs = users_ref.stream()
|
24 |
+
for doc in docs:
|
25 |
+
st.write(f'{doc.id} => {doc.to_dict()}')
|
26 |
+
|
27 |
+
def selectCollectionDocument(collection, document):
|
28 |
+
doc_ref = db.collection(collection).document(document)
|
29 |
+
doc = doc_ref.get()
|
30 |
+
st.write("The id is: ", doc.id)
|
31 |
+
st.write("The contents are: ", doc.to_dict())
|
32 |
+
|
33 |
+
|
34 |
+
st.write("singleton stateful connection to cloud firestore")
|
35 |
+
st.write(u"spin up some awesome 🤯 - episodic and semantic memory 🧠 for AI - here we come")
|
36 |
+
db = get_db_firestore()
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
# perceptual system processing agent that can store model
|
41 |
upsert(u'firecollection', u'firedocument', u'users1', u'Ada', u'Lovelace', 1815)
|
42 |
upsert(u'firecollection', u'firedocument', u'users2', u'Aaron', u'Wacker', 1971)
|
|
|
47 |
|
48 |
# its all stored here: https://console.firebase.google.com/u/0/project/clinical-nlp-b9117/firestore/data/~2FStreamlitSpaces
|
49 |
|
50 |
+
|
|
|
|
|
|
|
|
|
|
|
51 |
selectCollection(u'firecollection')
|
52 |
selectCollection(u'firecollection1')
|
53 |
selectCollection(u'firecollection2')
|
54 |
selectCollection(u'firecollection3')
|
55 |
selectCollection(u'firecollection4')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
selectCollectionDocument(u"firecollection", u"firedocument")
|
57 |
selectCollectionDocument(u"firecollection1", u"firedocument3")
|
58 |
selectCollectionDocument(u"firecollection3", u"firedocument3")
|
59 |
|
60 |
+
|
61 |
# from https://huggingface.co/spaces/awacke1/RealTimeVoiceASR
|
62 |
selectCollectionDocument(u"ASRCollection", u"ASRDocument")
|