Update app.py
Browse files1 unmodified line2345678910111213141516171819202122232425262728293031323334353637383940411 unmodified lineimport pandas as pddef process_file(file_path):try:# read exceldf = pd.read_excel(file_path, header=None)# delete first 4 rowsdf = df.iloc[4:].reset_index(drop=True)# ensure at least 10 columns (A–J)while df.shape[1] < 10:df[df.shape[1]] = ""# convert I and J to numbersdf.iloc[:,8] = pd.to_numeric(df.iloc[:,8], errors="coerce")df.iloc[:,9] = pd.to_numeric(df.iloc[:,9], errors="coerce")# H = I - Jdf.iloc[:,7] = df.iloc[:,8] - df.iloc[:,9]# save CSVoutput_file = "output.csv"df.to_csv(output_file, index=False, header=False)return output_fileexcept Exception as e:return str(e)demo = gr.Interface(fn=process_file,inputs=gr.File(type="filepath", label="Upload Excel File"),outputs=gr.File(label="Download CSV"),title="Excel to CSV Tool",description="Upload Excel → remove first 4 rows → H = I - J → download CSV")demo.launch()1 unmodified line234567891011121314151617181920212223242526272829303132333435361 unmodified lineimport pandas as pddef process_file(file_path):df = pd.read_excel(file_path, header=None)# delete first 4 rowsdf = df.iloc[4:].reset_index(drop=True)# ensure at least 10 columnswhile df.shape[1] < 10:df[df.shape[1]] = ""# convert column I and J to numbers safelydf.iloc[:,8] = pd.to_numeric(df.iloc[:,8], errors="coerce").fillna(0)df.iloc[:,9] = pd.to_numeric(df.iloc[:,9], errors="coerce").fillna(0)# H = I - Jdf.iloc[:,7] = df.iloc[:,8] - df.iloc[:,9]# save CSVoutput_file = "/tmp/output.csv"df.to_csv(output_file, index=False, header=False)return output_filedemo = gr.Interface(fn=process_file,inputs=gr.File(type="filepath", label="Upload Excel File"),outputs=gr.File(label="Download CSV"),title="Excel to CSV Tool")demo.launch()
app.py+16-21