SorrelC commited on
Commit
e0cb85f
Β·
verified Β·
1 Parent(s): 7ba3b38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -21
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: #1976d2; color: white; padding: 2px 5px; '
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: #1976d2; 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,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: 15px; border-radius: 8px; border: 1px solid #ddd; margin-bottom: 20px;">
84
- <h3 style="margin-top: 0; color: #1976d2;">πŸ“Š 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: 15px; border: 2px solid #ddd; border-radius: 8px; background-color: #fafafa; margin: 10px 0;'>
92
- <h4 style='margin: 0 0 15px 0; color: #1976d2;'>πŸ“ Text with Highlighted Keywords</h4>
93
- <div style='line-height: 1.8; font-size: 16px; background-color: white; padding: 15px; border-radius: 5px;'>{highlighted_html}</div>
94
  </div>
95
  """
96
 
97
  table_section = f"""
98
  <div style="margin-top: 20px;">
99
- <h4 style="color: #1976d2; margin-bottom: 10px;">πŸ“‹ Extracted Keywords</h4>
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 Extraction (KE) Explorer Tool
110
-
111
- See what different Keyword Extraction (KE) models can do, and if this is useful to you.
112
 
113
  ---
114
 
115
- ### πŸ› οΈ How to use:
116
 
117
- 1. **πŸ“ Paste your text** below.
118
- 2. **πŸŽ›οΈ Choose a model** and **set keyword count**.
119
- 3. **πŸ” Click "Extract Keywords"** to see:
 
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="Paste your text here...", lines=10)
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="πŸ”’ Number of Keywords")
133
 
134
- analyse_btn = gr.Button("πŸ” Extract Keywords", variant="primary")
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: 8px; margin-top: 20px; text-align: center;">
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: #1976d2;">
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: