Update app.py
Browse files
app.py
CHANGED
|
@@ -182,21 +182,80 @@ def create_interface():
|
|
| 182 |
|
| 183 |
# Examples section
|
| 184 |
gr.Markdown("### Examples")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
gr.Examples(
|
| 186 |
-
examples=[
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
# Examples section
|
| 184 |
gr.Markdown("### Examples")
|
| 185 |
+
|
| 186 |
+
example1 = [
|
| 187 |
+
"During World War II, many prisoners of war were held in camps across Europe. The Geneva Convention established rules for POW treatment. American soldiers and British troops were among those captured.",
|
| 188 |
+
"Prisoner of War", "POW; POWs; prisoner of war",
|
| 189 |
+
"World War II", "WWII; Second World War",
|
| 190 |
+
"United States", "USA; US; America; American",
|
| 191 |
+
"", "", "", ""
|
| 192 |
+
]
|
| 193 |
+
|
| 194 |
+
example2 = [
|
| 195 |
+
"The University of Oxford is located in Oxford, England. Students from around the world study at this prestigious institution.",
|
| 196 |
+
"University", "university; institution; college",
|
| 197 |
+
"Oxford", "oxford",
|
| 198 |
+
"England", "england; English",
|
| 199 |
+
"Student", "student; students; pupils",
|
| 200 |
+
"", ""
|
| 201 |
+
]
|
| 202 |
+
|
| 203 |
gr.Examples(
|
| 204 |
+
examples=[example1, example2],
|
| 205 |
+
inputs=[text_input, primary1, synonyms1, primary2, synonyms2, primary3, synonyms3, primary4, synonyms4, primary5, synonyms5],
|
| 206 |
+
label="Click an example to try it out"
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
# Button functions
|
| 210 |
+
find_btn.click(
|
| 211 |
+
fn=process_text,
|
| 212 |
+
inputs=[text_input, primary1, synonyms1, primary2, synonyms2, primary3, synonyms3, primary4, synonyms4, primary5, synonyms5],
|
| 213 |
+
outputs=[results_output, highlighted_output, copy_output]
|
| 214 |
+
)
|
| 215 |
+
|
| 216 |
+
def clear_all():
|
| 217 |
+
return "", "", "", "", "", "", "", "", "", "", "", "", "", ""
|
| 218 |
+
|
| 219 |
+
clear_btn.click(
|
| 220 |
+
fn=clear_all,
|
| 221 |
+
outputs=[text_input, primary1, synonyms1, primary2, synonyms2, primary3, synonyms3, primary4, synonyms4, primary5, synonyms5, results_output, highlighted_output, copy_output]
|
| 222 |
+
)
|
| 223 |
+
|
| 224 |
+
# Instructions
|
| 225 |
+
gr.Markdown("""
|
| 226 |
+
## Format Guide
|
| 227 |
+
|
| 228 |
+
**How to enter keywords:**
|
| 229 |
+
- **Primary Keyword:** Enter the main/preferred term for a concept
|
| 230 |
+
- **Synonyms:** Enter alternative terms separated by semicolons `;`
|
| 231 |
+
- Leave rows blank if you don't need all 5 keyword groups
|
| 232 |
+
- The tool will find ANY of these terms and return ALL related terms
|
| 233 |
+
|
| 234 |
+
**Example:**
|
| 235 |
+
- Primary: `Prisoner of War`
|
| 236 |
+
- Synonyms: `POW; POWs; prisoner of war`
|
| 237 |
+
|
| 238 |
+
**Special Handling:**
|
| 239 |
+
- "US" is matched exactly to avoid confusion with the word "us"
|
| 240 |
+
- Word boundaries are respected (prevents partial matches)
|
| 241 |
+
- Results are alphabetized and deduplicated
|
| 242 |
+
|
| 243 |
+
**How it works:**
|
| 244 |
+
When ANY variant is found in your text (primary OR synonym), the tool returns the complete standardized set of terms for that concept.
|
| 245 |
+
""")
|
| 246 |
+
|
| 247 |
+
# Footer
|
| 248 |
+
gr.HTML("""
|
| 249 |
+
<div style="margin-top: 40px; padding: 20px; background-color: #f8f9fa; border-radius: 8px; text-align: center;">
|
| 250 |
+
<p style="margin: 0; color: #666;">
|
| 251 |
+
Created for digital humanities keyword tagging workflows.
|
| 252 |
+
Based on controlled vocabulary matching principles.
|
| 253 |
+
</p>
|
| 254 |
+
</div>
|
| 255 |
+
""")
|
| 256 |
+
|
| 257 |
+
return demo
|
| 258 |
+
|
| 259 |
+
if __name__ == "__main__":
|
| 260 |
+
demo = create_interface()
|
| 261 |
+
demo.launch()
|