awacke1 commited on
Commit
f075917
·
verified ·
1 Parent(s): a94dc4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -51
app.py CHANGED
@@ -50,10 +50,10 @@ def delete_records(ids):
50
  def create_html_component(records):
51
  html_template = """
52
  <style>
53
- .song-list {
54
  font-family: Arial, sans-serif;
55
  }
56
- .song-item {
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
- .song-image {
65
  width: 50px;
66
  height: 50px;
67
  margin-right: 10px;
68
  }
69
- .song-details {
70
  flex-grow: 1;
71
  }
72
- .song-title {
73
  font-weight: bold;
74
  }
75
- .song-description {
76
  font-style: italic;
77
  color: #666;
78
  }
79
- .song-actions {
80
  display: flex;
81
  align-items: center;
82
  }
83
- .song-actions button {
84
  margin-left: 5px;
85
  }
86
  </style>
87
- <div class="song-list">
88
  """
89
 
90
  for record in records:
91
  html_template += f"""
92
- <div class="song-item">
93
- <img src="https://via.placeholder.com/50" class="song-image" alt="Song thumbnail">
94
- <div class="song-details">
95
- <div class="song-title">{record['name']}</div>
96
- <div class="song-description">{record['document']}</div>
97
  </div>
98
- <div class="song-actions">
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['action']
169
- record_id = component_value['id']
170
- if action == 'extend':
171
- st.write(f"Extending record {record_id}")
172
- elif action == 'toggle_public':
173
- st.write(f"Toggling public status for record {record_id}")
174
- elif action == 'like':
175
- st.write(f"Liked record {record_id}")
176
- elif action == 'dislike':
177
- st.write(f"Disliked record {record_id}")
 
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", pd.DataFrame(records).to_csv(index=False), "cosmos_db_data.csv", "text/csv"):
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 song to preview.")
 
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.")