Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,38 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
-
def process_file(
|
| 5 |
-
# file is a dict → get actual path
|
| 6 |
-
filepath = file["name"]
|
| 7 |
|
|
|
|
| 8 |
df = pd.read_excel(filepath, header=None)
|
| 9 |
|
| 10 |
# delete first 4 rows
|
| 11 |
df = df.iloc[4:].reset_index(drop=True)
|
| 12 |
|
| 13 |
-
#
|
| 14 |
while df.shape[1] < 10:
|
| 15 |
df[df.shape[1]] = ""
|
| 16 |
|
| 17 |
-
# convert I and J to numbers
|
| 18 |
df.iloc[:,8] = pd.to_numeric(df.iloc[:,8], errors="coerce")
|
| 19 |
df.iloc[:,9] = pd.to_numeric(df.iloc[:,9], errors="coerce")
|
| 20 |
|
| 21 |
-
# H = I - J
|
| 22 |
df.iloc[:,7] = df.iloc[:,8] - df.iloc[:,9]
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
-
return
|
| 28 |
|
| 29 |
|
| 30 |
demo = gr.Interface(
|
| 31 |
fn=process_file,
|
| 32 |
-
inputs=gr.File(),
|
| 33 |
-
outputs=gr.File(),
|
| 34 |
-
title="Excel to CSV Tool"
|
|
|
|
| 35 |
)
|
| 36 |
|
| 37 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
+
def process_file(filepath):
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# read excel file
|
| 7 |
df = pd.read_excel(filepath, header=None)
|
| 8 |
|
| 9 |
# delete first 4 rows
|
| 10 |
df = df.iloc[4:].reset_index(drop=True)
|
| 11 |
|
| 12 |
+
# make sure columns up to J exist
|
| 13 |
while df.shape[1] < 10:
|
| 14 |
df[df.shape[1]] = ""
|
| 15 |
|
| 16 |
+
# convert column I and J to numbers
|
| 17 |
df.iloc[:,8] = pd.to_numeric(df.iloc[:,8], errors="coerce")
|
| 18 |
df.iloc[:,9] = pd.to_numeric(df.iloc[:,9], errors="coerce")
|
| 19 |
|
| 20 |
+
# column H = I - J
|
| 21 |
df.iloc[:,7] = df.iloc[:,8] - df.iloc[:,9]
|
| 22 |
|
| 23 |
+
# save csv
|
| 24 |
+
output_file = "output.csv"
|
| 25 |
+
df.to_csv(output_file, index=False, header=False)
|
| 26 |
|
| 27 |
+
return output_file
|
| 28 |
|
| 29 |
|
| 30 |
demo = gr.Interface(
|
| 31 |
fn=process_file,
|
| 32 |
+
inputs=gr.File(type="filepath", label="Upload Excel File"),
|
| 33 |
+
outputs=gr.File(label="Download CSV"),
|
| 34 |
+
title="Excel to CSV Tool",
|
| 35 |
+
description="Upload Excel → Delete first 4 rows → Column H = I - J → Download CSV"
|
| 36 |
)
|
| 37 |
|
| 38 |
demo.launch()
|