Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,8 @@ os.environ["TRAINER_TELEMETRY"]= "0"
|
|
| 17 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
| 18 |
BASETEN_API = os.environ.get("BASETEN_API", None)
|
| 19 |
BASETEN_KEY = os.environ.get("BASETEN_KEY", None)
|
|
|
|
|
|
|
| 20 |
|
| 21 |
st.set_page_config(layout="wide")
|
| 22 |
# Load custom CSS to integrate Bootstrap, Font Awesome, and Google Fonts
|
|
@@ -184,6 +186,64 @@ with right:
|
|
| 184 |
|
| 185 |
# End of Box 4 and fourth Carousel Item
|
| 186 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
hide_default_format = """
|
| 188 |
<style>
|
| 189 |
#MainMenu {visibility: hidden; }
|
|
|
|
| 17 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
| 18 |
BASETEN_API = os.environ.get("BASETEN_API", None)
|
| 19 |
BASETEN_KEY = os.environ.get("BASETEN_KEY", None)
|
| 20 |
+
NOTION_KEY = os.environ.get("NOTION_API_KEY", None)
|
| 21 |
+
NOTION_DB_ID = os.environ.get("NOTION_DB_ID", None)
|
| 22 |
|
| 23 |
st.set_page_config(layout="wide")
|
| 24 |
# Load custom CSS to integrate Bootstrap, Font Awesome, and Google Fonts
|
|
|
|
| 186 |
|
| 187 |
# End of Box 4 and fourth Carousel Item
|
| 188 |
|
| 189 |
+
left, middle, right = st.columns([1,3,1])
|
| 190 |
+
|
| 191 |
+
with middle:
|
| 192 |
+
# Streamlit form for data input
|
| 193 |
+
with st.form(key='data_entry_form'):
|
| 194 |
+
name = st.text_input("Name")
|
| 195 |
+
age = st.number_input("Age", min_value=0)
|
| 196 |
+
location = st.text_input("Location")
|
| 197 |
+
submit_button = st.form_submit_button(label='Submit')
|
| 198 |
+
# Function to add data to Notion
|
| 199 |
+
def add_to_notion(name, age, location):
|
| 200 |
+
new_page = {
|
| 201 |
+
"Name": {
|
| 202 |
+
"title": [
|
| 203 |
+
{
|
| 204 |
+
"text": {
|
| 205 |
+
"content": name
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
]
|
| 209 |
+
},
|
| 210 |
+
"Age": {
|
| 211 |
+
"number": age
|
| 212 |
+
},
|
| 213 |
+
"Location": {
|
| 214 |
+
"rich_text": [
|
| 215 |
+
{
|
| 216 |
+
"text": {
|
| 217 |
+
"content": location
|
| 218 |
+
}
|
| 219 |
+
}
|
| 220 |
+
]
|
| 221 |
+
}
|
| 222 |
+
}
|
| 223 |
+
notion.pages.create(parent={"database_id": database_id}, properties=new_page)
|
| 224 |
+
|
| 225 |
+
# Add data to Notion when form is submitted
|
| 226 |
+
if submit_button:
|
| 227 |
+
add_to_notion(name, age, location)
|
| 228 |
+
st.success("Data submitted to Notion!")
|
| 229 |
+
|
| 230 |
+
# Function to retrieve data from Notion
|
| 231 |
+
def retrieve_data_from_notion():
|
| 232 |
+
query_result = notion.databases.query(database_id=database_id)
|
| 233 |
+
data = []
|
| 234 |
+
for result in query_result["results"]:
|
| 235 |
+
name = result["properties"]["Name"]["title"][0]["text"]["content"]
|
| 236 |
+
age = result["properties"]["Age"]["number"]
|
| 237 |
+
location = result["properties"]["Location"]["rich_text"][0]["text"]["content"]
|
| 238 |
+
data.append({"Name": name, "Age": age, "Location": location})
|
| 239 |
+
|
| 240 |
+
return pd.DataFrame(data)
|
| 241 |
+
|
| 242 |
+
# Display the data in a table
|
| 243 |
+
st.subheader("Stored Data")
|
| 244 |
+
data_df = retrieve_data_from_notion()
|
| 245 |
+
st.table(data_df)
|
| 246 |
+
|
| 247 |
hide_default_format = """
|
| 248 |
<style>
|
| 249 |
#MainMenu {visibility: hidden; }
|