jithenderchoudary commited on
Commit
71c8832
·
verified ·
1 Parent(s): 43fa626

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -2,6 +2,8 @@ import pdfplumber
2
  import re
3
  import PyPDF2
4
  import pandas as pd
 
 
5
 
6
  # Function to extract tables from PDF using pdfplumber
7
  def extract_table_from_pdf(pdf_path):
@@ -55,17 +57,21 @@ def process_po(pdf_path):
55
 
56
  return df
57
 
58
- # Main function to run the app
59
- def main(pdf_path):
60
- df = process_po(pdf_path)
61
-
62
- # Save the results to an Excel file
63
- output_file = 'extracted_data.xlsx'
64
- df.to_excel(output_file, index=False)
65
-
66
- print(f"Data extracted successfully. Results saved to {output_file}")
 
 
 
 
 
 
67
 
68
  if __name__ == "__main__":
69
- # Example PDF Path
70
- pdf_path = 'sample_po.pdf' # Replace with your PDF file path
71
- main(pdf_path)
 
2
  import re
3
  import PyPDF2
4
  import pandas as pd
5
+ import re
6
+ import gradio as gr
7
 
8
  # Function to extract tables from PDF using pdfplumber
9
  def extract_table_from_pdf(pdf_path):
 
57
 
58
  return df
59
 
60
+ # Gradio Interface
61
+ def gradio_interface(pdf_file):
62
+ """
63
+ Interface function for Gradio to process the PDF and return the Excel file.
64
+ """
65
+ return extract_data(pdf_file.name)
66
+
67
+ # Define Gradio interface
68
+ interface = gr.Interface(
69
+ fn=gradio_interface,
70
+ inputs=gr.File(label="Upload PDF"),
71
+ outputs=gr.File(label="Download Accurate Excel"),
72
+ title="Accurate BHEL PO Data Extractor",
73
+ description="Upload a PDF to extract accurate Material Numbers and related data into an Excel file."
74
+ )
75
 
76
  if __name__ == "__main__":
77
+ interface.launch()