Upload folder using huggingface_hub
Browse files- hate_speech_demo.py +11 -1
hate_speech_demo.py
CHANGED
|
@@ -15,8 +15,18 @@ load_dotenv()
|
|
| 15 |
|
| 16 |
# Process retrieval text to highlight relevant parts
|
| 17 |
def process_retrieval_text(retrieval_text, user_input):
|
| 18 |
-
if not retrieval_text or retrieval_text == "No retrieval text found.":
|
| 19 |
return retrieval_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Extract keywords from user input (longer than 3 chars)
|
| 22 |
keywords = re.findall(r'\b\w{4,}\b', user_input.lower())
|
|
|
|
| 15 |
|
| 16 |
# Process retrieval text to highlight relevant parts
|
| 17 |
def process_retrieval_text(retrieval_text, user_input):
|
| 18 |
+
if not retrieval_text or retrieval_text.strip() == "No retrieval text found.":
|
| 19 |
return retrieval_text
|
| 20 |
+
|
| 21 |
+
# Split chunks by two newlines (as created earlier)
|
| 22 |
+
chunks = retrieval_text.strip().split("\n\n")
|
| 23 |
+
formatted_chunks = []
|
| 24 |
+
|
| 25 |
+
for i, chunk in enumerate(chunks):
|
| 26 |
+
formatted_chunk = f"<strong>Evidence Chunk {i+1}</strong><br>{chunk.strip()}"
|
| 27 |
+
formatted_chunks.append(formatted_chunk)
|
| 28 |
+
|
| 29 |
+
return "<br><br>".join(formatted_chunks)
|
| 30 |
|
| 31 |
# Extract keywords from user input (longer than 3 chars)
|
| 32 |
keywords = re.findall(r'\b\w{4,}\b', user_input.lower())
|