| | import pandas as pd |
| | import re |
| | import gradio as gr |
| |
|
| | |
| | def contains_matching_number(row, numbers_list): |
| | for item in row: |
| | item_str = str(item) |
| | for number in numbers_list: |
| | if re.search(fr"\b{number}\b", item_str[-4:]): |
| | return True |
| | return False |
| |
|
| | |
| | def process_excel(file, numbers): |
| | |
| | df = pd.read_excel(file, sheet_name=0) |
| |
|
| | |
| | numbers_list = numbers.split(",") |
| | numbers_list = [num.strip()[-4:] for num in numbers_list] |
| |
|
| | |
| | matched_rows = df[df.apply(lambda row: contains_matching_number(row, numbers_list), axis=1)] |
| |
|
| | |
| | output_file = "processed_data.xlsx" |
| | with pd.ExcelWriter(output_file, engine="openpyxl") as writer: |
| | df.to_excel(writer, sheet_name="OriginalData", index=False) |
| | matched_rows.to_excel(writer, sheet_name="MatchedRows", index=False) |
| |
|
| | return output_file |
| |
|
| | |
| | def gradio_interface(file, numbers): |
| | if file is None: |
| | return None |
| | processed_file = process_excel(file.name, numbers) |
| | return processed_file |
| |
|
| | |
| | iface = gr.Interface( |
| | fn=gradio_interface, |
| | inputs=[ |
| | gr.File(label="Upload Excel File"), |
| | gr.Textbox(label="Enter numbers to match (comma-separated)") |
| | ], |
| | outputs=gr.File(label="Download Processed Excel File"), |
| | title="Excel Row Matcher (Last 4 Digits)", |
| | description="Upload an Excel file and enter numbers. The script will find rows where any cell contains the last 4 digits matching the entered numbers and save them to a new sheet.", |
| | ) |
| |
|
| | |
| | iface.launch(share=True) |
| |
|