patrickligardes commited on
Commit
98ebf2e
·
verified ·
1 Parent(s): a7160fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -3,6 +3,14 @@ from openpyxl import load_workbook
3
  import gradio as gr
4
  import os
5
 
 
 
 
 
 
 
 
 
6
  # Function to extract and map data from the input workbook
7
  def transform_data(input_path, mapping_df):
8
  # Load the input workbook
@@ -29,10 +37,10 @@ def transform_data(input_path, mapping_df):
29
  return pd.DataFrame(output_data)
30
 
31
  # Main processing function
32
- def process_files(input_workbook, mapping_file, output_template):
33
  try:
34
- # Load the data mapping file
35
- mapping_df = pd.read_excel(mapping_file, sheet_name="Output")
36
 
37
  # Transform the data
38
  transformed_data = transform_data(input_workbook, mapping_df)
@@ -56,8 +64,8 @@ def process_files(input_workbook, mapping_file, output_template):
56
  return f"An error occurred: {e}"
57
 
58
  # Define the Gradio interface
59
- def generate_excel(input_workbook, mapping_file, output_template):
60
- result = process_files(input_workbook.name, mapping_file.name, output_template.name)
61
  if os.path.exists(result):
62
  return result
63
  else:
@@ -65,17 +73,16 @@ def generate_excel(input_workbook, mapping_file, output_template):
65
 
66
  with gr.Blocks() as app:
67
  gr.Markdown("# Excel Sheet Generator")
68
- gr.Markdown("Upload the input workbook, mapping file, and output template to generate the final Excel file.")
69
 
70
  with gr.Row():
71
  input_workbook = gr.File(label="Input Workbook", file_types=[".xlsx"])
72
- mapping_file = gr.File(label="Mapping File", file_types=[".xlsx"])
73
  output_template = gr.File(label="Output Template", file_types=[".xlsx"])
74
 
75
  output_file = gr.File(label="Generated Excel File")
76
  generate_button = gr.Button("Generate Excel File")
77
 
78
- generate_button.click(generate_excel, inputs=[input_workbook, mapping_file, output_template], outputs=[output_file])
79
 
80
  # Launch the app
81
  app.launch()
 
3
  import gradio as gr
4
  import os
5
 
6
+ # Load the constant mapping file (embedded in the app)
7
+ def load_mapping():
8
+ mapping_data = {
9
+ "PO Output Column": ["Column1", "Column2", "Column3"], # Replace with actual columns
10
+ "UVM MMB POLY STICKER Column": ["Fixed-Value1", "Fixed-Value2", "Fixed-Value3"] # Replace with mapping logic
11
+ }
12
+ return pd.DataFrame(mapping_data)
13
+
14
  # Function to extract and map data from the input workbook
15
  def transform_data(input_path, mapping_df):
16
  # Load the input workbook
 
37
  return pd.DataFrame(output_data)
38
 
39
  # Main processing function
40
+ def process_files(input_workbook, output_template):
41
  try:
42
+ # Load the constant mapping data
43
+ mapping_df = load_mapping()
44
 
45
  # Transform the data
46
  transformed_data = transform_data(input_workbook, mapping_df)
 
64
  return f"An error occurred: {e}"
65
 
66
  # Define the Gradio interface
67
+ def generate_excel(input_workbook, output_template):
68
+ result = process_files(input_workbook.name, output_template.name)
69
  if os.path.exists(result):
70
  return result
71
  else:
 
73
 
74
  with gr.Blocks() as app:
75
  gr.Markdown("# Excel Sheet Generator")
76
+ gr.Markdown("Upload the input workbook and output template to generate the final Excel file.")
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, output_template], outputs=[output_file])
86
 
87
  # Launch the app
88
  app.launch()