Spaces:
Build error
Build error
| import streamlit as st | |
| from docx import Document | |
| import pandas as pd | |
| # Function to parse the Word file | |
| def parse_word_file(file): | |
| document = Document(file) | |
| data = [] | |
| for paragraph in document.paragraphs: | |
| if "Name:" in paragraph.text and "Status:" in paragraph.text: | |
| parts = paragraph.text.split(",") | |
| name_part = next((part for part in parts if "Name:" in part), None) | |
| status_part = next((part for part in parts if "Status:" in part), None) | |
| if name_part and status_part: | |
| name = name_part.split(":")[1].strip() | |
| status = status_part.split(":")[1].strip() | |
| data.append({"Name": name, "Status": status}) | |
| return data | |
| # Streamlit app | |
| st.title("Display File Data with Filtering") | |
| st.write("Upload a Word file containing `Name` and `Status` data to display it in separate columns.") | |
| # File uploader | |
| uploaded_file = st.file_uploader("Upload a Word file (.docx)", type="docx") | |
| if uploaded_file: | |
| try: | |
| # Parse the file | |
| data = parse_word_file(uploaded_file) | |
| if data: | |
| # Convert to DataFrame for display | |
| df = pd.DataFrame(data) | |
| # Display the data | |
| st.write("### Full Data") | |
| st.dataframe(df) | |
| # Add checkboxes for filtering | |
| st.write("### Filter Data by Name") | |
| selected_names = st.multiselect("Select names to display", options=df["Name"].unique()) | |
| # Filter the DataFrame based on selected names | |
| if selected_names: | |
| filtered_df = df[df["Name"].isin(selected_names)] | |
| st.write("### Filtered Data") | |
| st.dataframe(filtered_df) | |
| else: | |
| st.write("No names selected.") | |
| else: | |
| st.error("No valid Name-Status data found in the file.") | |
| except Exception as e: | |
| st.error(f"An error occurred: {e}") | |