Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -823,9 +823,79 @@ def main():
|
|
823 |
st.rerun()
|
824 |
except Exception as e:
|
825 |
st.error(f"Error deleting document: {str(e)}")
|
|
|
826 |
|
827 |
|
828 |
elif selected_view == 'Show as Run AI':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
829 |
Label = '#### ✏️ Run AI with wisdom, save with precision'
|
830 |
st.markdown(Label)
|
831 |
num_cols = len(documents_to_display)
|
|
|
823 |
st.rerun()
|
824 |
except Exception as e:
|
825 |
st.error(f"Error deleting document: {str(e)}")
|
826 |
+
|
827 |
|
828 |
|
829 |
elif selected_view == 'Show as Run AI':
|
830 |
+
Label = '#### ✏️ Run AI with wisdom, save with precision'
|
831 |
+
st.markdown(Label)
|
832 |
+
|
833 |
+
for idx, doc in enumerate(documents_to_display):
|
834 |
+
st.divider() # Visual separator between documents
|
835 |
+
|
836 |
+
# ID and Name fields in a smaller container
|
837 |
+
col1, col2 = st.columns(2)
|
838 |
+
with col1:
|
839 |
+
editable_id = st.text_input("ID", value=doc.get('id', ''), key=f'edit_id_{idx}')
|
840 |
+
with col2:
|
841 |
+
editable_name = st.text_input("Name", value=doc.get('name', ''), key=f'edit_name_{idx}')
|
842 |
+
|
843 |
+
# Create editable document copy without id and name
|
844 |
+
editable_doc = doc.copy()
|
845 |
+
editable_doc.pop('id', None)
|
846 |
+
editable_doc.pop('name', None)
|
847 |
+
|
848 |
+
# Document content using full width
|
849 |
+
doc_str = st.text_area("Document Content (in JSON format)",
|
850 |
+
value=json.dumps(editable_doc, indent=2),
|
851 |
+
height=300,
|
852 |
+
key=f'doc_str_{idx}')
|
853 |
+
|
854 |
+
# Action buttons in a row
|
855 |
+
col_save, col_ai, col_delete = st.columns([1, 1, 1])
|
856 |
+
|
857 |
+
with col_save:
|
858 |
+
if st.button("💾 Save Changes", key=f'save_runai_{idx}'):
|
859 |
+
try:
|
860 |
+
updated_doc = json.loads(doc_str)
|
861 |
+
# Reinsert ID and name from editable fields
|
862 |
+
updated_doc['id'] = editable_id
|
863 |
+
updated_doc['name'] = editable_name
|
864 |
+
response = container.upsert_item(body=updated_doc)
|
865 |
+
if response:
|
866 |
+
st.success(f"Document {updated_doc['id']} saved successfully.")
|
867 |
+
st.session_state.selected_document_id = updated_doc['id']
|
868 |
+
st.rerun()
|
869 |
+
except Exception as e:
|
870 |
+
st.error(f"Error saving document: {str(e)}")
|
871 |
+
|
872 |
+
with col_ai:
|
873 |
+
if st.button("🤖 Run AI", key=f'run_with_ai_button_{idx}'):
|
874 |
+
# AI output will use full width of the page
|
875 |
+
values_with_space = []
|
876 |
+
def extract_values2(obj):
|
877 |
+
if isinstance(obj, dict):
|
878 |
+
for k, v in obj.items():
|
879 |
+
extract_values2(v)
|
880 |
+
elif isinstance(obj, list):
|
881 |
+
for item in obj:
|
882 |
+
extract_values2(item)
|
883 |
+
elif isinstance(obj, str):
|
884 |
+
if ' ' in obj:
|
885 |
+
values_with_space.append(obj)
|
886 |
+
|
887 |
+
extract_values2(doc)
|
888 |
+
# AI results will use full page width
|
889 |
+
with st.container():
|
890 |
+
for term in values_with_space:
|
891 |
+
display_glossary_entity(term)
|
892 |
+
search_glossary(term)
|
893 |
+
|
894 |
+
|
895 |
+
|
896 |
+
|
897 |
+
|
898 |
+
elif selected_view == 'Show as Run AI - Old':
|
899 |
Label = '#### ✏️ Run AI with wisdom, save with precision'
|
900 |
st.markdown(Label)
|
901 |
num_cols = len(documents_to_display)
|