Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
def process_file(file):
|
| 5 |
+
df = pd.read_excel(file.name, header=None)
|
| 6 |
+
|
| 7 |
+
# delete first 4 rows
|
| 8 |
+
df = df.iloc[4:].reset_index(drop=True)
|
| 9 |
+
|
| 10 |
+
# make sure columns up to J exist
|
| 11 |
+
while df.shape[1] < 10:
|
| 12 |
+
df[df.shape[1]] = ""
|
| 13 |
+
|
| 14 |
+
# column H = I - J
|
| 15 |
+
df.iloc[:,7] = df.iloc[:,8] - df.iloc[:,9]
|
| 16 |
+
|
| 17 |
+
output = "output.csv"
|
| 18 |
+
df.to_csv(output, index=False, header=False)
|
| 19 |
+
|
| 20 |
+
return output
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
+
fn=process_file,
|
| 25 |
+
inputs=gr.File(label="Upload Excel File"),
|
| 26 |
+
outputs=gr.File(label="Download CSV"),
|
| 27 |
+
title="Excel to CSV Tool"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
demo.launch()
|