Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
-
from openpyxl import
|
| 3 |
-
from openpyxl.utils import get_column_letter
|
| 4 |
import gradio as gr
|
| 5 |
import os
|
| 6 |
import warnings
|
| 7 |
|
| 8 |
-
# Suppress
|
| 9 |
warnings.filterwarnings("ignore", category=UserWarning, module="openpyxl")
|
| 10 |
|
| 11 |
# Hardcoded mapping logic (from reference file)
|
|
@@ -57,15 +56,17 @@ def process_files(input_workbook):
|
|
| 57 |
# Transform the data
|
| 58 |
transformed_data = transform_data(input_workbook)
|
| 59 |
|
| 60 |
-
#
|
| 61 |
-
|
| 62 |
-
if not os.path.exists(output_template_path):
|
| 63 |
-
return None, "Output template file is missing."
|
| 64 |
-
|
| 65 |
-
output_workbook = load_workbook(output_template_path)
|
| 66 |
output_sheet = output_workbook.active
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
# Write
|
| 69 |
for row_idx, row_data in enumerate(transformed_data.itertuples(index=False), start=2):
|
| 70 |
for col_idx, value in enumerate(row_data, start=1):
|
| 71 |
output_sheet.cell(row=row_idx, column=col_idx, value=value)
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
+
from openpyxl import Workbook
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import os
|
| 5 |
import warnings
|
| 6 |
|
| 7 |
+
# Suppress warnings
|
| 8 |
warnings.filterwarnings("ignore", category=UserWarning, module="openpyxl")
|
| 9 |
|
| 10 |
# Hardcoded mapping logic (from reference file)
|
|
|
|
| 56 |
# Transform the data
|
| 57 |
transformed_data = transform_data(input_workbook)
|
| 58 |
|
| 59 |
+
# Create a new workbook for the output
|
| 60 |
+
output_workbook = Workbook()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
output_sheet = output_workbook.active
|
| 62 |
+
output_sheet.title = "Generated Output"
|
| 63 |
+
|
| 64 |
+
# Write headers
|
| 65 |
+
headers = transformed_data.columns.tolist()
|
| 66 |
+
for col_idx, header in enumerate(headers, start=1):
|
| 67 |
+
output_sheet.cell(row=1, column=col_idx, value=header)
|
| 68 |
|
| 69 |
+
# Write data rows
|
| 70 |
for row_idx, row_data in enumerate(transformed_data.itertuples(index=False), start=2):
|
| 71 |
for col_idx, value in enumerate(row_data, start=1):
|
| 72 |
output_sheet.cell(row=row_idx, column=col_idx, value=value)
|