CoolFace
Apppublic

awacke1/FirestorePersistence

sourceHugging Facemitupdated 4y agoView on Hugging Face
2likes
app.py85 linesDownload Raw Back to root
1import streamlit as st2import firebase_admin3from firebase_admin import credentials4from firebase_admin import firestore5from datetime import datetime6 7now = datetime.now() # current date and time8year = now.strftime("%Y")9st.write("year:", year)10month = now.strftime("%m")11st.write("month:", month)12day = now.strftime("%d")13st.write("day:", day)14time = now.strftime("%H:%M:%S")15st.write("time:", time)16date_time = now.strftime("%m/%d/%Y, %H:%M:%S")17st.write("date and time:",date_time)	18 19@st.experimental_singleton20def get_db_firestore():21    cred = credentials.Certificate('test.json')22    firebase_admin.initialize_app(cred, {'projectId': u'clinical-nlp-b9117',})23    db = firestore.client()24    return db25 26#add data to the beastie with a generic reusable upsert function27def upsert(collection, document, firefield, first, last, born):28    doc_ref = db.collection(collection).document(document)29    doc_ref.set({u'firefield': firefield, u'first': first, u'last': last, u'born': born30})31 32#read data back in firecollection33def selectCollection(collection):34    users_ref = db.collection(collection)35    docs = users_ref.stream()36    for doc in docs:37        st.write(f'{doc.id} => {doc.to_dict()}')38        39def selectCollectionDocument(collection, document):40    doc_ref = db.collection(collection).document(document)41    doc = doc_ref.get()42    st.write("The id is: ", doc.id)43    st.write("The contents are: ", doc.to_dict())44    45#add data to the beastie with a generic reusable upsert function46def upsertoftheminute(collection, document, firefield, first, last, born):47    date_time = now.strftime("%m/%d/%Y, %H:%M")48    doc_ref = db.collection(collection).document(document)49    doc_ref.set({u'firefield': firefield, u'first': first, u'last': last, u'born': date_time,})50 51 52st.write("singleton stateful connection to cloud firestore")53st.write(u"spin up some awesome 🤯 - episodic and semantic memory 🧠 for AI - here we come")54db = get_db_firestore()55 56# perceptual system processing agent that can store model 57upsert(u'firecollection', u'firedocument', u'users1', u'Ada', u'Lovelace', 1815)58upsert(u'firecollection', u'firedocument', u'users2', u'Aaron', u'Wacker', 1971)59upsert(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)60upsert(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)61upsert(u'firecollection3', u'firedocument3', u'users3', u'😶‍🌫️ 🤯Engineering Consciousness🧠  😶‍🌫️', u'https://youtu.be/rIpUf-Vy2JA?list=PLHgX2IExbFouJoqEr8JMF5MbZSbyC91-L&t=3622', 2022)62upsert(u'firecollection4', u'firedocument4', u'users4', u'🧠🌳Yggdrasil🌳🧠', u'https://github.com/AaronCWacker/Yggdrasil', 2022)63 64# its all stored here: https://console.firebase.google.com/u/0/project/clinical-nlp-b9117/firestore/data/~2FStreamlitSpaces65 66 67selectCollection(u'firecollection')68selectCollection(u'firecollection1')69selectCollection(u'firecollection2')70selectCollection(u'firecollection3')71selectCollection(u'firecollection4')72selectCollectionDocument(u"firecollection", u"firedocument")73selectCollectionDocument(u"firecollection1", u"firedocument3")74selectCollectionDocument(u"firecollection3", u"firedocument3")75 76 77# from https://huggingface.co/spaces/awacke1/RealTimeVoiceASR78selectCollectionDocument(u"ASRCollection", u"ASRDocument")79 80 81upsert(u'firecollection4', u'firedocument4', u'users4', u'🧠🌳Yggdrasil🌳🧠', u'https://github.com/AaronCWacker/Yggdrasil', 2022)82 83# intent - upsert at granularity of minute an aggregate document representing fields used in recent activity to replay shared state memory events84upsertoftheminute(u'TimeSeries', u'DocumentofMinute', u'TestUser1', u'🧠🌳Yggdrasil🌳🧠', u'https://huggingface.co/spaces/awacke1/FirestorePersistence', 2022)85selectCollectionDocument(u"TimeSeries", u"DocumentofMinute")