-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlit_app.py
33 lines (27 loc) · 944 Bytes
/
streamlit_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import streamlit as st
from google.cloud import firestore
from google.oauth2 import service_account
#db = firestore.Client.from_service_account_json("firestore-key.json")
import json
key_dict = json.loads(st.secrets["textkey"])
creds = service_account.Credentials.from_service_account_info(key_dict)
db = firestore.Client(credentials=creds)
# Streamlit widgets to let a user create a new post
title = st.text_input("Post title")
url = st.text_input("Post url")
submit = st.button("Submit new post")
# Once the user has submitted, upload it to the database
if title and url and submit:
doc_ref = db.collection("posts").document(title)
doc_ref.set({
"title": title,
"url": url
})
# And then render each post, using some light Markdown
posts_ref = db.collection("posts")
for doc in posts_ref.stream():
post = doc.to_dict()
title = post["title"]
url = post["url"]
st.subheader(f"Post: {title}")
st.write(f":link: [{url}]({url})")