Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -49,6 +49,10 @@ def transform_data(input_path, mapping_df):
|
|
49 |
# Main processing function
|
50 |
def process_files(input_workbook):
|
51 |
try:
|
|
|
|
|
|
|
|
|
52 |
# Load the constant mapping data
|
53 |
mapping_df = load_mapping()
|
54 |
|
@@ -58,7 +62,7 @@ def process_files(input_workbook):
|
|
58 |
# Load the output template (embedded in the app)
|
59 |
output_template_path = "Generated_Output.xlsx"
|
60 |
if not os.path.exists(output_template_path):
|
61 |
-
return "Output template file is missing."
|
62 |
|
63 |
output_workbook = load_workbook(output_template_path)
|
64 |
output_sheet = output_workbook.active
|
@@ -72,18 +76,17 @@ def process_files(input_workbook):
|
|
72 |
output_file_path = "Generated_Output_Final.xlsx"
|
73 |
output_workbook.save(output_file_path)
|
74 |
|
75 |
-
return output_file_path
|
76 |
|
77 |
except Exception as e:
|
78 |
-
return f"An error occurred during file generation: {e}"
|
79 |
|
80 |
# Define the Gradio interface
|
81 |
def generate_excel(input_workbook):
|
82 |
-
|
83 |
-
if
|
84 |
-
return
|
85 |
-
|
86 |
-
return "An error occurred during file generation."
|
87 |
|
88 |
with gr.Blocks() as app:
|
89 |
gr.Markdown("# Excel Sheet Generator")
|
@@ -93,9 +96,11 @@ with gr.Blocks() as app:
|
|
93 |
input_workbook = gr.File(label="Input Workbook", file_types=[".xlsx"])
|
94 |
|
95 |
output_file = gr.File(label="Generated Excel File")
|
|
|
|
|
96 |
generate_button = gr.Button("Generate Excel File")
|
97 |
|
98 |
-
generate_button.click(generate_excel, inputs=[input_workbook], outputs=[output_file])
|
99 |
|
100 |
# Launch the app
|
101 |
app.launch()
|
|
|
49 |
# Main processing function
|
50 |
def process_files(input_workbook):
|
51 |
try:
|
52 |
+
# Validate input file
|
53 |
+
if not os.path.exists(input_workbook):
|
54 |
+
return None, "Input workbook file does not exist."
|
55 |
+
|
56 |
# Load the constant mapping data
|
57 |
mapping_df = load_mapping()
|
58 |
|
|
|
62 |
# Load the output template (embedded in the app)
|
63 |
output_template_path = "Generated_Output.xlsx"
|
64 |
if not os.path.exists(output_template_path):
|
65 |
+
return None, "Output template file is missing."
|
66 |
|
67 |
output_workbook = load_workbook(output_template_path)
|
68 |
output_sheet = output_workbook.active
|
|
|
76 |
output_file_path = "Generated_Output_Final.xlsx"
|
77 |
output_workbook.save(output_file_path)
|
78 |
|
79 |
+
return output_file_path, None
|
80 |
|
81 |
except Exception as e:
|
82 |
+
return None, f"An error occurred during file generation: {e}"
|
83 |
|
84 |
# Define the Gradio interface
|
85 |
def generate_excel(input_workbook):
|
86 |
+
file_path, error = process_files(input_workbook.name)
|
87 |
+
if error:
|
88 |
+
return None, error
|
89 |
+
return file_path, "File generated successfully."
|
|
|
90 |
|
91 |
with gr.Blocks() as app:
|
92 |
gr.Markdown("# Excel Sheet Generator")
|
|
|
96 |
input_workbook = gr.File(label="Input Workbook", file_types=[".xlsx"])
|
97 |
|
98 |
output_file = gr.File(label="Generated Excel File")
|
99 |
+
status_message = gr.Textbox(label="Status", interactive=False)
|
100 |
+
|
101 |
generate_button = gr.Button("Generate Excel File")
|
102 |
|
103 |
+
generate_button.click(generate_excel, inputs=[input_workbook], outputs=[output_file, status_message])
|
104 |
|
105 |
# Launch the app
|
106 |
app.launch()
|