Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,11 +7,6 @@ import json
|
|
| 7 |
import os
|
| 8 |
import pandas as pd
|
| 9 |
import pytz
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
import random
|
| 16 |
import re
|
| 17 |
import shutil
|
|
@@ -1152,7 +1147,7 @@ def main():
|
|
| 1152 |
|
| 1153 |
if documents_to_display:
|
| 1154 |
# 🎨 View options - "Different strokes for different folks"
|
| 1155 |
-
view_options = ['Show as Markdown', 'Show as Code Editor', 'Show as Run AI', 'Clone Document', 'New Record']
|
| 1156 |
selected_view = st.sidebar.selectbox("Select Viewer/Editor", view_options, index=2)
|
| 1157 |
|
| 1158 |
|
|
@@ -1295,6 +1290,110 @@ def main():
|
|
| 1295 |
num_cols = len(documents_to_display)
|
| 1296 |
cols = st.columns(num_cols)
|
| 1297 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1298 |
for idx, (col, doc) in enumerate(zip(cols, documents_to_display)):
|
| 1299 |
with col:
|
| 1300 |
# ID and Name fields
|
|
@@ -1314,8 +1413,6 @@ def main():
|
|
| 1314 |
# Save and AI operations columns
|
| 1315 |
|
| 1316 |
|
| 1317 |
-
# Video Generator call - the video generation UI for container:
|
| 1318 |
-
add_video_generation_ui(container)
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
|
|
|
| 7 |
import os
|
| 8 |
import pandas as pd
|
| 9 |
import pytz
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
import random
|
| 11 |
import re
|
| 12 |
import shutil
|
|
|
|
| 1147 |
|
| 1148 |
if documents_to_display:
|
| 1149 |
# 🎨 View options - "Different strokes for different folks"
|
| 1150 |
+
view_options = ['Show as Markdown', 'Show as Code Editor', 'Show as Run AI', 'Show as Run Media AI', 'Clone Document', 'New Record']
|
| 1151 |
selected_view = st.sidebar.selectbox("Select Viewer/Editor", view_options, index=2)
|
| 1152 |
|
| 1153 |
|
|
|
|
| 1290 |
num_cols = len(documents_to_display)
|
| 1291 |
cols = st.columns(num_cols)
|
| 1292 |
|
| 1293 |
+
for idx, (col, doc) in enumerate(zip(cols, documents_to_display)):
|
| 1294 |
+
with col:
|
| 1295 |
+
# ID and Name fields
|
| 1296 |
+
editable_id = st.text_input("ID", value=doc.get('id', ''), key=f'edit_id_{idx}')
|
| 1297 |
+
editable_name = st.text_input("Name", value=doc.get('name', ''), key=f'edit_name_{idx}')
|
| 1298 |
+
|
| 1299 |
+
# Create editable document copy without id and name
|
| 1300 |
+
editable_doc = doc.copy()
|
| 1301 |
+
editable_doc.pop('id', None)
|
| 1302 |
+
editable_doc.pop('name', None)
|
| 1303 |
+
|
| 1304 |
+
doc_str = st.text_area("Document Content (in JSON format)",
|
| 1305 |
+
value=json.dumps(editable_doc, indent=2),
|
| 1306 |
+
height=300,
|
| 1307 |
+
key=f'doc_str_{idx}')
|
| 1308 |
+
|
| 1309 |
+
if st.button("🤖 Run AI", key=f'run_with_ai_button_{idx}'):
|
| 1310 |
+
# Your existing AI processing code here
|
| 1311 |
+
values_with_space = []
|
| 1312 |
+
def extract_values2(obj):
|
| 1313 |
+
if isinstance(obj, dict):
|
| 1314 |
+
for k, v in obj.items():
|
| 1315 |
+
extract_values2(v)
|
| 1316 |
+
elif isinstance(obj, list):
|
| 1317 |
+
for item in obj:
|
| 1318 |
+
extract_values2(item)
|
| 1319 |
+
elif isinstance(obj, str):
|
| 1320 |
+
if ' ' in obj:
|
| 1321 |
+
values_with_space.append(obj)
|
| 1322 |
+
|
| 1323 |
+
extract_values2(doc)
|
| 1324 |
+
for term in values_with_space:
|
| 1325 |
+
display_glossary_entity(term)
|
| 1326 |
+
search_glossary(term)
|
| 1327 |
+
|
| 1328 |
+
if st.button("💾 Save Changes", key=f'save_runai_{idx}'):
|
| 1329 |
+
try:
|
| 1330 |
+
updated_doc = json.loads(doc_str)
|
| 1331 |
+
# Reinsert ID and name from editable fields
|
| 1332 |
+
updated_doc['id'] = editable_id
|
| 1333 |
+
updated_doc['name'] = editable_name
|
| 1334 |
+
response = container.upsert_item(body=updated_doc)
|
| 1335 |
+
if response:
|
| 1336 |
+
st.success(f"Document {updated_doc['id']} saved successfully.")
|
| 1337 |
+
st.session_state.selected_document_id = updated_doc['id']
|
| 1338 |
+
st.rerun()
|
| 1339 |
+
except Exception as e:
|
| 1340 |
+
st.error(f"Error saving document: {str(e)}")
|
| 1341 |
+
|
| 1342 |
+
|
| 1343 |
+
# File Editor (When you need to tweak things ✏️)
|
| 1344 |
+
if hasattr(st.session_state, 'current_file'):
|
| 1345 |
+
st.subheader(f"Editing: {st.session_state.current_file} 🛠")
|
| 1346 |
+
new_content = st.text_area("File Content ✏️:", st.session_state.file_content, height=300)
|
| 1347 |
+
if st.button("Save Changes 💾"):
|
| 1348 |
+
with open(st.session_state.current_file, 'w', encoding='utf-8') as file:
|
| 1349 |
+
file.write(new_content)
|
| 1350 |
+
st.success("File updated successfully! 🎉")
|
| 1351 |
+
|
| 1352 |
+
# Image Gallery (For your viewing pleasure 📸)
|
| 1353 |
+
st.subheader("Image Gallery 🖼")
|
| 1354 |
+
image_files = glob.glob("*.png") + glob.glob("*.jpg") + glob.glob("*.jpeg")
|
| 1355 |
+
image_cols = st.slider("Gallery Columns 🖼", min_value=1, max_value=15, value=5)
|
| 1356 |
+
cols = st.columns(image_cols)
|
| 1357 |
+
for idx, image_file in enumerate(image_files):
|
| 1358 |
+
with cols[idx % image_cols]:
|
| 1359 |
+
img = Image.open(image_file)
|
| 1360 |
+
#st.image(img, caption=image_file, use_column_width=True)
|
| 1361 |
+
st.image(img, use_column_width=True)
|
| 1362 |
+
display_glossary_entity(os.path.splitext(image_file)[0])
|
| 1363 |
+
|
| 1364 |
+
# Video Gallery (Let’s roll the tapes 🎬)
|
| 1365 |
+
st.subheader("Video Gallery 🎥")
|
| 1366 |
+
video_files = glob.glob("*.mp4")
|
| 1367 |
+
video_cols = st.slider("Gallery Columns 🎬", min_value=1, max_value=5, value=3)
|
| 1368 |
+
cols = st.columns(video_cols)
|
| 1369 |
+
for idx, video_file in enumerate(video_files):
|
| 1370 |
+
with cols[idx % video_cols]:
|
| 1371 |
+
st.markdown(get_video_html(video_file, width="100%"), unsafe_allow_html=True)
|
| 1372 |
+
display_glossary_entity(os.path.splitext(video_file)[0])
|
| 1373 |
+
|
| 1374 |
+
# Audio Gallery (Tunes for the mood 🎶)
|
| 1375 |
+
st.subheader("Audio Gallery 🎧")
|
| 1376 |
+
audio_files = glob.glob("*.mp3") + glob.glob("*.wav")
|
| 1377 |
+
audio_cols = st.slider("Gallery Columns 🎶", min_value=1, max_value=15, value=5)
|
| 1378 |
+
cols = st.columns(audio_cols)
|
| 1379 |
+
for idx, audio_file in enumerate(audio_files):
|
| 1380 |
+
with cols[idx % audio_cols]:
|
| 1381 |
+
st.markdown(get_audio_html(audio_file, width="100%"), unsafe_allow_html=True)
|
| 1382 |
+
display_glossary_entity(os.path.splitext(audio_file)[0])
|
| 1383 |
+
|
| 1384 |
+
|
| 1385 |
+
|
| 1386 |
+
elif selected_view == 'Show as Run Media AI':
|
| 1387 |
+
Label = '#### ✏️ Run AI with wisdom, save with precision'
|
| 1388 |
+
st.markdown(Label)
|
| 1389 |
+
num_cols = len(documents_to_display)
|
| 1390 |
+
cols = st.columns(num_cols)
|
| 1391 |
+
|
| 1392 |
+
# Video Generator call - the video generation UI for container:
|
| 1393 |
+
add_video_generation_ui(container)
|
| 1394 |
+
|
| 1395 |
+
|
| 1396 |
+
|
| 1397 |
for idx, (col, doc) in enumerate(zip(cols, documents_to_display)):
|
| 1398 |
with col:
|
| 1399 |
# ID and Name fields
|
|
|
|
| 1413 |
# Save and AI operations columns
|
| 1414 |
|
| 1415 |
|
|
|
|
|
|
|
| 1416 |
|
| 1417 |
|
| 1418 |
|