Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +39 -6
src/streamlit_app.py
CHANGED
|
@@ -305,6 +305,7 @@ def generate_html_report(df, text_input, elapsed_time, df_topic_data):
|
|
| 305 |
FIX APPLIED: Removed the CSS Grid layout for the three comparative charts
|
| 306 |
(Pie, Category Count, Frequency) and stacked them vertically to prevent
|
| 307 |
overlapping and ensure reliable rendering across devices.
|
|
|
|
| 308 |
"""
|
| 309 |
|
| 310 |
# 1. Generate Visualizations (Plotly HTML)
|
|
@@ -331,7 +332,8 @@ def generate_html_report(df, text_input, elapsed_time, df_topic_data):
|
|
| 331 |
|
| 332 |
# 1c. Bar Chart (Category Count)
|
| 333 |
fig_bar_category = px.bar(grouped_counts, x='Category', y='Count',color='Category', title='Total Entities per Category',color_discrete_sequence=px.colors.qualitative.Pastel)
|
| 334 |
-
|
|
|
|
| 335 |
bar_category_html = fig_bar_category.to_html(full_html=False,include_plotlyjs='cdn')
|
| 336 |
|
| 337 |
# 1d. Bar Chart (Most Frequent Entities)
|
|
@@ -343,7 +345,8 @@ def generate_html_report(df, text_input, elapsed_time, df_topic_data):
|
|
| 343 |
|
| 344 |
if not repeating_entities.empty:
|
| 345 |
fig_bar_freq = px.bar(repeating_entities, x='Entity', y='Count',color='Entity', title='Top 10 Most Frequent Entities',color_discrete_sequence=px.colors.sequential.Plasma)
|
| 346 |
-
|
|
|
|
| 347 |
bar_freq_html = fig_bar_freq.to_html(full_html=False, include_plotlyjs='cdn')
|
| 348 |
|
| 349 |
# 1e. Network Graph HTML - UPDATED to pass text_input
|
|
@@ -452,9 +455,39 @@ def generate_html_report(df, text_input, elapsed_time, df_topic_data):
|
|
| 452 |
|
| 453 |
# --- Page Configuration and Styling (No Sidebar) ---
|
| 454 |
st.set_page_config(layout="wide", page_title="NER & Topic Report App")
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
st.subheader("NER and Topic Analysis Report Generator", divider="rainbow")
|
| 459 |
st.link_button("by nlpblogs", "https://nlpblogs.com", type="tertiary")
|
| 460 |
expander = st.expander("**Important notes**")
|
|
@@ -480,7 +513,7 @@ category_mapping = {
|
|
| 480 |
reverse_category_mapping = {label: category for category, label_list in category_mapping.items() for label in label_list}
|
| 481 |
|
| 482 |
# --- Model Loading ---
|
| 483 |
-
@st.
|
| 484 |
def load_ner_model():
|
| 485 |
"""Loads the GLiNER model and caches it."""
|
| 486 |
try:
|
|
|
|
| 305 |
FIX APPLIED: Removed the CSS Grid layout for the three comparative charts
|
| 306 |
(Pie, Category Count, Frequency) and stacked them vertically to prevent
|
| 307 |
overlapping and ensure reliable rendering across devices.
|
| 308 |
+
FIX 2 APPLIED: Increased the bottom margin (b) for both bar charts to prevent X-axis labels from being cut off.
|
| 309 |
"""
|
| 310 |
|
| 311 |
# 1. Generate Visualizations (Plotly HTML)
|
|
|
|
| 332 |
|
| 333 |
# 1c. Bar Chart (Category Count)
|
| 334 |
fig_bar_category = px.bar(grouped_counts, x='Category', y='Count',color='Category', title='Total Entities per Category',color_discrete_sequence=px.colors.qualitative.Pastel)
|
| 335 |
+
# FIX 2: Increased bottom margin from b=10 to b=100
|
| 336 |
+
fig_bar_category.update_layout(xaxis={'categoryorder': 'total descending'},margin=dict(t=50, b=100))
|
| 337 |
bar_category_html = fig_bar_category.to_html(full_html=False,include_plotlyjs='cdn')
|
| 338 |
|
| 339 |
# 1d. Bar Chart (Most Frequent Entities)
|
|
|
|
| 345 |
|
| 346 |
if not repeating_entities.empty:
|
| 347 |
fig_bar_freq = px.bar(repeating_entities, x='Entity', y='Count',color='Entity', title='Top 10 Most Frequent Entities',color_discrete_sequence=px.colors.sequential.Plasma)
|
| 348 |
+
# FIX 2: Increased bottom margin from b=10 to b=100
|
| 349 |
+
fig_bar_freq.update_layout(xaxis={'categoryorder': 'total descending'},margin=dict(t=50, b=100))
|
| 350 |
bar_freq_html = fig_bar_freq.to_html(full_html=False, include_plotlyjs='cdn')
|
| 351 |
|
| 352 |
# 1e. Network Graph HTML - UPDATED to pass text_input
|
|
|
|
| 455 |
|
| 456 |
# --- Page Configuration and Styling (No Sidebar) ---
|
| 457 |
st.set_page_config(layout="wide", page_title="NER & Topic Report App")
|
| 458 |
+
st.markdown(
|
| 459 |
+
"""
|
| 460 |
+
<style>
|
| 461 |
+
/* Overall app container - NO SIDEBAR */
|
| 462 |
+
.main {
|
| 463 |
+
background-color: #FFF0F5; /* Blanched Almond/Light Pink */
|
| 464 |
+
color: #333333; /* Dark grey text for contrast */
|
| 465 |
+
}
|
| 466 |
+
.stApp {
|
| 467 |
+
background-color: #FFF0F5;
|
| 468 |
+
}
|
| 469 |
+
/* Text Area background and text color (input fields) */
|
| 470 |
+
.stTextArea textarea {
|
| 471 |
+
background-color: #FFFAF0; /* Floral White/Near white for input fields */
|
| 472 |
+
color: #000000; /* Black text for input */
|
| 473 |
+
border: 1px solid #FF69B4; /* Deep Pink border */
|
| 474 |
+
}
|
| 475 |
+
/* Button styling */
|
| 476 |
+
.stButton > button {
|
| 477 |
+
background-color: #FF69B4; /* Deep Pink for the button */
|
| 478 |
+
color: #FFFFFF; /* White text for contrast */
|
| 479 |
+
border: none;
|
| 480 |
+
padding: 10px 20px;
|
| 481 |
+
border-radius: 5px;
|
| 482 |
+
}
|
| 483 |
+
/* Expander header and content background */
|
| 484 |
+
.streamlit-expanderHeader, .streamlit-expanderContent {
|
| 485 |
+
background-color: #FFE4E1; /* Misty Rose/Lighter Pink */
|
| 486 |
+
color: #333333;
|
| 487 |
+
}
|
| 488 |
+
</style>
|
| 489 |
+
""",
|
| 490 |
+
unsafe_allow_html=True)
|
| 491 |
st.subheader("NER and Topic Analysis Report Generator", divider="rainbow")
|
| 492 |
st.link_button("by nlpblogs", "https://nlpblogs.com", type="tertiary")
|
| 493 |
expander = st.expander("**Important notes**")
|
|
|
|
| 513 |
reverse_category_mapping = {label: category for category, label_list in category_mapping.items() for label in label_list}
|
| 514 |
|
| 515 |
# --- Model Loading ---
|
| 516 |
+
@st.cache_resourced
|
| 517 |
def load_ner_model():
|
| 518 |
"""Loads the GLiNER model and caches it."""
|
| 519 |
try:
|