Create a streamlit app that contains a catalog of all snowflake assets
To upload files, please first save the app
from sqlalchemy import Column, Integer, String
import pandas as pd
from sqlalchemy import create_engine
from sqlalchemy.orm import Session, DeclarativeBase
class Base(DeclarativeBase):
pass
# Placeholder for Snowflake assets
class SnowflakeAsset(Base):
__tablename__ = 'snowflake_assets'
id = Column(Integer, primary_key=True)
name = Column(String)
description = Column(String)
# Create the SQLite engine
engine = create_engine('sqlite:///snowflake_assets.db')
# Create tables
Base.metadata.create_all(bind=engine)
# Function to add sample data (for demonstration purposes)
def add_sample_data():
assets = [
{'name': 'Asset 1', 'description': 'Description for Asset 1'},
{'name': 'Asset 2', 'description': 'Description for Asset 2'},
{'name': 'Asset 3', 'description': 'Description for Asset 3'},
]
with Session(engine) as session:
for asset in assets:
session.add(SnowflakeAsset(**asset))
session.commit()
# Uncomment the next line to add sample data once
#add_sample_data()
st.title('Snowflake Assets Catalog')
# Load data from the database
with Session(engine) as session:
assets = session.query(SnowflakeAsset).all()
asset_data = [{'ID': asset.id, 'Name': asset.name, 'Description': asset.description} for asset in assets]
df = pd.DataFrame(asset_data)
# Display the assets in a table
if df.empty:
st.write('No assets found in the catalog.')
else:
st.table(df)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?