Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +11 -11
src/streamlit_app.py
CHANGED
|
@@ -311,8 +311,8 @@ def fig_to_image_buffer(fig):
|
|
| 311 |
img_buffer = BytesIO(img_bytes)
|
| 312 |
return img_buffer
|
| 313 |
except Exception as e:
|
| 314 |
-
#
|
| 315 |
-
print(f"
|
| 316 |
return None
|
| 317 |
|
| 318 |
# --- PPTX GENERATION FUNCTION ---
|
|
@@ -408,7 +408,7 @@ def generate_pptx_report(df, text_input, elapsed_time, df_topic_data, reverse_ca
|
|
| 408 |
slide.shapes.title.text = "Entity Distribution Treemap (Chart Failed)"
|
| 409 |
# FIX: Safety check for placeholder index 1
|
| 410 |
if len(slide.placeholders) > 1:
|
| 411 |
-
slide.placeholders[1].text = "Chart generation failed
|
| 412 |
|
| 413 |
|
| 414 |
# 5. Entity Count Bar Chart Slide (Visualization)
|
|
@@ -434,7 +434,7 @@ def generate_pptx_report(df, text_input, elapsed_time, df_topic_data, reverse_ca
|
|
| 434 |
slide.shapes.title.text = "Total Entities per Category (Chart Failed)"
|
| 435 |
# FIX: Safety check for placeholder index 1
|
| 436 |
if len(slide.placeholders) > 1:
|
| 437 |
-
slide.placeholders[1].text = "Chart generation failed
|
| 438 |
|
| 439 |
|
| 440 |
# 6. Topic Modeling Bubble Chart Slide
|
|
@@ -452,7 +452,7 @@ def generate_pptx_report(df, text_input, elapsed_time, df_topic_data, reverse_ca
|
|
| 452 |
slide.shapes.title.text = "Topic Word Weights (Chart Failed)"
|
| 453 |
# FIX: Safety check for placeholder index 1
|
| 454 |
if len(slide.placeholders) > 1:
|
| 455 |
-
slide.placeholders[1].text = "Chart generation failed
|
| 456 |
|
| 457 |
else:
|
| 458 |
# Placeholder slide if topic modeling is not available
|
|
@@ -495,7 +495,7 @@ def generate_html_report(df, text_input, elapsed_time, df_topic_data):
|
|
| 495 |
path=[px.Constant("All Entities"), 'category', 'label', 'text'],
|
| 496 |
values='score',
|
| 497 |
color='category',
|
| 498 |
-
|
| 499 |
color_discrete_sequence=px.colors.sequential.Greys # Monochrome palette
|
| 500 |
)
|
| 501 |
fig_treemap.update_layout(margin=dict(t=50, l=25, r=25, b=25))
|
|
@@ -529,7 +529,7 @@ def generate_html_report(df, text_input, elapsed_time, df_topic_data):
|
|
| 529 |
network_html = network_fig.to_html(full_html=False, include_plotlyjs='cdn')
|
| 530 |
|
| 531 |
# 1f. Topic Charts HTML
|
| 532 |
-
topic_charts_html = '<h3>
|
| 533 |
if df_topic_data is not None and not df_topic_data.empty:
|
| 534 |
bubble_figure = create_topic_word_bubbles(df_topic_data)
|
| 535 |
if bubble_figure:
|
|
@@ -588,13 +588,13 @@ def generate_html_report(df, text_input, elapsed_time, df_topic_data):
|
|
| 588 |
<h2>3. Data Visualizations</h2>
|
| 589 |
<h3>3.1 Entity Distribution Treemap</h3>
|
| 590 |
<div class="chart-box">{treemap_html}</div>
|
| 591 |
-
<h3>3.2 Comparative Charts
|
| 592 |
<div class="chart-box">{pie_html}</div>
|
| 593 |
<div class="chart-box">{bar_category_html}</div>
|
| 594 |
<div class="chart-box">{bar_freq_html}</div>
|
| 595 |
-
<h3>3.3 Entity
|
| 596 |
<div class="chart-box">{network_html}</div>
|
| 597 |
-
<h2>4. Topic
|
| 598 |
{topic_charts_html}
|
| 599 |
</div></body></html>
|
| 600 |
"""
|
|
@@ -644,7 +644,7 @@ st.subheader("NER and Topic Analysis Report Generator", divider="gray") # Divide
|
|
| 644 |
st.link_button("by nlpblogs", "https://nlpblogs.com", type="secondary")
|
| 645 |
expander = st.expander("**Important notes**")
|
| 646 |
expander.write(f"""**Named Entities:** This app predicts fifteen (15) labels: {', '.join(entity_color_map.keys())}.
|
| 647 |
-
**Dependencies:** Note that **PPTX** and **image export** require the Python libraries `python-pptx`, `plotly`, and
|
| 648 |
**Results:** Results are compiled into a single, comprehensive **HTML report**, a **PowerPoint (.pptx) file**, and a **CSV file** for easy download and sharing.
|
| 649 |
**How to Use:** Type or paste your text into the text area below, then press Ctrl + Enter. Click the 'Results' button to extract entities and generate the report.""")
|
| 650 |
st.markdown("For any errors or inquiries, please contact us at [info@nlpblogs.com](mailto:info@nlpblogs.com)")
|
|
|
|
| 311 |
img_buffer = BytesIO(img_bytes)
|
| 312 |
return img_buffer
|
| 313 |
except Exception as e:
|
| 314 |
+
# Changed the error message to be more explicit about the Kaleido dependency issue
|
| 315 |
+
print(f"Plotly image export failed (Kaleido dependency error): {e}. This means the PPTX will contain placeholder slides where charts should be.")
|
| 316 |
return None
|
| 317 |
|
| 318 |
# --- PPTX GENERATION FUNCTION ---
|
|
|
|
| 408 |
slide.shapes.title.text = "Entity Distribution Treemap (Chart Failed)"
|
| 409 |
# FIX: Safety check for placeholder index 1
|
| 410 |
if len(slide.placeholders) > 1:
|
| 411 |
+
slide.placeholders[1].text = "Chart generation failed, likely due to a missing 'kaleido' dependency for static image export."
|
| 412 |
|
| 413 |
|
| 414 |
# 5. Entity Count Bar Chart Slide (Visualization)
|
|
|
|
| 434 |
slide.shapes.title.text = "Total Entities per Category (Chart Failed)"
|
| 435 |
# FIX: Safety check for placeholder index 1
|
| 436 |
if len(slide.placeholders) > 1:
|
| 437 |
+
slide.placeholders[1].text = "Chart generation failed, likely due to a missing 'kaleido' dependency for static image export."
|
| 438 |
|
| 439 |
|
| 440 |
# 6. Topic Modeling Bubble Chart Slide
|
|
|
|
| 452 |
slide.shapes.title.text = "Topic Word Weights (Chart Failed)"
|
| 453 |
# FIX: Safety check for placeholder index 1
|
| 454 |
if len(slide.placeholders) > 1:
|
| 455 |
+
slide.placeholders[1].text = "Chart generation failed, likely due to a missing 'kaleido' dependency for static image export."
|
| 456 |
|
| 457 |
else:
|
| 458 |
# Placeholder slide if topic modeling is not available
|
|
|
|
| 495 |
path=[px.Constant("All Entities"), 'category', 'label', 'text'],
|
| 496 |
values='score',
|
| 497 |
color='category',
|
| 498 |
+
title="Entity Distribution by Category and Label",
|
| 499 |
color_discrete_sequence=px.colors.sequential.Greys # Monochrome palette
|
| 500 |
)
|
| 501 |
fig_treemap.update_layout(margin=dict(t=50, l=25, r=25, b=25))
|
|
|
|
| 529 |
network_html = network_fig.to_html(full_html=False, include_plotlyjs='cdn')
|
| 530 |
|
| 531 |
# 1f. Topic Charts HTML
|
| 532 |
+
topic_charts_html = '<h3>Topic Word Weights (Bubble Chart)</h3>'
|
| 533 |
if df_topic_data is not None and not df_topic_data.empty:
|
| 534 |
bubble_figure = create_topic_word_bubbles(df_topic_data)
|
| 535 |
if bubble_figure:
|
|
|
|
| 588 |
<h2>3. Data Visualizations</h2>
|
| 589 |
<h3>3.1 Entity Distribution Treemap</h3>
|
| 590 |
<div class="chart-box">{treemap_html}</div>
|
| 591 |
+
<h3>3.2 Comparative Charts (Pie, Category Count, Frequency) - *Stacked Vertically*</h3>
|
| 592 |
<div class="chart-box">{pie_html}</div>
|
| 593 |
<div class="chart-box">{bar_category_html}</div>
|
| 594 |
<div class="chart-box">{bar_freq_html}</div>
|
| 595 |
+
<h3>3.3 Entity Co-occurrence Network (Edges = Same Sentence)</h3>
|
| 596 |
<div class="chart-box">{network_html}</div>
|
| 597 |
+
<h2>4. Topic Modeling (LDA on Entities)</h2>
|
| 598 |
{topic_charts_html}
|
| 599 |
</div></body></html>
|
| 600 |
"""
|
|
|
|
| 644 |
st.link_button("by nlpblogs", "https://nlpblogs.com", type="secondary")
|
| 645 |
expander = st.expander("**Important notes**")
|
| 646 |
expander.write(f"""**Named Entities:** This app predicts fifteen (15) labels: {', '.join(entity_color_map.keys())}.
|
| 647 |
+
**Dependencies:** Note that **PPTX** and **image export** require the Python libraries `python-pptx`, `plotly`, and **`kaleido`**. If charts in the PPTX are blank, please check your environment's $\text{kaleido}$ installation/permissions.
|
| 648 |
**Results:** Results are compiled into a single, comprehensive **HTML report**, a **PowerPoint (.pptx) file**, and a **CSV file** for easy download and sharing.
|
| 649 |
**How to Use:** Type or paste your text into the text area below, then press Ctrl + Enter. Click the 'Results' button to extract entities and generate the report.""")
|
| 650 |
st.markdown("For any errors or inquiries, please contact us at [info@nlpblogs.com](mailto:info@nlpblogs.com)")
|