Spaces:
Running
Running
Commit
·
5af250e
1
Parent(s):
9e11d83
Fix Streamlit app: use radio buttons instead of tabs for input selection
Browse files- Replace tabs with radio buttons for input type selection (more reliable)
- Fix page_icon to use emoji instead of file path
- Add proper session state initialization
- Ensure variables are correctly scoped
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
app.py
CHANGED
|
@@ -571,7 +571,7 @@ def create_distribution_chart(result_df, categories):
|
|
| 571 |
# Page config
|
| 572 |
st.set_page_config(
|
| 573 |
page_title="CatLLM - Research Data Classifier",
|
| 574 |
-
page_icon="
|
| 575 |
layout="wide"
|
| 576 |
)
|
| 577 |
|
|
@@ -586,6 +586,14 @@ if 'extracted_categories' not in st.session_state:
|
|
| 586 |
st.session_state.extracted_categories = None
|
| 587 |
if 'results' not in st.session_state:
|
| 588 |
st.session_state.results = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 589 |
|
| 590 |
# Logo and title
|
| 591 |
col_logo, col_title = st.columns([1, 6])
|
|
@@ -630,24 +638,33 @@ Soria, C. (2025). CatLLM: A Python package for LLM-based text classification. DO
|
|
| 630 |
col_input, col_output = st.columns([1, 1])
|
| 631 |
|
| 632 |
with col_input:
|
| 633 |
-
# Input type
|
| 634 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 635 |
|
| 636 |
-
with tab_survey:
|
| 637 |
uploaded_file = st.file_uploader(
|
| 638 |
"Upload Data (CSV or Excel)",
|
| 639 |
type=['csv', 'xlsx', 'xls'],
|
| 640 |
key="survey_file"
|
| 641 |
)
|
| 642 |
|
| 643 |
-
# Load example button
|
| 644 |
if st.button("Try Example Dataset", key="example_btn"):
|
| 645 |
-
|
| 646 |
-
st.session_state.example_loaded = True
|
| 647 |
-
except:
|
| 648 |
-
st.error("Could not load example dataset")
|
| 649 |
|
| 650 |
-
# Column selector
|
| 651 |
columns = []
|
| 652 |
df = None
|
| 653 |
if uploaded_file is not None:
|
|
@@ -675,15 +692,15 @@ with col_input:
|
|
| 675 |
key="survey_column"
|
| 676 |
)
|
| 677 |
|
| 678 |
-
input_type_selected = "text"
|
| 679 |
-
input_data = None
|
| 680 |
description = selected_column if columns else ""
|
| 681 |
original_filename = uploaded_file.name if uploaded_file else "example_data.csv"
|
| 682 |
|
| 683 |
if df is not None and columns and selected_column in columns:
|
| 684 |
input_data = df[selected_column].tolist()
|
| 685 |
|
| 686 |
-
|
|
|
|
|
|
|
| 687 |
pdf_files = st.file_uploader(
|
| 688 |
"Upload PDF Document(s)",
|
| 689 |
type=['pdf'],
|
|
@@ -704,11 +721,9 @@ with col_input:
|
|
| 704 |
key="pdf_mode"
|
| 705 |
)
|
| 706 |
|
| 707 |
-
input_type_selected = "pdf"
|
| 708 |
if pdf_files:
|
| 709 |
input_data = []
|
| 710 |
for f in pdf_files:
|
| 711 |
-
# Save to temp file
|
| 712 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.pdf') as tmp:
|
| 713 |
tmp.write(f.read())
|
| 714 |
input_data.append(tmp.name)
|
|
@@ -716,7 +731,9 @@ with col_input:
|
|
| 716 |
original_filename = "pdf_files"
|
| 717 |
st.success(f"Uploaded {len(pdf_files)} PDF file(s)")
|
| 718 |
|
| 719 |
-
|
|
|
|
|
|
|
| 720 |
image_files = st.file_uploader(
|
| 721 |
"Upload Images",
|
| 722 |
type=['png', 'jpg', 'jpeg', 'gif', 'webp'],
|
|
@@ -731,11 +748,9 @@ with col_input:
|
|
| 731 |
key="image_desc"
|
| 732 |
)
|
| 733 |
|
| 734 |
-
input_type_selected = "image"
|
| 735 |
if image_files:
|
| 736 |
input_data = []
|
| 737 |
for f in image_files:
|
| 738 |
-
# Save to temp file
|
| 739 |
suffix = '.' + f.name.split('.')[-1]
|
| 740 |
with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as tmp:
|
| 741 |
tmp.write(f.read())
|
|
|
|
| 571 |
# Page config
|
| 572 |
st.set_page_config(
|
| 573 |
page_title="CatLLM - Research Data Classifier",
|
| 574 |
+
page_icon="🐱",
|
| 575 |
layout="wide"
|
| 576 |
)
|
| 577 |
|
|
|
|
| 586 |
st.session_state.extracted_categories = None
|
| 587 |
if 'results' not in st.session_state:
|
| 588 |
st.session_state.results = None
|
| 589 |
+
if 'active_tab' not in st.session_state:
|
| 590 |
+
st.session_state.active_tab = "survey"
|
| 591 |
+
if 'survey_data' not in st.session_state:
|
| 592 |
+
st.session_state.survey_data = None
|
| 593 |
+
if 'pdf_data' not in st.session_state:
|
| 594 |
+
st.session_state.pdf_data = None
|
| 595 |
+
if 'image_data' not in st.session_state:
|
| 596 |
+
st.session_state.image_data = None
|
| 597 |
|
| 598 |
# Logo and title
|
| 599 |
col_logo, col_title = st.columns([1, 6])
|
|
|
|
| 638 |
col_input, col_output = st.columns([1, 1])
|
| 639 |
|
| 640 |
with col_input:
|
| 641 |
+
# Input type selector
|
| 642 |
+
input_type_choice = st.radio(
|
| 643 |
+
"Input Type",
|
| 644 |
+
options=["Survey Responses", "PDF Documents", "Images"],
|
| 645 |
+
horizontal=True,
|
| 646 |
+
key="input_type_radio"
|
| 647 |
+
)
|
| 648 |
+
|
| 649 |
+
# Initialize variables
|
| 650 |
+
input_data = None
|
| 651 |
+
input_type_selected = "text"
|
| 652 |
+
description = ""
|
| 653 |
+
original_filename = "data"
|
| 654 |
+
pdf_mode = "Image (visual documents)"
|
| 655 |
+
|
| 656 |
+
if input_type_choice == "Survey Responses":
|
| 657 |
+
input_type_selected = "text"
|
| 658 |
|
|
|
|
| 659 |
uploaded_file = st.file_uploader(
|
| 660 |
"Upload Data (CSV or Excel)",
|
| 661 |
type=['csv', 'xlsx', 'xls'],
|
| 662 |
key="survey_file"
|
| 663 |
)
|
| 664 |
|
|
|
|
| 665 |
if st.button("Try Example Dataset", key="example_btn"):
|
| 666 |
+
st.session_state.example_loaded = True
|
|
|
|
|
|
|
|
|
|
| 667 |
|
|
|
|
| 668 |
columns = []
|
| 669 |
df = None
|
| 670 |
if uploaded_file is not None:
|
|
|
|
| 692 |
key="survey_column"
|
| 693 |
)
|
| 694 |
|
|
|
|
|
|
|
| 695 |
description = selected_column if columns else ""
|
| 696 |
original_filename = uploaded_file.name if uploaded_file else "example_data.csv"
|
| 697 |
|
| 698 |
if df is not None and columns and selected_column in columns:
|
| 699 |
input_data = df[selected_column].tolist()
|
| 700 |
|
| 701 |
+
elif input_type_choice == "PDF Documents":
|
| 702 |
+
input_type_selected = "pdf"
|
| 703 |
+
|
| 704 |
pdf_files = st.file_uploader(
|
| 705 |
"Upload PDF Document(s)",
|
| 706 |
type=['pdf'],
|
|
|
|
| 721 |
key="pdf_mode"
|
| 722 |
)
|
| 723 |
|
|
|
|
| 724 |
if pdf_files:
|
| 725 |
input_data = []
|
| 726 |
for f in pdf_files:
|
|
|
|
| 727 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.pdf') as tmp:
|
| 728 |
tmp.write(f.read())
|
| 729 |
input_data.append(tmp.name)
|
|
|
|
| 731 |
original_filename = "pdf_files"
|
| 732 |
st.success(f"Uploaded {len(pdf_files)} PDF file(s)")
|
| 733 |
|
| 734 |
+
else: # Images
|
| 735 |
+
input_type_selected = "image"
|
| 736 |
+
|
| 737 |
image_files = st.file_uploader(
|
| 738 |
"Upload Images",
|
| 739 |
type=['png', 'jpg', 'jpeg', 'gif', 'webp'],
|
|
|
|
| 748 |
key="image_desc"
|
| 749 |
)
|
| 750 |
|
|
|
|
| 751 |
if image_files:
|
| 752 |
input_data = []
|
| 753 |
for f in image_files:
|
|
|
|
| 754 |
suffix = '.' + f.name.split('.')[-1]
|
| 755 |
with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as tmp:
|
| 756 |
tmp.write(f.read())
|