bonrix commited on
Commit
6905e33
·
1 Parent(s): 659fcbb

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import gradio as gr
3
+
4
+ def compare_excel_files(new_file, old_file):
5
+ # Check if the file extensions are valid
6
+ if not new_file.name.endswith(".xlsx") or not old_file.name.endswith(".xlsx"):
7
+ raise ValueError("Invalid file type. Please upload Excel files with .xlsx extension.")
8
+
9
+ # Read the Excel files into pandas DataFrames
10
+ df_new = pd.read_excel(new_file.name)
11
+ df_old = pd.read_excel(old_file.name)
12
+
13
+ # Compare new file to old file (Find missing data in old file)
14
+ missing_in_old = df_new[~df_new.isin(df_old)].dropna()
15
+
16
+ # Compare old file to new file (Find added data in new file)
17
+ added_in_new = df_old[~df_old.isin(df_new)].dropna()
18
+
19
+ # Create Excel files for the comparison results
20
+ output_file_missing = 'missing_data_in_old.xlsx'
21
+ output_file_added = 'added_data_in_new.xlsx'
22
+ missing_in_old.to_excel(output_file_missing, index=False)
23
+ added_in_new.to_excel(output_file_added, index=False)
24
+
25
+ return output_file_missing, output_file_added
26
+
27
+ iface = gr.Interface(
28
+ fn=compare_excel_files,
29
+ inputs=[gr.inputs.File(label="New Excel File"), gr.inputs.File(label="Old Excel File")],
30
+ outputs=[gr.outputs.File(label="Missing Data in Old"), gr.outputs.File(label="Added Data in New")],
31
+ title="Excel File Comparison",
32
+ description="Upload two Excel files: one with new data and the other with old data to find missing data in old and added data in new."
33
+
34
+ )
35
+
36
+ iface.launch()