soft.engineer commited on
Commit
6a97c2a
·
1 Parent(s): 79e0552

update style

Browse files
Files changed (1) hide show
  1. app.py +24 -10
app.py CHANGED
@@ -5,6 +5,7 @@ from dotenv import load_dotenv
5
  import tempfile
6
  import pandas as pd
7
  from typing import List, Dict, Any, Tuple
 
8
  import json
9
  from core.ingest import DocumentChunker, HierarchyManager
10
  from core.index import VectorStore
@@ -126,6 +127,21 @@ def initialize_system():
126
 
127
  return f"System initialized successfully! Using persist directory: {persist_dir}"
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  def upload_documents(files: List[str], hierarchy: str, doc_type: str, language: str, progress: Any = None) -> Tuple[str, List[Dict[str, Any]], Dict[str, Any], List[Dict[str, Any]]]:
130
  """Upload and process documents.
131
  Returns: (status_text, per_file_summaries, collection_stats)
@@ -508,16 +524,7 @@ def run_evaluation(queries_json: str, output_filename: str) -> Tuple[str, pd.Dat
508
  initialize_system()
509
 
510
  # Create Gradio interface
511
- APP_CSS = """
512
- .gradio-container { max-width: 1100px !important; margin: 0 auto !important; }
513
- .gradio-container img { max-width: 100%; height: auto; }
514
- /* Prevent toolbar and button icons from stretching */
515
- button img, .icon, .toolbar img { width: 20px !important; height: 20px !important; object-fit: contain; }
516
- /* Keep DataFrame within container width */
517
- .gr-dataframe { max-width: 100%; }
518
- """
519
-
520
- with gr.Blocks(title="RAG Evaluation System", css=APP_CSS, fill_height=False) as demo:
521
  gr.Markdown("# RAG Evaluation System: Hierarchical vs Standard RAG")
522
 
523
  with gr.Tab("Upload Documents"):
@@ -550,6 +557,7 @@ with gr.Blocks(title="RAG Evaluation System", css=APP_CSS, fill_height=False) as
550
  build_output = gr.Textbox(label="Build Status", lines=4)
551
  stats_table = gr.DataFrame(label="File Summary")
552
  chunks_table = gr.DataFrame(label="Indexed Chunks (preview)")
 
553
 
554
  with gr.Tab("Search"):
555
  gr.Markdown("## Compare Retrieval Pipelines")
@@ -662,6 +670,12 @@ with gr.Blocks(title="RAG Evaluation System", css=APP_CSS, fill_height=False) as
662
  outputs=[build_output, stats_table, chunks_table],
663
  api_name="build_rag"
664
  )
 
 
 
 
 
 
665
 
666
  # One button: uses manual if checked; otherwise auto
667
  search_btn.click(
 
5
  import tempfile
6
  import pandas as pd
7
  from typing import List, Dict, Any, Tuple
8
+ import shutil
9
  import json
10
  from core.ingest import DocumentChunker, HierarchyManager
11
  from core.index import VectorStore
 
127
 
128
  return f"System initialized successfully! Using persist directory: {persist_dir}"
129
 
130
+ def reset_index() -> str:
131
+ """Clear Chroma persistence and reinitialize the vector store."""
132
+ global rag_manager, evaluator, persist_directory
133
+ try:
134
+ dir_path = persist_directory or ("/data/chroma" if os.path.exists("/data/chroma") else "./chroma_data")
135
+ if os.path.exists(dir_path):
136
+ shutil.rmtree(dir_path, ignore_errors=True)
137
+ os.makedirs(dir_path, exist_ok=True, mode=0o755)
138
+ persist_directory = dir_path
139
+ rag_manager = RAGManager(persist_directory=dir_path)
140
+ evaluator = RAGEvaluator(rag_manager)
141
+ return f"Index reset complete. Using fresh directory: {dir_path}"
142
+ except Exception as ex:
143
+ return f"Failed to reset index: {ex}"
144
+
145
  def upload_documents(files: List[str], hierarchy: str, doc_type: str, language: str, progress: Any = None) -> Tuple[str, List[Dict[str, Any]], Dict[str, Any], List[Dict[str, Any]]]:
146
  """Upload and process documents.
147
  Returns: (status_text, per_file_summaries, collection_stats)
 
524
  initialize_system()
525
 
526
  # Create Gradio interface
527
+ with gr.Blocks(title="RAG Evaluation System") as demo:
 
 
 
 
 
 
 
 
 
528
  gr.Markdown("# RAG Evaluation System: Hierarchical vs Standard RAG")
529
 
530
  with gr.Tab("Upload Documents"):
 
557
  build_output = gr.Textbox(label="Build Status", lines=4)
558
  stats_table = gr.DataFrame(label="File Summary")
559
  chunks_table = gr.DataFrame(label="Indexed Chunks (preview)")
560
+ reset_btn = gr.Button("Reset Index (Clear chroma_data)", variant="secondary")
561
 
562
  with gr.Tab("Search"):
563
  gr.Markdown("## Compare Retrieval Pipelines")
 
670
  outputs=[build_output, stats_table, chunks_table],
671
  api_name="build_rag"
672
  )
673
+
674
+ reset_btn.click(
675
+ fn=reset_index,
676
+ inputs=None,
677
+ outputs=build_output
678
+ )
679
 
680
  # One button: uses manual if checked; otherwise auto
681
  search_btn.click(