Spaces:
Sleeping
Sleeping
DSatishchandra
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
elif
|
12 |
-
|
|
|
|
|
13 |
else:
|
14 |
-
return "
|
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 |
-
#
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
if __name__ == "__main__":
|
45 |
-
|
|
|
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()
|