Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -715,7 +715,7 @@ ner_manager = HybridNERManager()
|
|
| 715 |
def process_text(text, standard_entities, custom_entities_str, confidence_threshold, selected_model, progress=gr.Progress()):
|
| 716 |
"""Main processing function for Gradio interface with progress tracking"""
|
| 717 |
if not text.strip():
|
| 718 |
-
return "β Please enter some text to analyse", "", ""
|
| 719 |
|
| 720 |
progress(0.1, desc="Initialising...")
|
| 721 |
|
|
@@ -728,7 +728,7 @@ def process_text(text, standard_entities, custom_entities_str, confidence_thresh
|
|
| 728 |
selected_standard = [entity for entity in standard_entities if entity]
|
| 729 |
|
| 730 |
if not selected_standard and not custom_entities:
|
| 731 |
-
return "β Please select at least one common entity type OR enter custom entity types", "", ""
|
| 732 |
|
| 733 |
progress(0.2, desc="Loading models...")
|
| 734 |
|
|
@@ -747,7 +747,7 @@ def process_text(text, standard_entities, custom_entities_str, confidence_thresh
|
|
| 747 |
all_entities.extend(custom_entity_results)
|
| 748 |
|
| 749 |
if not all_entities:
|
| 750 |
-
return "β No entities found. Try lowering the confidence threshold or using different entity types.", "", ""
|
| 751 |
|
| 752 |
progress(0.8, desc="Processing results...")
|
| 753 |
|
|
@@ -777,7 +777,7 @@ def process_text(text, standard_entities, custom_entities_str, confidence_thresh
|
|
| 777 |
|
| 778 |
progress(1.0, desc="Complete!")
|
| 779 |
|
| 780 |
-
return summary, legend_html + highlighted_html, results_html
|
| 781 |
|
| 782 |
# Create Gradio interface
|
| 783 |
def create_interface():
|
|
@@ -825,9 +825,9 @@ def create_interface():
|
|
| 825 |
|
| 826 |
# Add confidence threshold explanation
|
| 827 |
gr.HTML("""
|
| 828 |
-
<details style="margin: 10px 0; padding: 10px; background-color: #
|
| 829 |
-
<summary style="cursor: pointer; font-weight: bold; padding: 5px; color: #
|
| 830 |
-
βΉοΈ Understanding Confidence Threshold
|
| 831 |
</summary>
|
| 832 |
<div style="margin-top: 10px; padding: 10px; font-size: 14px;">
|
| 833 |
<p style="margin: 0 0 10px 0;">The <strong>confidence threshold</strong> controls how certain the model needs to be before identifying an entity:</p>
|
|
@@ -958,6 +958,9 @@ def create_interface():
|
|
| 958 |
|
| 959 |
analyse_btn = gr.Button("π Analyse Text", variant="primary", size="lg")
|
| 960 |
|
|
|
|
|
|
|
|
|
|
| 961 |
# Output sections
|
| 962 |
with gr.Row():
|
| 963 |
summary_output = gr.Markdown(label="Summary")
|
|
@@ -965,8 +968,8 @@ def create_interface():
|
|
| 965 |
with gr.Row():
|
| 966 |
highlighted_output = gr.HTML(label="Highlighted Text")
|
| 967 |
|
| 968 |
-
# Results section
|
| 969 |
-
with gr.Row():
|
| 970 |
with gr.Column():
|
| 971 |
gr.Markdown("### π Detailed Results")
|
| 972 |
results_output = gr.HTML(label="Entity Results")
|
|
@@ -981,14 +984,15 @@ def create_interface():
|
|
| 981 |
confidence_threshold,
|
| 982 |
model_dropdown
|
| 983 |
],
|
| 984 |
-
outputs=[summary_output, highlighted_output, results_output]
|
| 985 |
)
|
| 986 |
|
| 987 |
-
# Updated examples text
|
| 988 |
-
gr.
|
| 989 |
-
|
| 990 |
-
|
| 991 |
-
|
|
|
|
| 992 |
|
| 993 |
gr.Examples(
|
| 994 |
examples=[
|
|
@@ -1024,7 +1028,7 @@ def create_interface():
|
|
| 1024 |
label="Examples"
|
| 1025 |
)
|
| 1026 |
|
| 1027 |
-
# Add custom CSS to make Examples label black
|
| 1028 |
gr.HTML("""
|
| 1029 |
<style>
|
| 1030 |
/* Make the Examples label text black */
|
|
@@ -1040,6 +1044,20 @@ def create_interface():
|
|
| 1040 |
#examples-heading + div .label-text {
|
| 1041 |
color: black !important;
|
| 1042 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1043 |
</style>
|
| 1044 |
""")
|
| 1045 |
|
|
@@ -1084,7 +1102,7 @@ def create_interface():
|
|
| 1084 |
funded research project:<br>
|
| 1085 |
<em>Extracting Keywords from Crowdsourced Collections</em>.
|
| 1086 |
</p>
|
| 1087 |
-
<p style="font-size: 14px; line-height: 1.8; margin: 0;"
|
| 1088 |
The code for this tool was built with the aid of Claude Opus 4.</p>
|
| 1089 |
</p>
|
| 1090 |
</div>
|
|
|
|
| 715 |
def process_text(text, standard_entities, custom_entities_str, confidence_threshold, selected_model, progress=gr.Progress()):
|
| 716 |
"""Main processing function for Gradio interface with progress tracking"""
|
| 717 |
if not text.strip():
|
| 718 |
+
return "β Please enter some text to analyse", "", "", gr.update(visible=False)
|
| 719 |
|
| 720 |
progress(0.1, desc="Initialising...")
|
| 721 |
|
|
|
|
| 728 |
selected_standard = [entity for entity in standard_entities if entity]
|
| 729 |
|
| 730 |
if not selected_standard and not custom_entities:
|
| 731 |
+
return "β Please select at least one common entity type OR enter custom entity types", "", "", gr.update(visible=False)
|
| 732 |
|
| 733 |
progress(0.2, desc="Loading models...")
|
| 734 |
|
|
|
|
| 747 |
all_entities.extend(custom_entity_results)
|
| 748 |
|
| 749 |
if not all_entities:
|
| 750 |
+
return "β No entities found. Try lowering the confidence threshold or using different entity types.", "", "", gr.update(visible=False)
|
| 751 |
|
| 752 |
progress(0.8, desc="Processing results...")
|
| 753 |
|
|
|
|
| 777 |
|
| 778 |
progress(1.0, desc="Complete!")
|
| 779 |
|
| 780 |
+
return summary, legend_html + highlighted_html, results_html, gr.update(visible=True)
|
| 781 |
|
| 782 |
# Create Gradio interface
|
| 783 |
def create_interface():
|
|
|
|
| 825 |
|
| 826 |
# Add confidence threshold explanation
|
| 827 |
gr.HTML("""
|
| 828 |
+
<details style="margin: 10px 0; padding: 10px; background-color: #f8f9fa; border-radius: 8px; border: 1px solid #ddd;">
|
| 829 |
+
<summary style="cursor: pointer; font-weight: bold; padding: 5px; color: #1976d2;">
|
| 830 |
+
βΉοΈ Understanding the Confidence Threshold
|
| 831 |
</summary>
|
| 832 |
<div style="margin-top: 10px; padding: 10px; font-size: 14px;">
|
| 833 |
<p style="margin: 0 0 10px 0;">The <strong>confidence threshold</strong> controls how certain the model needs to be before identifying an entity:</p>
|
|
|
|
| 958 |
|
| 959 |
analyse_btn = gr.Button("π Analyse Text", variant="primary", size="lg")
|
| 960 |
|
| 961 |
+
# Add horizontal line separator after the button
|
| 962 |
+
gr.HTML("<hr style='margin-top: 20px; margin-bottom: 15px;'>")
|
| 963 |
+
|
| 964 |
# Output sections
|
| 965 |
with gr.Row():
|
| 966 |
summary_output = gr.Markdown(label="Summary")
|
|
|
|
| 968 |
with gr.Row():
|
| 969 |
highlighted_output = gr.HTML(label="Highlighted Text")
|
| 970 |
|
| 971 |
+
# Results section (initially hidden)
|
| 972 |
+
with gr.Row(visible=False) as results_row:
|
| 973 |
with gr.Column():
|
| 974 |
gr.Markdown("### π Detailed Results")
|
| 975 |
results_output = gr.HTML(label="Entity Results")
|
|
|
|
| 984 |
confidence_threshold,
|
| 985 |
model_dropdown
|
| 986 |
],
|
| 987 |
+
outputs=[summary_output, highlighted_output, results_output, results_row]
|
| 988 |
)
|
| 989 |
|
| 990 |
+
# Updated examples text with reduced spacing
|
| 991 |
+
with gr.Column():
|
| 992 |
+
gr.Markdown("""
|
| 993 |
+
### π‘ No example text to test? No problem!
|
| 994 |
+
Simply click on one of the examples provided below, and the fields will be populated for you.
|
| 995 |
+
""", elem_id="examples-heading")
|
| 996 |
|
| 997 |
gr.Examples(
|
| 998 |
examples=[
|
|
|
|
| 1028 |
label="Examples"
|
| 1029 |
)
|
| 1030 |
|
| 1031 |
+
# Add custom CSS to make Examples label black and improve entity label readability
|
| 1032 |
gr.HTML("""
|
| 1033 |
<style>
|
| 1034 |
/* Make the Examples label text black */
|
|
|
|
| 1044 |
#examples-heading + div .label-text {
|
| 1045 |
color: black !important;
|
| 1046 |
}
|
| 1047 |
+
|
| 1048 |
+
/* Improve readability of entity checkbox labels */
|
| 1049 |
+
.gradio-checkbox-group label {
|
| 1050 |
+
font-size: 14px !important;
|
| 1051 |
+
font-weight: normal !important;
|
| 1052 |
+
color: #333333 !important;
|
| 1053 |
+
line-height: 1.5 !important;
|
| 1054 |
+
}
|
| 1055 |
+
|
| 1056 |
+
/* Make the checkbox labels match the entity definitions style */
|
| 1057 |
+
input[type="checkbox"] + span {
|
| 1058 |
+
font-size: 14px !important;
|
| 1059 |
+
color: #333333 !important;
|
| 1060 |
+
}
|
| 1061 |
</style>
|
| 1062 |
""")
|
| 1063 |
|
|
|
|
| 1102 |
funded research project:<br>
|
| 1103 |
<em>Extracting Keywords from Crowdsourced Collections</em>.
|
| 1104 |
</p>
|
| 1105 |
+
<p><p style="font-size: 14px; line-height: 1.8; margin: 0;">
|
| 1106 |
The code for this tool was built with the aid of Claude Opus 4.</p>
|
| 1107 |
</p>
|
| 1108 |
</div>
|