Spaces:
Sleeping
Sleeping
Update app.py
Browse filesremove ref from criteria box
app.py
CHANGED
|
@@ -67,43 +67,31 @@ storage_context = StorageContext.from_defaults(persist_dir="malteos_scincl__CAR_
|
|
| 67 |
# load index
|
| 68 |
index_persisted = load_index_from_storage(storage_context, index_id="vector_index")
|
| 69 |
|
| 70 |
-
import re
|
| 71 |
-
|
| 72 |
async def clean_trial_text(text):
|
| 73 |
-
"""
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
if re.match(r'Reference Papers\s*$', line, re.IGNORECASE):
|
| 80 |
-
in_references, reference_title_index = True, len(cleaned_sections)
|
| 81 |
-
cleaned_sections.append(line)
|
| 82 |
-
continue
|
| 83 |
-
|
| 84 |
-
if in_references and not found_numbers:
|
| 85 |
-
if re.match(r'\d+\.', line.strip()):
|
| 86 |
-
found_numbers = True
|
| 87 |
-
elif line.strip():
|
| 88 |
-
cleaned_sections.append(line)
|
| 89 |
-
continue
|
| 90 |
-
|
| 91 |
-
cleaned_sections.append(line)
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
| 95 |
|
| 96 |
-
return
|
| 97 |
|
| 98 |
async def process_criteria(text):
|
| 99 |
-
"""
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
text =
|
|
|
|
|
|
|
| 104 |
return text
|
| 105 |
|
| 106 |
-
|
| 107 |
async def extract_criteria(text):
|
| 108 |
"""Extracts inclusion and exclusion criteria from text."""
|
| 109 |
patterns = {
|
|
|
|
| 67 |
# load index
|
| 68 |
index_persisted = load_index_from_storage(storage_context, index_id="vector_index")
|
| 69 |
|
|
|
|
|
|
|
| 70 |
async def clean_trial_text(text):
|
| 71 |
+
"""
|
| 72 |
+
Cleans text by removing everything starting from the word 'Reference Papers'
|
| 73 |
+
and any special characters like '*'.
|
| 74 |
+
"""
|
| 75 |
+
# Remove special characters like '*'
|
| 76 |
+
text = re.sub(r'\*+', '', text).strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
+
# Find the position of 'Reference Papers' and truncate the text
|
| 79 |
+
reference_start = re.search(r'\bReference Papers\b', text, re.IGNORECASE)
|
| 80 |
+
if reference_start:
|
| 81 |
+
text = text[:reference_start.start()].strip()
|
| 82 |
|
| 83 |
+
return text
|
| 84 |
|
| 85 |
async def process_criteria(text):
|
| 86 |
+
"""
|
| 87 |
+
Processes the query response text, removing special characters and cleaning it
|
| 88 |
+
up to the word 'Reference Papers'.
|
| 89 |
+
"""
|
| 90 |
+
text = re.sub(r'#+\s*', '', text) # Remove headings like '###'
|
| 91 |
+
text = re.sub(r'(Criteria)\n\s*\n(\d+\.)', r'\1\n\2', text) # Fix spacing issues
|
| 92 |
+
text = await clean_trial_text(text) # Clean up text until 'Reference Papers'
|
| 93 |
return text
|
| 94 |
|
|
|
|
| 95 |
async def extract_criteria(text):
|
| 96 |
"""Extracts inclusion and exclusion criteria from text."""
|
| 97 |
patterns = {
|