Ajaykanth Maddi commited on
Commit
ea26be4
·
1 Parent(s): fa41141

global variable fix.

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -84,7 +84,7 @@ DATASET_TYPE = 'dataset_type'
84
  ENTRIES = 'entries'
85
  QUESTIONS = 'questions'
86
 
87
- ragbench_summary_questions = {}
88
 
89
  import os
90
  print(os.listdir("data")) # Check if the file is there
@@ -94,11 +94,11 @@ print(os.listdir("data")) # Check if the file is there
94
  DATA_PATH = 'data/ragbench_summary_questions_chunking.json'
95
  try:
96
  with open(DATA_PATH) as f:
97
- ragbench_summary_questions = json.load(f)
98
- logger.info(f"Loaded data with {len(ragbench_summary_questions)} subsets")
99
  except Exception as e:
100
  logger.error(f"Failed to load data: {e}")
101
- ragbench_summary_questions = {} # Fallback empty dict
102
 
103
  # Placeholder for generated values (integrate your pipeline here)
104
  # Placeholder for generated values (integrate your pipeline here)
@@ -186,27 +186,29 @@ def run_rag_pipeline(subset, question, custom_question, chunking, embed_model, r
186
  )
187
 
188
  available_questions = {}
189
- for item in ragbench_summary_questions.keys():
190
  available_questions[item] = []
191
- for sq in ragbench_summary_questions[item][QUESTIONS]:
192
  available_questions[item].append(sq['question'])
193
 
194
  # Sample Configs and Options
195
- available_subsets = list(ragbench_summary_questions.keys())
196
- chunking_strategies = ["SentenceBased", "Hybrid"]
 
 
197
  embedding_models = ["BAAI/bge-large-en-v1.5"]
198
  generator_models = ["mistralai/Mistral-7B-Instruct-v0.2"]
199
- evaluators = ["Ollama"]
200
 
201
  def update_question_list_and_info(subset):
202
- subset_questions = ragbench_summary_questions.get(subset, [])
203
  questions = [q["question"] for q in subset_questions[QUESTIONS]]
204
  selected = questions[0] if questions else None
205
  orig_ans, y_metrics = get_info_from_sample_questions(subset, selected) if selected else ("", "")
206
  return gr.update(choices=questions, value=selected), orig_ans, y_metrics
207
 
208
  def get_info_from_sample_questions(subset, question):
209
- subset_questions = ragbench_summary_questions.get(subset, [])
210
 
211
  for entry in subset_questions[QUESTIONS]:
212
  if entry.get("question") == question:
@@ -219,7 +221,7 @@ def get_info_from_sample_questions(subset, question):
219
  return "No answer found.", "No metrics found."
220
 
221
  def plot_subset_metrics(subset_name):
222
- summary = ragbench_summary_questions[subset_name]["summary"]
223
 
224
  # Create a DataFrame for plotting
225
  keys = ['Entries', 'TotalDocs', 'TotalUniqueIds', 'TotalUniqueDocs', 'UniqueDocsPercent']
@@ -240,7 +242,7 @@ def plot_subset_metrics(subset_name):
240
  return fig
241
 
242
  def plot_chunking_strategies(subset_name):
243
- chunking_data = ragbench_summary_questions[subset_name]["chunking"]
244
 
245
  plt.figure(figsize=(10, 6))
246
  strategies = list(chunking_data.keys())
 
84
  ENTRIES = 'entries'
85
  QUESTIONS = 'questions'
86
 
87
+ ragbench_details = {}
88
 
89
  import os
90
  print(os.listdir("data")) # Check if the file is there
 
94
  DATA_PATH = 'data/ragbench_summary_questions_chunking.json'
95
  try:
96
  with open(DATA_PATH) as f:
97
+ ragbench_details = json.load(f)
98
+ logger.info(f"Loaded data with {len(ragbench_details)} subsets")
99
  except Exception as e:
100
  logger.error(f"Failed to load data: {e}")
101
+ ragbench_details = {} # Fallback empty dict
102
 
103
  # Placeholder for generated values (integrate your pipeline here)
104
  # Placeholder for generated values (integrate your pipeline here)
 
186
  )
187
 
188
  available_questions = {}
189
+ for item in ragbench_details.keys():
190
  available_questions[item] = []
191
+ for sq in ragbench_details[item][QUESTIONS]:
192
  available_questions[item].append(sq['question'])
193
 
194
  # Sample Configs and Options
195
+
196
+ available_subsets = list(ragbench_details.keys())
197
+
198
+ chunking_strategies = ["SentenceBasedLangchain", "Hybrid"]
199
  embedding_models = ["BAAI/bge-large-en-v1.5"]
200
  generator_models = ["mistralai/Mistral-7B-Instruct-v0.2"]
201
+ evaluators = ["llama"]
202
 
203
  def update_question_list_and_info(subset):
204
+ subset_questions = ragbench_details.get(subset, [])
205
  questions = [q["question"] for q in subset_questions[QUESTIONS]]
206
  selected = questions[0] if questions else None
207
  orig_ans, y_metrics = get_info_from_sample_questions(subset, selected) if selected else ("", "")
208
  return gr.update(choices=questions, value=selected), orig_ans, y_metrics
209
 
210
  def get_info_from_sample_questions(subset, question):
211
+ subset_questions = ragbench_details.get(subset, [])
212
 
213
  for entry in subset_questions[QUESTIONS]:
214
  if entry.get("question") == question:
 
221
  return "No answer found.", "No metrics found."
222
 
223
  def plot_subset_metrics(subset_name):
224
+ summary = ragbench_details[subset_name]["summary"]
225
 
226
  # Create a DataFrame for plotting
227
  keys = ['Entries', 'TotalDocs', 'TotalUniqueIds', 'TotalUniqueDocs', 'UniqueDocsPercent']
 
242
  return fig
243
 
244
  def plot_chunking_strategies(subset_name):
245
+ chunking_data = ragbench_details[subset_name]["chunking"]
246
 
247
  plt.figure(figsize=(10, 6))
248
  strategies = list(chunking_data.keys())