awacke1 commited on
Commit
12a499e
1 Parent(s): 745091c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -106
app.py CHANGED
@@ -826,76 +826,8 @@ def main():
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)
@@ -918,44 +850,44 @@ def main():
918
  key=f'doc_str_{idx}')
919
 
920
  # Save and AI operations columns
921
- col_save, col_ai, col_delete = st.columns(3)
922
-
923
- with col_save:
924
- if st.button("💾 Save Changes", key=f'save_runai_{idx}'):
925
- try:
926
- updated_doc = json.loads(doc_str)
927
- # Reinsert ID and name from editable fields
928
- updated_doc['id'] = editable_id
929
- updated_doc['name'] = editable_name
930
- response = container.upsert_item(body=updated_doc)
931
- if response:
932
- st.success(f"Document {updated_doc['id']} saved successfully.")
933
- st.session_state.selected_document_id = updated_doc['id']
934
- st.rerun()
935
- except Exception as e:
936
- st.error(f"Error saving document: {str(e)}")
937
-
938
- with col_ai:
939
- if st.button("🤖 Run AI", key=f'run_with_ai_button_{idx}'):
940
- # Your existing AI processing code here
941
- values_with_space = []
942
- def extract_values2(obj):
943
- if isinstance(obj, dict):
944
- for k, v in obj.items():
945
- extract_values2(v)
946
- elif isinstance(obj, list):
947
- for item in obj:
948
- extract_values2(item)
949
- elif isinstance(obj, str):
950
- if ' ' in obj:
951
- values_with_space.append(obj)
952
-
953
- extract_values2(doc)
954
- for term in values_with_space:
955
- display_glossary_entity(term)
956
- search_glossary(term)
957
 
958
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
959
  elif selected_view == 'Clone Document':
960
  st.markdown("#### 📄 Clone Document (Save As)")
961
 
 
826
 
827
 
828
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
829
 
830
+ elif selected_view == 'Show as Run AI':
 
831
  Label = '#### ✏️ Run AI with wisdom, save with precision'
832
  st.markdown(Label)
833
  num_cols = len(documents_to_display)
 
850
  key=f'doc_str_{idx}')
851
 
852
  # Save and AI operations columns
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
853
 
854
+ if st.button("🤖 Run AI", key=f'run_with_ai_button_{idx}'):
855
+ # Your existing AI processing code here
856
+ values_with_space = []
857
+ def extract_values2(obj):
858
+ if isinstance(obj, dict):
859
+ for k, v in obj.items():
860
+ extract_values2(v)
861
+ elif isinstance(obj, list):
862
+ for item in obj:
863
+ extract_values2(item)
864
+ elif isinstance(obj, str):
865
+ if ' ' in obj:
866
+ values_with_space.append(obj)
867
+
868
+ extract_values2(doc)
869
+ for term in values_with_space:
870
+ display_glossary_entity(term)
871
+ search_glossary(term)
872
+
873
+ if st.button("💾 Save Changes", key=f'save_runai_{idx}'):
874
+ try:
875
+ updated_doc = json.loads(doc_str)
876
+ # Reinsert ID and name from editable fields
877
+ updated_doc['id'] = editable_id
878
+ updated_doc['name'] = editable_name
879
+ response = container.upsert_item(body=updated_doc)
880
+ if response:
881
+ st.success(f"Document {updated_doc['id']} saved successfully.")
882
+ st.session_state.selected_document_id = updated_doc['id']
883
+ st.rerun()
884
+ except Exception as e:
885
+ st.error(f"Error saving document: {str(e)}")
886
+
887
+
888
+
889
+
890
+
891
  elif selected_view == 'Clone Document':
892
  st.markdown("#### 📄 Clone Document (Save As)")
893