rwillats commited on
Commit
43178f3
·
verified ·
1 Parent(s): 2ff25ee

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. hate_speech_demo.py +82 -12
hate_speech_demo.py CHANGED
@@ -66,17 +66,18 @@ def process_retrieval_text(retrieval_text, user_input):
66
  content_match = re.search(r'Content:\s*(.*)', doc_info, re.DOTALL)
67
  content = content_match.group(1).strip() if content_match else "No content available"
68
 
69
- # Format with clear section headers
70
  formatted_html = f"""
71
  <div class='doc-section'>
72
- <strong>Evidence Document {i+1}</strong>
73
- <br>
74
- <strong>Document Title:</strong> {doc_name}
75
- <br>
76
- <strong>Section:</strong> Page {page}
77
- <br>
78
- <strong>Content:</strong>
79
- <div class='doc-content'>{content}</div>
 
80
  </div>
81
  """
82
  chunks.append(formatted_html)
@@ -107,8 +108,12 @@ def process_retrieval_text(retrieval_text, user_input):
107
  chunks.append(current_chunk)
108
 
109
  # Format each chunk with better section styling
110
- chunks = [f"<div class='doc-section'><div class='doc-title'>Evidence Document {i+1}</div><div class='doc-content'>{chunk.strip()}</div></div>"
111
- for i, chunk in enumerate(chunks)]
 
 
 
 
112
 
113
  # Extract keywords from user input (longer than 3 chars)
114
  keywords = re.findall(r'\b\w{4,}\b', user_input.lower())
@@ -127,7 +132,72 @@ def process_retrieval_text(retrieval_text, user_input):
127
 
128
  highlighted_chunks.append(highlighted_chunk)
129
 
130
- return "<div class='knowledge-sections'>" + "".join(highlighted_chunks) + "</div>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
 
132
  # API Keys - hardcoded for convenience
133
  # Replace these with your actual API keys
 
66
  content_match = re.search(r'Content:\s*(.*)', doc_info, re.DOTALL)
67
  content = content_match.group(1).strip() if content_match else "No content available"
68
 
69
+ # Format with clear section headers and better spacing
70
  formatted_html = f"""
71
  <div class='doc-section'>
72
+ <h3 class="doc-number">Evidence Document {i+1}</h3>
73
+ <div class="doc-info">
74
+ <p><strong>Document Title:</strong> {doc_name}</p>
75
+ <p><strong>Section:</strong> Page {page}</p>
76
+ </div>
77
+ <div class="doc-content-container">
78
+ <h4>Content:</h4>
79
+ <div class='doc-content'>{content}</div>
80
+ </div>
81
  </div>
82
  """
83
  chunks.append(formatted_html)
 
108
  chunks.append(current_chunk)
109
 
110
  # Format each chunk with better section styling
111
+ chunks = [f"""
112
+ <div class='doc-section'>
113
+ <h3 class="doc-title">Evidence Document {i+1}</h3>
114
+ <div class='doc-content'>{chunk.strip()}</div>
115
+ </div>
116
+ """ for i, chunk in enumerate(chunks)]
117
 
118
  # Extract keywords from user input (longer than 3 chars)
119
  keywords = re.findall(r'\b\w{4,}\b', user_input.lower())
 
132
 
133
  highlighted_chunks.append(highlighted_chunk)
134
 
135
+ # Add some additional CSS for the knowledge sections
136
+ additional_css = """
137
+ <style>
138
+ .knowledge-sections {
139
+ border-radius: 8px;
140
+ background: #f9f9f9;
141
+ padding: 15px;
142
+ font-family: 'All Round Gothic Demi', 'Poppins', sans-serif !important;
143
+ }
144
+
145
+ .doc-section {
146
+ margin-bottom: 25px;
147
+ padding: 15px;
148
+ background: white;
149
+ border-radius: 8px;
150
+ box-shadow: 0 2px 5px rgba(0,0,0,0.05);
151
+ }
152
+
153
+ .doc-number, .doc-title {
154
+ margin-top: 0;
155
+ padding-bottom: 10px;
156
+ border-bottom: 1px solid #eee;
157
+ color: #222;
158
+ font-size: 18px;
159
+ }
160
+
161
+ .doc-info {
162
+ margin: 10px 0;
163
+ padding: 8px;
164
+ background: #f5f5f5;
165
+ border-radius: 4px;
166
+ }
167
+
168
+ .doc-info p {
169
+ margin: 5px 0;
170
+ }
171
+
172
+ .doc-content-container {
173
+ margin-top: 15px;
174
+ }
175
+
176
+ .doc-content-container h4 {
177
+ margin-bottom: 8px;
178
+ font-size: 16px;
179
+ }
180
+
181
+ .doc-content {
182
+ padding: 12px;
183
+ background: #f9f9f9;
184
+ border-left: 3px solid #FCA539;
185
+ line-height: 1.6;
186
+ border-radius: 4px;
187
+ white-space: pre-line;
188
+ }
189
+
190
+ .highlight-match {
191
+ background-color: #FCA539;
192
+ color: black;
193
+ font-weight: bold;
194
+ padding: 0 2px;
195
+ border-radius: 2px;
196
+ }
197
+ </style>
198
+ """
199
+
200
+ return additional_css + "<div class='knowledge-sections'>" + "".join(highlighted_chunks) + "</div>"
201
 
202
  # API Keys - hardcoded for convenience
203
  # Replace these with your actual API keys