imurra commited on
Commit
9ef5e84
·
verified ·
1 Parent(s): 85baae8

change code to check to see if answer choices in question

Browse files
Files changed (1) hide show
  1. app.py +37 -6
app.py CHANGED
@@ -29,15 +29,46 @@ def ui_search(query, num_results=3):
29
  return "Enter a query"
30
  try:
31
  r = search(query, num_results)
32
-
33
- # DEBUG: Show what's in metadata
34
- print("METADATA KEYS:", r['metadatas'][0][0].keys())
35
- print("FULL METADATA:", r['metadatas'][0][0])
36
-
37
  out = ""
38
  for i in range(len(r['documents'][0])):
39
  out += f"\n{'='*60}\nExample {i+1}\n{'='*60}\n"
40
- out += r['documents'][0][i] + f"\n\nAnswer: {r['metadatas'][0][i].get('answer', 'N/A')}\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  out += f"Similarity: {1 - r['distances'][0][i]:.3f}\n"
42
  return out
43
  except Exception as e:
 
29
  return "Enter a query"
30
  try:
31
  r = search(query, num_results)
 
 
 
 
 
32
  out = ""
33
  for i in range(len(r['documents'][0])):
34
  out += f"\n{'='*60}\nExample {i+1}\n{'='*60}\n"
35
+
36
+ # Get the full question text
37
+ question_text = r['documents'][0][i]
38
+
39
+ # Parse question and answer choices
40
+ import re
41
+ # Look for answer choices pattern (A. or A) followed by text)
42
+ lines = question_text.split('\n')
43
+ question_part = []
44
+ choices_part = []
45
+ in_choices = False
46
+
47
+ for line in lines:
48
+ # Check if line starts with A-E followed by . or )
49
+ if re.match(r'^[A-E][\.\)]', line.strip()):
50
+ in_choices = True
51
+ choices_part.append(line)
52
+ elif in_choices:
53
+ # Continue collecting choices if they span multiple lines
54
+ if line.strip() and not re.match(r'^[A-E][\.\)]', line.strip()):
55
+ choices_part[-1] += " " + line.strip()
56
+ elif re.match(r'^[A-E][\.\)]', line.strip()):
57
+ choices_part.append(line)
58
+ else:
59
+ question_part.append(line)
60
+
61
+ # Display question
62
+ out += '\n'.join(question_part).strip() + "\n\n"
63
+
64
+ # Display choices if found
65
+ if choices_part:
66
+ out += "Answer Choices:\n"
67
+ for choice in choices_part:
68
+ out += choice.strip() + "\n"
69
+ out += "\n"
70
+
71
+ out += f"Correct Answer: {r['metadatas'][0][i].get('answer', 'N/A')}\n"
72
  out += f"Similarity: {1 - r['distances'][0][i]:.3f}\n"
73
  return out
74
  except Exception as e: