jzou19950715 commited on
Commit
fc897ee
·
verified ·
1 Parent(s): d0a3775

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +105 -36
app.py CHANGED
@@ -763,7 +763,49 @@ def get_db_stats(vector_store: VectorStoreManager) -> str:
763
  except Exception as e:
764
  logger.error(f"Error getting statistics: {e}")
765
  return "Error getting database statistics"
 
766
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
767
  def main():
768
  """Main function to run the RAG application"""
769
  # Path for configuration file
@@ -790,39 +832,66 @@ def main():
790
  # Initialize RAG system without API keys initially
791
  rag_system = RAGSystem(vector_store, config)
792
 
793
- # Custom CSS for better UI
794
- custom_css = """
795
- .gradio-container {
796
- max-width: 1200px;
797
- margin: auto;
798
- }
799
- .gr-prose h1 {
800
- font-size: 2.5rem;
801
- margin-bottom: 1rem;
802
- color: #1a5276;
803
- }
804
- .gr-prose h3 {
805
- font-size: 1.25rem;
806
- font-weight: 600;
807
- margin-top: 1rem;
808
- margin-bottom: 0.5rem;
809
- color: #2874a6;
810
- }
811
- .container {
812
- margin: 0 auto;
813
- padding: 2rem;
814
- }
815
- .gr-box {
816
- border-radius: 8px;
817
- box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
818
- padding: 1rem;
819
- margin-bottom: 1rem;
820
- background-color: #f9f9f9;
821
- }
822
- .footer {
823
- text-align: center;
824
- font-size: 0.8rem;
825
- color: #666;
826
- margin-top: 2rem;
827
- }
828
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
763
  except Exception as e:
764
  logger.error(f"Error getting statistics: {e}")
765
  return "Error getting database statistics"
766
+ # Find and fix the `try` block around line 828
767
 
768
+ # The error occurs because there's likely a `try` statement without a matching `except` or `finally`
769
+ # Here are the possible locations and fixes:
770
+
771
+ # Option 1: If it's in the custom CSS definition around that line number
772
+ custom_css = """
773
+ .gradio-container {
774
+ max-width: 1200px;
775
+ margin: auto;
776
+ }
777
+ .gr-prose h1 {
778
+ font-size: 2.5rem;
779
+ margin-bottom: 1rem;
780
+ color: #1a5276;
781
+ }
782
+ .gr-prose h3 {
783
+ font-size: 1.25rem;
784
+ font-weight: 600;
785
+ margin-top: 1rem;
786
+ margin-bottom: 0.5rem;
787
+ color: #2874a6;
788
+ }
789
+ .container {
790
+ margin: 0 auto;
791
+ padding: 2rem;
792
+ }
793
+ .gr-box {
794
+ border-radius: 8px;
795
+ box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
796
+ padding: 1rem;
797
+ margin-bottom: 1rem;
798
+ background-color: #f9f9f9;
799
+ }
800
+ .footer {
801
+ text-align: center;
802
+ font-size: 0.8rem;
803
+ color: #666;
804
+ margin-top: 2rem;
805
+ }
806
+ """ # Make sure this closing triple quote is present
807
+
808
+ # Option 2: If it's in the main function, make sure all try blocks have matching except clauses
809
  def main():
810
  """Main function to run the RAG application"""
811
  # Path for configuration file
 
832
  # Initialize RAG system without API keys initially
833
  rag_system = RAGSystem(vector_store, config)
834
 
835
+ # Create the Gradio interface with custom CSS
836
+ with gr.Blocks(title="Document Knowledge Assistant", css=custom_css) as app:
837
+ # Interface code here...
838
+ pass # Replace with actual UI code
839
+
840
+ # Launch the interface
841
+ app.launch(
842
+ share=False,
843
+ server_name="0.0.0.0",
844
+ server_port=7860,
845
+ debug=False
846
+ )
847
+
848
+ except Exception as e: # Make sure there's an except clause for every try
849
+ logger.critical(f"Error starting application: {e}")
850
+ print(f"Error starting application: {e}")
851
+ sys.exit(1)
852
+
853
+ # Option 3: If it's in an Example or Markdown section, make sure triple quotes are properly closed
854
+
855
+ # Option 4: Complete fix for the most likely scenario - an incomplete try block in the main function
856
+ def main_fixed():
857
+ """Main function to run the RAG application"""
858
+ # Path for configuration file
859
+ CONFIG_FILE_PATH = "rag_config.json"
860
+
861
+ # Try to load configuration from file, or use defaults
862
+ try:
863
+ if os.path.exists(CONFIG_FILE_PATH):
864
+ config = Config.from_file(CONFIG_FILE_PATH)
865
+ else:
866
+ config = Config(
867
+ local_dir="./chroma_db",
868
+ collection_name="markdown_docs"
869
+ )
870
+ # Save default configuration
871
+ config.save_to_file(CONFIG_FILE_PATH)
872
+
873
+ print(f"Starting Document Knowledge Assistant v{VERSION}")
874
+ print(f"Log file: {log_file}")
875
+
876
+ # Initialize vector store manager with existing collection
877
+ vector_store = VectorStoreManager(config)
878
+
879
+ # Initialize RAG system without API keys initially
880
+ rag_system = RAGSystem(vector_store, config)
881
+
882
+ # Create the Gradio interface
883
+ with gr.Blocks(title="Document Knowledge Assistant", css=custom_css) as app:
884
+ # UI code here
885
+ pass # Replace with actual UI code
886
+
887
+ # Launch the interface
888
+ app.launch(
889
+ share=False,
890
+ server_name="0.0.0.0",
891
+ server_port=7860,
892
+ debug=False
893
+ )
894
+ except Exception as e:
895
+ logger.critical(f"Error starting application: {e}")
896
+ print(f"Error starting application: {e}")
897
+ sys.exit(1)