Spaces:
Running
Running
Commit
·
cfd3f46
1
Parent(s):
9b20d9d
Change category distribution from table to horizontal bar plot
Browse files- Replace DataFrame with BarPlot component for category distribution
- Display categories on y-axis with count bars extending horizontally
- Cleaner visualization of classification results
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- __pycache__/app.cpython-311.pyc +0 -0
- app.py +12 -8
__pycache__/app.cpython-311.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
|
|
|
app.py
CHANGED
|
@@ -556,18 +556,16 @@ is the key and a 1 if the category is present and a 0 if not.'''
|
|
| 556 |
python_version=python_version
|
| 557 |
)
|
| 558 |
|
| 559 |
-
# Build distribution summary DataFrame for
|
| 560 |
dist_data = []
|
| 561 |
total_rows = len(result)
|
| 562 |
for i, cat in enumerate(categories, 1):
|
| 563 |
col_name = f"category_{i}"
|
| 564 |
if col_name in result.columns:
|
| 565 |
count = int(result[col_name].sum())
|
| 566 |
-
pct = (count / total_rows) * 100 if total_rows > 0 else 0
|
| 567 |
dist_data.append({
|
| 568 |
"Category": cat,
|
| 569 |
-
"Count": count
|
| 570 |
-
"Percentage": f"{pct:.1f}%"
|
| 571 |
})
|
| 572 |
distribution_df = pd.DataFrame(dist_data)
|
| 573 |
|
|
@@ -627,7 +625,7 @@ def reset_all():
|
|
| 627 |
"", # api_key
|
| 628 |
"**Free tier** - no API key required! We cover the cost while CatLLM is in review.", # api_key_status
|
| 629 |
"Ready to classify", # status
|
| 630 |
-
gr.update(value=None, visible=False), #
|
| 631 |
gr.update(value=None, visible=False), # sample_results
|
| 632 |
gr.update(value=None, visible=False), # results
|
| 633 |
None, # download_file
|
|
@@ -793,7 +791,13 @@ https://github.com/chrissoria/cat-llm
|
|
| 793 |
|
| 794 |
with gr.Column():
|
| 795 |
status = gr.Markdown("Ready to classify")
|
| 796 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 797 |
sample_results = gr.DataFrame(label="Sample Results (First 5 Rows)", visible=False)
|
| 798 |
results = gr.DataFrame(label="Full Classification Results", visible=False)
|
| 799 |
download_file = gr.File(label="Download Results (CSV + Codebook PDF)", file_count="multiple")
|
|
@@ -840,7 +844,7 @@ https://github.com/chrissoria/cat-llm
|
|
| 840 |
classify_btn.click(
|
| 841 |
fn=classify_data,
|
| 842 |
inputs=[spreadsheet_file, spreadsheet_column] + category_inputs + [model_tier, model, model_source, api_key],
|
| 843 |
-
outputs=[
|
| 844 |
)
|
| 845 |
|
| 846 |
see_code_btn.click(
|
|
@@ -852,7 +856,7 @@ https://github.com/chrissoria/cat-llm
|
|
| 852 |
reset_btn.click(
|
| 853 |
fn=reset_all,
|
| 854 |
inputs=[],
|
| 855 |
-
outputs=[spreadsheet_file, spreadsheet_column] + category_inputs + [add_category_btn, category_count, model_tier, model, model_source, api_key, api_key_status, status,
|
| 856 |
)
|
| 857 |
|
| 858 |
|
|
|
|
| 556 |
python_version=python_version
|
| 557 |
)
|
| 558 |
|
| 559 |
+
# Build distribution summary DataFrame for bar plot
|
| 560 |
dist_data = []
|
| 561 |
total_rows = len(result)
|
| 562 |
for i, cat in enumerate(categories, 1):
|
| 563 |
col_name = f"category_{i}"
|
| 564 |
if col_name in result.columns:
|
| 565 |
count = int(result[col_name].sum())
|
|
|
|
| 566 |
dist_data.append({
|
| 567 |
"Category": cat,
|
| 568 |
+
"Count": count
|
|
|
|
| 569 |
})
|
| 570 |
distribution_df = pd.DataFrame(dist_data)
|
| 571 |
|
|
|
|
| 625 |
"", # api_key
|
| 626 |
"**Free tier** - no API key required! We cover the cost while CatLLM is in review.", # api_key_status
|
| 627 |
"Ready to classify", # status
|
| 628 |
+
gr.update(value=None, visible=False), # distribution_plot
|
| 629 |
gr.update(value=None, visible=False), # sample_results
|
| 630 |
gr.update(value=None, visible=False), # results
|
| 631 |
None, # download_file
|
|
|
|
| 791 |
|
| 792 |
with gr.Column():
|
| 793 |
status = gr.Markdown("Ready to classify")
|
| 794 |
+
distribution_plot = gr.BarPlot(
|
| 795 |
+
x="Count",
|
| 796 |
+
y="Category",
|
| 797 |
+
title="Category Distribution",
|
| 798 |
+
horizontal=True,
|
| 799 |
+
visible=False
|
| 800 |
+
)
|
| 801 |
sample_results = gr.DataFrame(label="Sample Results (First 5 Rows)", visible=False)
|
| 802 |
results = gr.DataFrame(label="Full Classification Results", visible=False)
|
| 803 |
download_file = gr.File(label="Download Results (CSV + Codebook PDF)", file_count="multiple")
|
|
|
|
| 844 |
classify_btn.click(
|
| 845 |
fn=classify_data,
|
| 846 |
inputs=[spreadsheet_file, spreadsheet_column] + category_inputs + [model_tier, model, model_source, api_key],
|
| 847 |
+
outputs=[distribution_plot, sample_results, results, download_file, status]
|
| 848 |
)
|
| 849 |
|
| 850 |
see_code_btn.click(
|
|
|
|
| 856 |
reset_btn.click(
|
| 857 |
fn=reset_all,
|
| 858 |
inputs=[],
|
| 859 |
+
outputs=[spreadsheet_file, spreadsheet_column] + category_inputs + [add_category_btn, category_count, model_tier, model, model_source, api_key, api_key_status, status, distribution_plot, sample_results, results, download_file, code_output]
|
| 860 |
)
|
| 861 |
|
| 862 |
|