CoolFace
Apppublic

penosh/categoriser1

sourceHugging Faceunknownupdated 1y agoView on Hugging Face
0likes
app.py42 linesDownload Raw Back to root
1import streamlit as st
2import pandas as pd
3import io
4
5# Title
6st.title("Color Matcher from Text")
7
8# Upload Excel file
9uploaded_file = st.file_uploader("Upload an Excel file", type=["xlsx"])
10
11# Define colors to search
12colors = ['red', 'yellow', 'green', 'blue']
13
14# Function to find color in text
15def find_color(text):
16    for color in colors:
17        if color in str(text).lower():
18            return color
19    return ""
20
21# Process file
22if uploaded_file:
23    df = pd.read_excel(uploaded_file, engine='openpyxl')
24    df['Matched'] = df.iloc[:, 0].apply(find_color)
25
26    st.subheader("Processed Data")
27    st.dataframe(df)
28
29    # Create a downloadable Excel file in memory
30    output = io.BytesIO()
31    with pd.ExcelWriter(output, engine='openpyxl') as writer:
32        df.to_excel(writer, index=False)
33    output.seek(0)
34
35    # Download button
36    st.download_button(
37        label="Download Result",
38        data=output,
39        file_name="categorise_output.xlsx",
40        mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
41    )
42