Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,7 +37,7 @@ def transform_data(input_path, mapping_df):
|
|
| 37 |
return pd.DataFrame(output_data)
|
| 38 |
|
| 39 |
# Main processing function
|
| 40 |
-
def process_files(input_workbook
|
| 41 |
try:
|
| 42 |
# Load the constant mapping data
|
| 43 |
mapping_df = load_mapping()
|
|
@@ -45,8 +45,9 @@ def process_files(input_workbook, output_template):
|
|
| 45 |
# Transform the data
|
| 46 |
transformed_data = transform_data(input_workbook, mapping_df)
|
| 47 |
|
| 48 |
-
# Load the output template
|
| 49 |
-
|
|
|
|
| 50 |
output_sheet = output_workbook["363040"]
|
| 51 |
|
| 52 |
# Write transformed data to the output sheet
|
|
@@ -64,8 +65,8 @@ def process_files(input_workbook, output_template):
|
|
| 64 |
return f"An error occurred: {e}"
|
| 65 |
|
| 66 |
# Define the Gradio interface
|
| 67 |
-
def generate_excel(input_workbook
|
| 68 |
-
result = process_files(input_workbook.name
|
| 69 |
if os.path.exists(result):
|
| 70 |
return result
|
| 71 |
else:
|
|
@@ -73,16 +74,15 @@ def generate_excel(input_workbook, output_template):
|
|
| 73 |
|
| 74 |
with gr.Blocks() as app:
|
| 75 |
gr.Markdown("# Excel Sheet Generator")
|
| 76 |
-
gr.Markdown("Upload the input workbook
|
| 77 |
|
| 78 |
with gr.Row():
|
| 79 |
input_workbook = gr.File(label="Input Workbook", file_types=[".xlsx"])
|
| 80 |
-
output_template = gr.File(label="Output Template", file_types=[".xlsx"])
|
| 81 |
|
| 82 |
output_file = gr.File(label="Generated Excel File")
|
| 83 |
generate_button = gr.Button("Generate Excel File")
|
| 84 |
|
| 85 |
-
generate_button.click(generate_excel, inputs=[input_workbook
|
| 86 |
|
| 87 |
# Launch the app
|
| 88 |
app.launch()
|
|
|
|
| 37 |
return pd.DataFrame(output_data)
|
| 38 |
|
| 39 |
# Main processing function
|
| 40 |
+
def process_files(input_workbook):
|
| 41 |
try:
|
| 42 |
# Load the constant mapping data
|
| 43 |
mapping_df = load_mapping()
|
|
|
|
| 45 |
# Transform the data
|
| 46 |
transformed_data = transform_data(input_workbook, mapping_df)
|
| 47 |
|
| 48 |
+
# Load the output template (embedded in the app)
|
| 49 |
+
output_template_path = "output_template.xlsx" # Replace with the actual template file path
|
| 50 |
+
output_workbook = load_workbook(output_template_path)
|
| 51 |
output_sheet = output_workbook["363040"]
|
| 52 |
|
| 53 |
# Write transformed data to the output sheet
|
|
|
|
| 65 |
return f"An error occurred: {e}"
|
| 66 |
|
| 67 |
# Define the Gradio interface
|
| 68 |
+
def generate_excel(input_workbook):
|
| 69 |
+
result = process_files(input_workbook.name)
|
| 70 |
if os.path.exists(result):
|
| 71 |
return result
|
| 72 |
else:
|
|
|
|
| 74 |
|
| 75 |
with gr.Blocks() as app:
|
| 76 |
gr.Markdown("# Excel Sheet Generator")
|
| 77 |
+
gr.Markdown("Upload the input workbook to generate the final Excel file.")
|
| 78 |
|
| 79 |
with gr.Row():
|
| 80 |
input_workbook = gr.File(label="Input Workbook", file_types=[".xlsx"])
|
|
|
|
| 81 |
|
| 82 |
output_file = gr.File(label="Generated Excel File")
|
| 83 |
generate_button = gr.Button("Generate Excel File")
|
| 84 |
|
| 85 |
+
generate_button.click(generate_excel, inputs=[input_workbook], outputs=[output_file])
|
| 86 |
|
| 87 |
# Launch the app
|
| 88 |
app.launch()
|