awacke1 commited on
Commit
73a2033
1 Parent(s): 605e4db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -14
app.py CHANGED
@@ -588,7 +588,8 @@ def main():
588
  # Create columns for each document
589
  num_cols = len(documents_to_display)
590
  cols = st.columns(num_cols)
591
-
 
592
  for idx, (col, doc) in enumerate(zip(cols, documents_to_display)):
593
  with col:
594
  st.markdown(f"##### Document ID: {doc.get('id', '')}")
@@ -597,19 +598,38 @@ def main():
597
  editable_doc = doc.copy()
598
  editable_doc.pop('id', None)
599
  doc_str = st.text_area("Document Content (in JSON format)", value=json.dumps(editable_doc, indent=2), height=300, key=f'doc_str_{idx}')
600
- if st.button("💾 Save Changes", key=f'save_button_{idx}'):
601
- try:
602
- updated_doc = json.loads(doc_str)
603
- updated_doc['id'] = editable_id # Include the possibly edited ID
604
- success, message = update_record(container, updated_doc)
605
- if success:
606
- st.success(f"Document {updated_doc['id']} saved successfully.")
607
- st.session_state.selected_document_id = updated_doc['id']
608
- st.rerun()
609
- else:
610
- st.error(message)
611
- except json.JSONDecodeError as e:
612
- st.error(f"Invalid JSON: {str(e)} 🚫")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
613
 
614
  elif selected_view == 'Clone Document':
615
  # 🧬 Clone Document per record
 
588
  # Create columns for each document
589
  num_cols = len(documents_to_display)
590
  cols = st.columns(num_cols)
591
+
592
+
593
  for idx, (col, doc) in enumerate(zip(cols, documents_to_display)):
594
  with col:
595
  st.markdown(f"##### Document ID: {doc.get('id', '')}")
 
598
  editable_doc = doc.copy()
599
  editable_doc.pop('id', None)
600
  doc_str = st.text_area("Document Content (in JSON format)", value=json.dumps(editable_doc, indent=2), height=300, key=f'doc_str_{idx}')
601
+
602
+ # Add the "Run With AI" button next to "Save Changes"
603
+ col_save, col_ai = st.columns(2)
604
+ with col_save:
605
+ if st.button("💾 Save Changes", key=f'save_button_{idx}'):
606
+ try:
607
+ updated_doc = json.loads(doc_str)
608
+ updated_doc['id'] = editable_id # Include the possibly edited ID
609
+ success, message = update_record(container, updated_doc)
610
+ if success:
611
+ st.success(f"Document {updated_doc['id']} saved successfully.")
612
+ st.session_state.selected_document_id = updated_doc['id']
613
+ st.rerun()
614
+ else:
615
+ st.error(message)
616
+ except json.JSONDecodeError as e:
617
+ st.error(f"Invalid JSON: {str(e)} 🚫")
618
+ with col_ai:
619
+ if st.button("🤖 Run With AI", key=f'run_with_ai_button_{idx}'):
620
+ # Use the entire document as input
621
+ try:
622
+ doc_content = json.loads(doc_str)
623
+ # Convert the JSON document to a string representation
624
+ doc_input = json.dumps(doc_content, indent=2)
625
+ # Call the process_text function with the document content
626
+ process_text(doc_input)
627
+ except json.JSONDecodeError as e:
628
+ st.error(f"Invalid JSON: {str(e)} 🚫")
629
+
630
+
631
+
632
+
633
 
634
  elif selected_view == 'Clone Document':
635
  # 🧬 Clone Document per record