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