Update app.py
Browse files
app.py
CHANGED
|
@@ -41,7 +41,7 @@ def highlight_keywords(text, keywords):
|
|
| 41 |
for kw in sorted(keywords, key=lambda k: -len(k)):
|
| 42 |
pattern = re.compile(re.escape(kw), re.IGNORECASE)
|
| 43 |
highlighted = pattern.sub(
|
| 44 |
-
f'<span style="background-color: #
|
| 45 |
f'border-radius: 4px; font-weight: bold;">{kw}</span>',
|
| 46 |
highlighted
|
| 47 |
)
|
|
@@ -54,7 +54,7 @@ def create_keywords_table(keywords):
|
|
| 54 |
table_html = """
|
| 55 |
<table style="width: 100%; border-collapse: collapse; border: 1px solid #ddd;">
|
| 56 |
<thead>
|
| 57 |
-
<tr style="background-color: #
|
| 58 |
<th style="padding: 10px; text-align: left;">Rank</th>
|
| 59 |
<th style="padding: 10px; text-align: left;">Keyword</th>
|
| 60 |
</tr>
|
|
@@ -80,23 +80,23 @@ def process_text(text, model_choice, num_keywords):
|
|
| 80 |
keywords_table_html = create_keywords_table(keywords)
|
| 81 |
|
| 82 |
summary_html = f"""
|
| 83 |
-
<div style="background-color: #f8f9fa; padding:
|
| 84 |
-
<h3 style="margin-top: 0; color: #
|
| 85 |
<p><strong>Model Used:</strong> {model_choice}</p>
|
| 86 |
<p><strong>Keywords Found:</strong> {len(keywords)}</p>
|
| 87 |
</div>
|
| 88 |
"""
|
| 89 |
|
| 90 |
highlighted_section = f"""
|
| 91 |
-
<div style='padding:
|
| 92 |
-
<h4 style='margin: 0 0 15px 0; color: #
|
| 93 |
-
<div style='line-height: 1.8; font-size: 16px; background-color: white; padding:
|
| 94 |
</div>
|
| 95 |
"""
|
| 96 |
|
| 97 |
table_section = f"""
|
| 98 |
<div style="margin-top: 20px;">
|
| 99 |
-
<h4 style="color: #
|
| 100 |
{keywords_table_html}
|
| 101 |
</div>
|
| 102 |
"""
|
|
@@ -106,32 +106,30 @@ def process_text(text, model_choice, num_keywords):
|
|
| 106 |
def create_interface():
|
| 107 |
with gr.Blocks(title="Keyword Explorer Tool") as demo:
|
| 108 |
gr.Markdown("""
|
| 109 |
-
# π Keyword
|
| 110 |
-
|
| 111 |
-
See what different Keyword Extraction (KE) models can do, and if this is useful to you.
|
| 112 |
|
| 113 |
---
|
| 114 |
|
| 115 |
-
###
|
| 116 |
|
| 117 |
-
1. **π
|
| 118 |
-
2. **ποΈ
|
| 119 |
-
3.
|
|
|
|
| 120 |
- π A summary of results.
|
| 121 |
- β¨ Highlighted keywords inside your text.
|
| 122 |
- π A full keyword list.
|
| 123 |
|
| 124 |
---
|
| 125 |
-
|
| 126 |
""")
|
| 127 |
|
| 128 |
-
text_input = gr.Textbox(label="π Text to Analyse", placeholder="
|
| 129 |
|
| 130 |
with gr.Row():
|
| 131 |
model_dropdown = gr.Dropdown(choices=AVAILABLE_MODELS, value=AVAILABLE_MODELS[0], label="ποΈ Select Model")
|
| 132 |
-
num_keywords_slider = gr.Slider(minimum=5, maximum=50, value=10, step=1, label="
|
| 133 |
|
| 134 |
-
analyse_btn = gr.Button("π Extract Keywords",
|
| 135 |
|
| 136 |
summary_output = gr.HTML()
|
| 137 |
highlighted_output = gr.HTML()
|
|
@@ -145,10 +143,10 @@ See what different Keyword Extraction (KE) models can do, and if this is useful
|
|
| 145 |
|
| 146 |
gr.HTML("""
|
| 147 |
<hr style="margin-top: 40px; margin-bottom: 20px;">
|
| 148 |
-
<div style="background-color: #f8f9fa; padding: 20px; border-radius:
|
| 149 |
<p style="font-size: 14px; line-height: 1.8; margin: 0;">
|
| 150 |
This <strong>Keyword Extraction Explorer Tool</strong> was created as part of the
|
| 151 |
-
<a href="https://digitalscholarship.web.ox.ac.uk/" target="_blank" style="color: #
|
| 152 |
Digital Scholarship at Oxford (DiSc)
|
| 153 |
</a>
|
| 154 |
funded research project:
|
|
|
|
| 41 |
for kw in sorted(keywords, key=lambda k: -len(k)):
|
| 42 |
pattern = re.compile(re.escape(kw), re.IGNORECASE)
|
| 43 |
highlighted = pattern.sub(
|
| 44 |
+
f'<span style="background-color: #6C63FF; color: white; padding: 2px 5px; '
|
| 45 |
f'border-radius: 4px; font-weight: bold;">{kw}</span>',
|
| 46 |
highlighted
|
| 47 |
)
|
|
|
|
| 54 |
table_html = """
|
| 55 |
<table style="width: 100%; border-collapse: collapse; border: 1px solid #ddd;">
|
| 56 |
<thead>
|
| 57 |
+
<tr style="background-color: #6C63FF; color: white;">
|
| 58 |
<th style="padding: 10px; text-align: left;">Rank</th>
|
| 59 |
<th style="padding: 10px; text-align: left;">Keyword</th>
|
| 60 |
</tr>
|
|
|
|
| 80 |
keywords_table_html = create_keywords_table(keywords)
|
| 81 |
|
| 82 |
summary_html = f"""
|
| 83 |
+
<div style="background-color: #f8f9fa; padding: 20px; border-radius: 10px; border: 1px solid #ddd; box-shadow: 0 2px 5px rgba(0,0,0,0.05); margin-bottom: 20px;">
|
| 84 |
+
<h3 style="margin-top: 0; color: #6C63FF;">π Analysis Summary</h3>
|
| 85 |
<p><strong>Model Used:</strong> {model_choice}</p>
|
| 86 |
<p><strong>Keywords Found:</strong> {len(keywords)}</p>
|
| 87 |
</div>
|
| 88 |
"""
|
| 89 |
|
| 90 |
highlighted_section = f"""
|
| 91 |
+
<div style='padding: 20px; border: 2px solid #ddd; border-radius: 10px; background-color: #fafafa; margin: 15px 0; box-shadow: 0 2px 5px rgba(0,0,0,0.05);'>
|
| 92 |
+
<h4 style='margin: 0 0 15px 0; color: #6C63FF;'>π Text with Highlighted Keywords</h4>
|
| 93 |
+
<div style='line-height: 1.8; font-size: 16px; background-color: white; padding: 20px; border-radius: 8px;'>{highlighted_html}</div>
|
| 94 |
</div>
|
| 95 |
"""
|
| 96 |
|
| 97 |
table_section = f"""
|
| 98 |
<div style="margin-top: 20px;">
|
| 99 |
+
<h4 style="color: #6C63FF; margin-bottom: 10px;">π Extracted Keywords</h4>
|
| 100 |
{keywords_table_html}
|
| 101 |
</div>
|
| 102 |
"""
|
|
|
|
| 106 |
def create_interface():
|
| 107 |
with gr.Blocks(title="Keyword Explorer Tool") as demo:
|
| 108 |
gr.Markdown("""
|
| 109 |
+
# π Keyword Explorer Tool
|
|
|
|
|
|
|
| 110 |
|
| 111 |
---
|
| 112 |
|
| 113 |
+
### π How to use:
|
| 114 |
|
| 115 |
+
1. **π Enter your text** in the text area below.
|
| 116 |
+
2. **ποΈ Select a model** from the dropdown.
|
| 117 |
+
3. **βοΈ Adjust the maximum number of keywords to be identified ** using the slider.
|
| 118 |
+
4. **π Click "Analyse Text"** to see:
|
| 119 |
- π A summary of results.
|
| 120 |
- β¨ Highlighted keywords inside your text.
|
| 121 |
- π A full keyword list.
|
| 122 |
|
| 123 |
---
|
|
|
|
| 124 |
""")
|
| 125 |
|
| 126 |
+
text_input = gr.Textbox(label="π Text to Analyse", placeholder="Enter your text here...", lines=10)
|
| 127 |
|
| 128 |
with gr.Row():
|
| 129 |
model_dropdown = gr.Dropdown(choices=AVAILABLE_MODELS, value=AVAILABLE_MODELS[0], label="ποΈ Select Model")
|
| 130 |
+
num_keywords_slider = gr.Slider(minimum=5, maximum=50, value=10, step=1, label="βοΈ Adjust Number of Keywords")
|
| 131 |
|
| 132 |
+
analyse_btn = gr.Button("π Extract Keywords", elem_classes="explorer-button")
|
| 133 |
|
| 134 |
summary_output = gr.HTML()
|
| 135 |
highlighted_output = gr.HTML()
|
|
|
|
| 143 |
|
| 144 |
gr.HTML("""
|
| 145 |
<hr style="margin-top: 40px; margin-bottom: 20px;">
|
| 146 |
+
<div style="background-color: #f8f9fa; padding: 20px; border-radius: 10px; text-align: center; border: 1px solid #ddd;">
|
| 147 |
<p style="font-size: 14px; line-height: 1.8; margin: 0;">
|
| 148 |
This <strong>Keyword Extraction Explorer Tool</strong> was created as part of the
|
| 149 |
+
<a href="https://digitalscholarship.web.ox.ac.uk/" target="_blank" style="color: #6C63FF;">
|
| 150 |
Digital Scholarship at Oxford (DiSc)
|
| 151 |
</a>
|
| 152 |
funded research project:
|