Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,10 +50,10 @@ def delete_records(ids):
|
|
| 50 |
def create_html_component(records):
|
| 51 |
html_template = """
|
| 52 |
<style>
|
| 53 |
-
.
|
| 54 |
font-family: Arial, sans-serif;
|
| 55 |
}
|
| 56 |
-
.
|
| 57 |
display: flex;
|
| 58 |
align-items: center;
|
| 59 |
margin-bottom: 10px;
|
|
@@ -61,41 +61,41 @@ def create_html_component(records):
|
|
| 61 |
border: 1px solid #ddd;
|
| 62 |
border-radius: 5px;
|
| 63 |
}
|
| 64 |
-
.
|
| 65 |
width: 50px;
|
| 66 |
height: 50px;
|
| 67 |
margin-right: 10px;
|
| 68 |
}
|
| 69 |
-
.
|
| 70 |
flex-grow: 1;
|
| 71 |
}
|
| 72 |
-
.
|
| 73 |
font-weight: bold;
|
| 74 |
}
|
| 75 |
-
.
|
| 76 |
font-style: italic;
|
| 77 |
color: #666;
|
| 78 |
}
|
| 79 |
-
.
|
| 80 |
display: flex;
|
| 81 |
align-items: center;
|
| 82 |
}
|
| 83 |
-
.
|
| 84 |
margin-left: 5px;
|
| 85 |
}
|
| 86 |
</style>
|
| 87 |
-
<div class="
|
| 88 |
"""
|
| 89 |
|
| 90 |
for record in records:
|
| 91 |
html_template += f"""
|
| 92 |
-
<div class="
|
| 93 |
-
<img src="https://via.placeholder.com/50" class="
|
| 94 |
-
<div class="
|
| 95 |
-
<div class="
|
| 96 |
-
<div class="
|
| 97 |
</div>
|
| 98 |
-
<div class="
|
| 99 |
<button onclick="Streamlit.setComponentValue({{action: 'extend', id: '{record['id']}'}})">Extend</button>
|
| 100 |
<label>
|
| 101 |
Public
|
|
@@ -113,20 +113,6 @@ def create_html_component(records):
|
|
| 113 |
# Streamlit app
|
| 114 |
st.title("🌟 Cosmos DB Record Management")
|
| 115 |
|
| 116 |
-
# Sidebar
|
| 117 |
-
st.sidebar.title("Suno")
|
| 118 |
-
st.sidebar.markdown("### Home")
|
| 119 |
-
st.sidebar.markdown("### Create")
|
| 120 |
-
st.sidebar.markdown("### Library")
|
| 121 |
-
st.sidebar.markdown("### Explore (BETA)")
|
| 122 |
-
st.sidebar.markdown("---")
|
| 123 |
-
st.sidebar.markdown("2360 credits")
|
| 124 |
-
st.sidebar.markdown("### Subscription")
|
| 125 |
-
st.sidebar.markdown("### What's New? 5")
|
| 126 |
-
st.sidebar.markdown("### Community")
|
| 127 |
-
st.sidebar.markdown("### Help")
|
| 128 |
-
st.sidebar.markdown("### About")
|
| 129 |
-
|
| 130 |
# Login section
|
| 131 |
if 'logged_in' not in st.session_state:
|
| 132 |
st.session_state.logged_in = False
|
|
@@ -147,34 +133,33 @@ else:
|
|
| 147 |
database = client.get_database_client(DATABASE_NAME)
|
| 148 |
container = database.get_container_client(CONTAINER_NAME)
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
# Main Content Area
|
| 151 |
-
st.title("Create")
|
| 152 |
-
st.checkbox("Custom Mode", key="custom_mode")
|
| 153 |
-
st.text_area("Song Description", "a futuristic anime song about a literal banana", key="song_description")
|
| 154 |
-
st.radio("Instrumental", ["Yes", "No"], key="instrumental")
|
| 155 |
-
st.selectbox("Version", ["v1", "v2", "v3"], key="version")
|
| 156 |
-
st.button("Create 🎵")
|
| 157 |
-
|
| 158 |
-
# Fetch and display all records
|
| 159 |
st.subheader("📊 All Records")
|
| 160 |
-
records = fetch_all_records().to_dict('records')
|
| 161 |
|
| 162 |
# Create and render the HTML component
|
| 163 |
-
html_component = create_html_component(records)
|
| 164 |
component_value = html(html_component, height=400)
|
| 165 |
|
| 166 |
# Handle component interactions
|
| 167 |
if component_value:
|
| 168 |
-
action = component_value
|
| 169 |
-
record_id = component_value
|
| 170 |
-
if action
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
|
|
|
| 178 |
|
| 179 |
# Add delete and download buttons
|
| 180 |
col1, col2 = st.columns(2)
|
|
@@ -183,7 +168,7 @@ else:
|
|
| 183 |
st.warning("Deletion functionality needs to be implemented for the new component")
|
| 184 |
|
| 185 |
with col2:
|
| 186 |
-
if st.download_button("📥 Download Data",
|
| 187 |
st.success("Data downloaded successfully!")
|
| 188 |
|
| 189 |
# Input fields for new record
|
|
@@ -248,4 +233,4 @@ else:
|
|
| 248 |
|
| 249 |
# Preview section
|
| 250 |
st.markdown("---")
|
| 251 |
-
st.markdown("### Select a
|
|
|
|
| 50 |
def create_html_component(records):
|
| 51 |
html_template = """
|
| 52 |
<style>
|
| 53 |
+
.record-list {
|
| 54 |
font-family: Arial, sans-serif;
|
| 55 |
}
|
| 56 |
+
.record-item {
|
| 57 |
display: flex;
|
| 58 |
align-items: center;
|
| 59 |
margin-bottom: 10px;
|
|
|
|
| 61 |
border: 1px solid #ddd;
|
| 62 |
border-radius: 5px;
|
| 63 |
}
|
| 64 |
+
.record-image {
|
| 65 |
width: 50px;
|
| 66 |
height: 50px;
|
| 67 |
margin-right: 10px;
|
| 68 |
}
|
| 69 |
+
.record-details {
|
| 70 |
flex-grow: 1;
|
| 71 |
}
|
| 72 |
+
.record-title {
|
| 73 |
font-weight: bold;
|
| 74 |
}
|
| 75 |
+
.record-description {
|
| 76 |
font-style: italic;
|
| 77 |
color: #666;
|
| 78 |
}
|
| 79 |
+
.record-actions {
|
| 80 |
display: flex;
|
| 81 |
align-items: center;
|
| 82 |
}
|
| 83 |
+
.record-actions button {
|
| 84 |
margin-left: 5px;
|
| 85 |
}
|
| 86 |
</style>
|
| 87 |
+
<div class="record-list">
|
| 88 |
"""
|
| 89 |
|
| 90 |
for record in records:
|
| 91 |
html_template += f"""
|
| 92 |
+
<div class="record-item">
|
| 93 |
+
<img src="https://via.placeholder.com/50" class="record-image" alt="Record thumbnail">
|
| 94 |
+
<div class="record-details">
|
| 95 |
+
<div class="record-title">{record['name']}</div>
|
| 96 |
+
<div class="record-description">{record['document']}</div>
|
| 97 |
</div>
|
| 98 |
+
<div class="record-actions">
|
| 99 |
<button onclick="Streamlit.setComponentValue({{action: 'extend', id: '{record['id']}'}})">Extend</button>
|
| 100 |
<label>
|
| 101 |
Public
|
|
|
|
| 113 |
# Streamlit app
|
| 114 |
st.title("🌟 Cosmos DB Record Management")
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
# Login section
|
| 117 |
if 'logged_in' not in st.session_state:
|
| 118 |
st.session_state.logged_in = False
|
|
|
|
| 133 |
database = client.get_database_client(DATABASE_NAME)
|
| 134 |
container = database.get_container_client(CONTAINER_NAME)
|
| 135 |
|
| 136 |
+
# Fetch all records
|
| 137 |
+
records_df = fetch_all_records()
|
| 138 |
+
|
| 139 |
+
# Sidebar for data editing
|
| 140 |
+
st.sidebar.title("Edit Records")
|
| 141 |
+
edited_df = st.sidebar.data_editor(records_df, num_rows="dynamic", key="sidebar_editor")
|
| 142 |
+
|
| 143 |
# Main Content Area
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
st.subheader("📊 All Records")
|
|
|
|
| 145 |
|
| 146 |
# Create and render the HTML component
|
| 147 |
+
html_component = create_html_component(edited_df.to_dict('records'))
|
| 148 |
component_value = html(html_component, height=400)
|
| 149 |
|
| 150 |
# Handle component interactions
|
| 151 |
if component_value:
|
| 152 |
+
action = component_value.get('action')
|
| 153 |
+
record_id = component_value.get('id')
|
| 154 |
+
if action and record_id:
|
| 155 |
+
if action == 'extend':
|
| 156 |
+
st.write(f"Extending record {record_id}")
|
| 157 |
+
elif action == 'toggle_public':
|
| 158 |
+
st.write(f"Toggling public status for record {record_id}")
|
| 159 |
+
elif action == 'like':
|
| 160 |
+
st.write(f"Liked record {record_id}")
|
| 161 |
+
elif action == 'dislike':
|
| 162 |
+
st.write(f"Disliked record {record_id}")
|
| 163 |
|
| 164 |
# Add delete and download buttons
|
| 165 |
col1, col2 = st.columns(2)
|
|
|
|
| 168 |
st.warning("Deletion functionality needs to be implemented for the new component")
|
| 169 |
|
| 170 |
with col2:
|
| 171 |
+
if st.download_button("📥 Download Data", edited_df.to_csv(index=False), "cosmos_db_data.csv", "text/csv"):
|
| 172 |
st.success("Data downloaded successfully!")
|
| 173 |
|
| 174 |
# Input fields for new record
|
|
|
|
| 233 |
|
| 234 |
# Preview section
|
| 235 |
st.markdown("---")
|
| 236 |
+
st.markdown("### Select a record to preview.")
|