shrudhit commited on
Commit
f992abc
·
verified ·
1 Parent(s): a3aacf0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -24
app.py CHANGED
@@ -1,43 +1,50 @@
1
  import gradio as gr
2
  import pandas as pd
3
 
4
- def process_file(file_path):
5
 
6
- # read correct sheet
7
- df = pd.read_excel(file_path, sheet_name="Price Recommendations-Fill This", header=None)
8
 
9
- # remove first 4 rows
10
- df = df.iloc[4:].reset_index(drop=True)
11
 
12
- # make sure at least 10 columns exist
13
- while df.shape[1] < 10:
14
- df[df.shape[1]] = 0
15
 
16
- # convert columns I and J to numbers
17
- col_i = pd.to_numeric(df.iloc[:,8], errors="coerce").fillna(0)
18
- col_j = pd.to_numeric(df.iloc[:,9], errors="coerce").fillna(0)
19
 
20
- # calculate column H
21
- df.iloc[:,7] = col_i - col_j
 
22
 
23
- # keep only rows where H < 59
24
- df = df[df.iloc[:,7] < 59]
 
25
 
26
- # sort column H from low to high
27
- df = df.sort_values(by=7)
28
 
29
- # save CSV
30
- output = "/tmp/output.csv"
31
- df.to_csv(output, index=False, header=False)
 
 
 
 
 
 
 
 
 
 
32
 
33
  return output
34
 
35
 
36
  demo = gr.Interface(
37
- fn=process_file,
38
- inputs=gr.File(type="filepath", label="Upload Excel File"),
39
- outputs=gr.File(label="Download CSV"),
40
- title="Excel Pricing Filter Tool"
41
  )
42
 
43
  demo.launch()
 
1
  import gradio as gr
2
  import pandas as pd
3
 
4
+ def process_files(files):
5
 
6
+ all_data = []
 
7
 
8
+ for file in files:
 
9
 
10
+ df = pd.read_excel(file.name, sheet_name="Price Recommendations-Fill This", header=None)
 
 
11
 
12
+ # remove first 4 rows
13
+ df = df.iloc[4:].reset_index(drop=True)
 
14
 
15
+ # ensure at least 10 columns
16
+ while df.shape[1] < 10:
17
+ df[df.shape[1]] = 0
18
 
19
+ # convert columns I and J
20
+ col_i = pd.to_numeric(df.iloc[:,8], errors="coerce").fillna(0)
21
+ col_j = pd.to_numeric(df.iloc[:,9], errors="coerce").fillna(0)
22
 
23
+ # H = I - J
24
+ df.iloc[:,7] = col_i - col_j
25
 
26
+ # filter H < 59
27
+ df = df[df.iloc[:,7] < 59]
28
+
29
+ all_data.append(df)
30
+
31
+ # merge all files
32
+ merged = pd.concat(all_data)
33
+
34
+ # sort H column low → high
35
+ merged = merged.sort_values(by=7)
36
+
37
+ output = "/tmp/merged_output.csv"
38
+ merged.to_csv(output, index=False, header=False)
39
 
40
  return output
41
 
42
 
43
  demo = gr.Interface(
44
+ fn=process_files,
45
+ inputs=gr.File(file_count="multiple", label="Upload Excel Files"),
46
+ outputs=gr.File(label="Download Merged CSV"),
47
+ title="Bulk Excel Pricing Tool"
48
  )
49
 
50
  demo.launch()