DSatishchandra commited on
Commit
2928d72
·
verified ·
1 Parent(s): 37746c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -38
app.py CHANGED
@@ -1,45 +1,35 @@
1
  import gradio as gr
2
-
3
- # Placeholder function for PO extraction
4
- # Replace this with the actual logic for processing the selected format
5
- def process_format(format_name):
6
- # Simulated logic for different formats
7
- if format_name == "BHEL.py":
8
- return "Processing in BHEL.py format..."
9
- elif format_name == "Federal Electric.py":
10
- return "Processing in Federal Electric.py format..."
11
- elif format_name == "AL-NISF":
12
- return "Processing in AL-NISF format..."
 
 
13
  else:
14
- return "Unknown format selected."
15
-
16
- # Define the dropdown options
17
- format_options = ["BHEL.py", "Federal Electric.py", "AL-NISF"]
18
-
19
- # Build the Gradio app
20
- def app():
21
- dropdown = gr.Dropdown(
22
- choices=format_options,
23
- label="Select Format",
24
- value="BHEL.py", # Default value
25
- interactive=True,
26
- )
27
-
28
- output = gr.Textbox(label="Result", interactive=False)
29
 
30
- # Update function to display result based on selected format
31
- def update(format_name):
32
- return process_format(format_name)
33
 
34
- interface = gr.Interface(
35
- fn=update,
36
- inputs=dropdown,
37
- outputs=output,
38
- title="PO Extraction Format Selector",
39
- description="Select the desired format from the dropdown, and the app will process accordingly."
40
- )
41
 
42
- return interface
 
 
 
 
 
 
 
 
43
 
44
  if __name__ == "__main__":
45
- app().launch()
 
1
  import gradio as gr
2
+ import pandas as pd
3
+ from BHEL import parse_bhel_pdf
4
+ from FederalElectric import parse_federal_electric_pdf
5
+ from ALNISF import parse_alnisf_pdf
6
+
7
+ def process_pdf(file, format_type):
8
+ # Select the appropriate parser based on format type
9
+ if format_type == "BHEL.py":
10
+ df = parse_bhel_pdf(file.name)
11
+ elif format_type == "Federal Electric.py":
12
+ df = parse_federal_electric_pdf(file.name)
13
+ elif format_type == "AL-NISF":
14
+ df = parse_alnisf_pdf(file.name)
15
  else:
16
+ return "Unsupported format selected", None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
+ # Save the DataFrame to an Excel file
19
+ output_file = f"{format_type}_Data.xlsx"
20
+ df.to_excel(output_file, index=False)
21
 
22
+ return output_file
 
 
 
 
 
 
23
 
24
+ # Gradio Interface
25
+ iface = gr.Interface(
26
+ fn=process_pdf,
27
+ inputs=[
28
+ gr.File(label="Upload PDF"),
29
+ gr.Dropdown(choices=["BHEL.py", "Federal Electric.py", "AL-NISF"], label="Select Format")
30
+ ],
31
+ outputs=gr.File(label="Download Excel")
32
+ )
33
 
34
  if __name__ == "__main__":
35
+ iface.launch()