Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,10 @@ import pandas as pd
|
|
2 |
from openpyxl import load_workbook
|
3 |
import gradio as gr
|
4 |
import os
|
|
|
|
|
|
|
|
|
5 |
|
6 |
# Load the constant mapping file (embedded in the app)
|
7 |
def load_mapping():
|
@@ -30,7 +34,7 @@ def transform_data(input_path, mapping_df):
|
|
30 |
# Handle fixed values
|
31 |
if "Fixed" in input_rule:
|
32 |
fixed_value = input_rule.split("-")[0].strip()
|
33 |
-
output_data[output_column] = [fixed_value] *
|
34 |
|
35 |
# Handle column mapping from input workbook
|
36 |
elif "." in input_rule:
|
@@ -40,6 +44,11 @@ def transform_data(input_path, mapping_df):
|
|
40 |
if column_name in sheet_data.columns:
|
41 |
output_data[output_column] = sheet_data[column_name].tolist()
|
42 |
|
|
|
|
|
|
|
|
|
|
|
43 |
return pd.DataFrame(output_data)
|
44 |
|
45 |
# Main processing function
|
@@ -53,6 +62,9 @@ def process_files(input_workbook):
|
|
53 |
|
54 |
# Load the output template (embedded in the app)
|
55 |
output_template_path = "output_template.xlsx" # Replace with the actual template file path
|
|
|
|
|
|
|
56 |
output_workbook = load_workbook(output_template_path)
|
57 |
output_sheet = output_workbook["363040"]
|
58 |
|
@@ -68,7 +80,7 @@ def process_files(input_workbook):
|
|
68 |
return output_file_path
|
69 |
|
70 |
except Exception as e:
|
71 |
-
return f"An error occurred: {e}"
|
72 |
|
73 |
# Define the Gradio interface
|
74 |
def generate_excel(input_workbook):
|
|
|
2 |
from openpyxl import load_workbook
|
3 |
import gradio as gr
|
4 |
import os
|
5 |
+
import warnings
|
6 |
+
|
7 |
+
# Suppress openpyxl warnings
|
8 |
+
warnings.filterwarnings("ignore", category=UserWarning, module="openpyxl")
|
9 |
|
10 |
# Load the constant mapping file (embedded in the app)
|
11 |
def load_mapping():
|
|
|
34 |
# Handle fixed values
|
35 |
if "Fixed" in input_rule:
|
36 |
fixed_value = input_rule.split("-")[0].strip()
|
37 |
+
output_data[output_column] = [fixed_value] * 10 # Placeholder for rows
|
38 |
|
39 |
# Handle column mapping from input workbook
|
40 |
elif "." in input_rule:
|
|
|
44 |
if column_name in sheet_data.columns:
|
45 |
output_data[output_column] = sheet_data[column_name].tolist()
|
46 |
|
47 |
+
# Fill missing columns with empty lists
|
48 |
+
for key in output_data:
|
49 |
+
if not output_data[key]:
|
50 |
+
output_data[key] = ["" for _ in range(10)]
|
51 |
+
|
52 |
return pd.DataFrame(output_data)
|
53 |
|
54 |
# Main processing function
|
|
|
62 |
|
63 |
# Load the output template (embedded in the app)
|
64 |
output_template_path = "output_template.xlsx" # Replace with the actual template file path
|
65 |
+
if not os.path.exists(output_template_path):
|
66 |
+
return "Output template file is missing."
|
67 |
+
|
68 |
output_workbook = load_workbook(output_template_path)
|
69 |
output_sheet = output_workbook["363040"]
|
70 |
|
|
|
80 |
return output_file_path
|
81 |
|
82 |
except Exception as e:
|
83 |
+
return f"An error occurred during file generation: {e}"
|
84 |
|
85 |
# Define the Gradio interface
|
86 |
def generate_excel(input_workbook):
|