Spaces:
Build error
Build error
File size: 1,961 Bytes
d2f05a1 0628507 d48422d 0628507 d48422d 0628507 d48422d ebf461d 0628507 ebf461d d48422d ebf461d d48422d 0628507 d2f05a1 623a2be d48422d 0628507 d48422d d2f05a1 d48422d d2f05a1 d48422d 0628507 623a2be d48422d 623a2be d2f05a1 d48422d d2f05a1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | 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}")
|