Update app.py
Browse files
app.py
CHANGED
|
@@ -2,19 +2,19 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
import tempfile
|
| 4 |
|
| 5 |
-
def process_file(
|
| 6 |
|
| 7 |
# read correct sheet
|
| 8 |
-
df = pd.read_excel(
|
| 9 |
|
| 10 |
# delete first 4 rows
|
| 11 |
df = df.iloc[4:].reset_index(drop=True)
|
| 12 |
|
| 13 |
-
# ensure
|
| 14 |
while df.shape[1] < 10:
|
| 15 |
df[df.shape[1]] = ""
|
| 16 |
|
| 17 |
-
# convert
|
| 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 |
|
|
@@ -22,15 +22,15 @@ def process_file(file):
|
|
| 22 |
df.iloc[:,7] = df.iloc[:,8] - df.iloc[:,9]
|
| 23 |
|
| 24 |
# save CSV
|
| 25 |
-
|
| 26 |
-
df.to_csv(
|
| 27 |
|
| 28 |
-
return
|
| 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 |
)
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import tempfile
|
| 4 |
|
| 5 |
+
def process_file(file_path):
|
| 6 |
|
| 7 |
# read correct sheet
|
| 8 |
+
df = pd.read_excel(file_path, sheet_name="Price Recommendations-Fill This", 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 columns I and J to numeric
|
| 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 |
|
|
|
|
| 22 |
df.iloc[:,7] = df.iloc[:,8] - df.iloc[:,9]
|
| 23 |
|
| 24 |
# save CSV
|
| 25 |
+
output_path = "/tmp/output.csv"
|
| 26 |
+
df.to_csv(output_path, index=False, header=False)
|
| 27 |
|
| 28 |
+
return output_path
|
| 29 |
|
| 30 |
|
| 31 |
demo = gr.Interface(
|
| 32 |
fn=process_file,
|
| 33 |
+
inputs=gr.File(type="filepath", label="Upload Excel File"),
|
| 34 |
outputs=gr.File(label="Download CSV"),
|
| 35 |
title="Excel → CSV Tool"
|
| 36 |
)
|