Spaces:
Build error
Build error
| import streamlit as st | |
| import firebase_admin | |
| from firebase_admin import credentials | |
| from firebase_admin import firestore | |
| from datetime import datetime | |
| now = datetime.now() # current date and time | |
| year = now.strftime("%Y") | |
| st.write("year:", year) | |
| month = now.strftime("%m") | |
| st.write("month:", month) | |
| day = now.strftime("%d") | |
| st.write("day:", day) | |
| time = now.strftime("%H:%M:%S") | |
| st.write("time:", time) | |
| date_time = now.strftime("%m/%d/%Y, %H:%M:%S") | |
| st.write("date and time:",date_time) | |
| def get_db_firestore(): | |
| cred = credentials.Certificate('test.json') | |
| firebase_admin.initialize_app(cred, {'projectId': u'clinical-nlp-b9117',}) | |
| db = firestore.client() | |
| return db | |
| #add data to the beastie with a generic reusable upsert function | |
| def upsert(collection, document, firefield, first, last, born): | |
| doc_ref = db.collection(collection).document(document) | |
| doc_ref.set({u'firefield': firefield, u'first': first, u'last': last, u'born': born | |
| }) | |
| #read data back in firecollection | |
| def selectCollection(collection): | |
| users_ref = db.collection(collection) | |
| docs = users_ref.stream() | |
| for doc in docs: | |
| st.write(f'{doc.id} => {doc.to_dict()}') | |
| def selectCollectionDocument(collection, document): | |
| doc_ref = db.collection(collection).document(document) | |
| doc = doc_ref.get() | |
| st.write("The id is: ", doc.id) | |
| st.write("The contents are: ", doc.to_dict()) | |
| #add data to the beastie with a generic reusable upsert function | |
| def upsertoftheminute(collection, document, firefield, first, last, born): | |
| date_time = now.strftime("%m/%d/%Y, %H:%M") | |
| doc_ref = db.collection(collection).document(document) | |
| doc_ref.set({u'firefield': firefield, u'first': first, u'last': last, u'born': date_time,}) | |
| st.write("singleton stateful connection to cloud firestore") | |
| st.write(u"spin up some awesome 🤯 - episodic and semantic memory 🧠 for AI - here we come") | |
| db = get_db_firestore() | |
| # perceptual system processing agent that can store model | |
| upsert(u'firecollection', u'firedocument', u'users1', u'Ada', u'Lovelace', 1815) | |
| upsert(u'firecollection', u'firedocument', u'users2', u'Aaron', u'Wacker', 1971) | |
| 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) | |
| 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) | |
| upsert(u'firecollection3', u'firedocument3', u'users3', u'😶🌫️ 🤯Engineering Consciousness🧠 😶🌫️', u'https://youtu.be/rIpUf-Vy2JA?list=PLHgX2IExbFouJoqEr8JMF5MbZSbyC91-L&t=3622', 2022) | |
| upsert(u'firecollection4', u'firedocument4', u'users4', u'🧠🌳Yggdrasil🌳🧠', u'https://github.com/AaronCWacker/Yggdrasil', 2022) | |
| # its all stored here: https://console.firebase.google.com/u/0/project/clinical-nlp-b9117/firestore/data/~2FStreamlitSpaces | |
| selectCollection(u'firecollection') | |
| selectCollection(u'firecollection1') | |
| selectCollection(u'firecollection2') | |
| selectCollection(u'firecollection3') | |
| selectCollection(u'firecollection4') | |
| selectCollectionDocument(u"firecollection", u"firedocument") | |
| selectCollectionDocument(u"firecollection1", u"firedocument3") | |
| selectCollectionDocument(u"firecollection3", u"firedocument3") | |
| # from https://huggingface.co/spaces/awacke1/RealTimeVoiceASR | |
| selectCollectionDocument(u"ASRCollection", u"ASRDocument") | |
| upsert(u'firecollection4', u'firedocument4', u'users4', u'🧠🌳Yggdrasil🌳🧠', u'https://github.com/AaronCWacker/Yggdrasil', 2022) | |
| # intent - upsert at granularity of minute an aggregate document representing fields used in recent activity to replay shared state memory events | |
| upsertoftheminute(u'TimeSeries', u'DocumentofMinute', u'TestUser1', u'🧠🌳Yggdrasil🌳🧠', u'https://huggingface.co/spaces/awacke1/FirestorePersistence', 2022) | |
| selectCollectionDocument(u"TimeSeries", u"DocumentofMinute") |