SVashishta1 commited on
Commit
b8b94fc
Β·
1 Parent(s): 7504c5e

Cleanup: Remove list documents feature and save visualization, keep download feature

Browse files
Files changed (1) hide show
  1. app.py +15 -99
app.py CHANGED
@@ -433,20 +433,21 @@ def process_file_upload(files):
433
 
434
  return "\n".join(file_info)
435
 
436
- def list_documents():
437
- """List all indexed documents"""
438
- try:
439
- docs = document_assistant.get_all_documents()
440
- if not docs:
441
- return "No documents indexed yet."
442
-
443
- result = "Indexed Documents:\n\n"
444
- for doc in docs:
445
- result += f"- {doc['filename']} ({doc['file_type']})\n"
446
-
447
- return result
448
- except Exception as e:
449
- return f"Error listing documents: {str(e)}"
 
450
 
451
  def clear_context():
452
  """Clear the current context"""
@@ -775,7 +776,6 @@ with gr.Blocks(title="LLM Powered Database Chatbot") as demo:
775
 
776
  with gr.Row():
777
  clear_viz_btn = gr.Button("πŸ—‘οΈ Clear Visualization")
778
- save_viz_btn = gr.Button("πŸ’Ύ Save Visualization")
779
  download_btn = gr.Button("πŸ“₯ Download Visualization")
780
 
781
  save_status = gr.Textbox(label="Save Status", visible=False)
@@ -793,29 +793,6 @@ with gr.Blocks(title="LLM Powered Database Chatbot") as demo:
793
  def clear_visualization():
794
  return "", ""
795
 
796
- def save_visualization(viz_html):
797
- if not viz_html:
798
- return "No visualization to save", gr.update(visible=True)
799
-
800
- try:
801
- # Extract the base64 image data from the HTML
802
- img_data_match = re.search(r'src=\'data:image/png;base64,([^\']+)\'', viz_html)
803
-
804
- if img_data_match:
805
- # Get the base64 data
806
- img_data = img_data_match.group(1)
807
-
808
- # Create a downloadable file
809
- timestamp = time.strftime("%Y%m%d_%H%M%S")
810
- filename = f"visualization_{timestamp}.png"
811
-
812
- # Return success message with download link
813
- return f"Visualization ready for download", gr.update(visible=True)
814
- else:
815
- return "Could not extract image data", gr.update(visible=True)
816
- except Exception as e:
817
- return f"Error preparing visualization for download: {str(e)}", gr.update(visible=True)
818
-
819
  def download_visualization(viz_html):
820
  if not viz_html:
821
  return None
@@ -848,12 +825,6 @@ with gr.Blocks(title="LLM Powered Database Chatbot") as demo:
848
  outputs=[visualization_output, current_visualization]
849
  )
850
 
851
- save_viz_btn.click(
852
- save_visualization,
853
- inputs=[current_visualization],
854
- outputs=[save_status, save_status]
855
- )
856
-
857
  download_btn.click(
858
  download_visualization,
859
  inputs=[current_visualization],
@@ -917,61 +888,6 @@ with gr.Blocks(title="LLM Powered Database Chatbot") as demo:
917
  inputs=[],
918
  outputs=[upload_output]
919
  )
920
-
921
- list_docs_button = gr.Button("List Indexed Documents")
922
- docs_output = gr.Textbox(label="Indexed Documents")
923
-
924
- list_docs_button.click(
925
- list_documents,
926
- inputs=[],
927
- outputs=[docs_output]
928
- )
929
-
930
- # Settings tab commented out as it's not currently used
931
- # with gr.Tab("Settings"):
932
- # with gr.Row():
933
- # gr.Markdown("## Database Management")
934
- # flush_db_btn = gr.Button("πŸ—‘οΈ Flush All Databases", variant="stop", scale=1)
935
- #
936
- # flush_result = gr.Textbox(label="Flush Result")
937
- #
938
- # flush_db_btn.click(
939
- # flush_databases,
940
- # inputs=[],
941
- # outputs=[flush_result]
942
- # )
943
- #
944
- # gr.Markdown("## System Settings")
945
- # api_key = gr.Textbox(
946
- # label="Groq API Key",
947
- # placeholder="Enter your Groq API key",
948
- # type="password",
949
- # value=os.getenv("GROQ_API_KEY", "")
950
- # )
951
- # save_btn = gr.Button("Save Settings")
952
- #
953
- # def save_settings(key):
954
- # try:
955
- # os.environ["GROQ_API_KEY"] = key
956
- # return "Settings saved!"
957
- # except Exception as e:
958
- # return f"Error saving settings: {str(e)}"
959
- #
960
- # save_btn.click(
961
- # save_settings,
962
- # inputs=[api_key],
963
- # outputs=[gr.Textbox(label="Status")]
964
- # )
965
- #
966
- # gr.Markdown("## Debugging")
967
- # test_viz_btn = gr.Button("Test Visualization")
968
- # test_viz_output = gr.HTML(label="Test Visualization")
969
- #
970
- # test_viz_btn.click(
971
- # create_test_html_visualization,
972
- # inputs=[],
973
- # outputs=[test_viz_output]
974
- # )
975
 
976
  # Launch the app
977
  if __name__ == "__main__":
 
433
 
434
  return "\n".join(file_info)
435
 
436
+ # Function commented out as it's no longer used
437
+ # def list_documents():
438
+ # """List all indexed documents"""
439
+ # try:
440
+ # docs = document_assistant.get_all_documents()
441
+ # if not docs:
442
+ # return "No documents indexed yet."
443
+ #
444
+ # result = "Indexed Documents:\n\n"
445
+ # for doc in docs:
446
+ # result += f"- {doc['filename']} ({doc['file_type']})\n"
447
+ #
448
+ # return result
449
+ # except Exception as e:
450
+ # return f"Error listing documents: {str(e)}"
451
 
452
  def clear_context():
453
  """Clear the current context"""
 
776
 
777
  with gr.Row():
778
  clear_viz_btn = gr.Button("πŸ—‘οΈ Clear Visualization")
 
779
  download_btn = gr.Button("πŸ“₯ Download Visualization")
780
 
781
  save_status = gr.Textbox(label="Save Status", visible=False)
 
793
  def clear_visualization():
794
  return "", ""
795
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
796
  def download_visualization(viz_html):
797
  if not viz_html:
798
  return None
 
825
  outputs=[visualization_output, current_visualization]
826
  )
827
 
 
 
 
 
 
 
828
  download_btn.click(
829
  download_visualization,
830
  inputs=[current_visualization],
 
888
  inputs=[],
889
  outputs=[upload_output]
890
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
891
 
892
  # Launch the app
893
  if __name__ == "__main__":