Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import fitz # PyMuPDF
|
2 |
import pandas as pd
|
3 |
|
@@ -33,16 +34,32 @@ def dataframe_to_excel(df, excel_path):
|
|
33 |
|
34 |
# Main function
|
35 |
def main():
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
#
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
#
|
43 |
-
|
44 |
-
|
45 |
-
print(f"Excel saved to {excel_path}")
|
46 |
|
47 |
if __name__ == "__main__":
|
48 |
main()
|
|
|
1 |
+
import gradio as gr
|
2 |
import fitz # PyMuPDF
|
3 |
import pandas as pd
|
4 |
|
|
|
34 |
|
35 |
# Main function
|
36 |
def main():
|
37 |
+
def pdf_to_excel_function(pdf_file):
|
38 |
+
# Save the uploaded PDF to a temporary file
|
39 |
+
pdf_path = "temp.pdf"
|
40 |
+
with open(pdf_path, "wb") as f:
|
41 |
+
f.write(pdf_file.read())
|
42 |
+
|
43 |
+
# Convert PDF to DataFrame
|
44 |
+
df = pdf_to_dataframe(pdf_path)
|
45 |
+
|
46 |
+
# Save DataFrame to Excel
|
47 |
+
excel_path = "output.xlsx"
|
48 |
+
dataframe_to_excel(df, excel_path)
|
49 |
+
|
50 |
+
return excel_path
|
51 |
|
52 |
+
# Create the Gradio interface
|
53 |
+
iface = gr.Interface(
|
54 |
+
fn=pdf_to_excel_function,
|
55 |
+
inputs=gr.inputs.File(label="Upload PDF File"),
|
56 |
+
outputs=gr.outputs.File(label="Download Excel File"),
|
57 |
+
title="PDF to Excel Converter",
|
58 |
+
description="Convert a PDF file to an Excel file."
|
59 |
+
)
|
60 |
|
61 |
+
# Launch the interface
|
62 |
+
iface.launch()
|
|
|
|
|
63 |
|
64 |
if __name__ == "__main__":
|
65 |
main()
|