Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import gradio as gr
|
3 |
import pandas as pd
|
4 |
from fpdf import FPDF
|
@@ -71,7 +70,7 @@ def generate_pdf(company_name):
|
|
71 |
# Check if file exists
|
72 |
if os.path.exists(pdf_file_path):
|
73 |
print(f"PDF successfully created at {pdf_file_path}")
|
74 |
-
return pdf_file_path
|
75 |
else:
|
76 |
return "Error: PDF not generated."
|
77 |
|
@@ -95,15 +94,24 @@ with gr.Blocks() as app:
|
|
95 |
invoice_records = gr.DataFrame(label="Invoice Records")
|
96 |
total_amount = gr.Textbox(label="Total Amount", interactive=False)
|
97 |
|
98 |
-
# Section for generating and
|
99 |
with gr.Row():
|
100 |
generate_pdf_button = gr.Button("Generate PDF")
|
101 |
-
|
102 |
|
103 |
# Define button functionalities
|
104 |
add_button.click(add_invoice, [company_name, name, invoice_no, date, amount], [invoice_records, total_amount])
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
# Launch the app
|
108 |
app.launch(share=True)
|
109 |
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
from fpdf import FPDF
|
|
|
70 |
# Check if file exists
|
71 |
if os.path.exists(pdf_file_path):
|
72 |
print(f"PDF successfully created at {pdf_file_path}")
|
73 |
+
return pdf_file_path
|
74 |
else:
|
75 |
return "Error: PDF not generated."
|
76 |
|
|
|
94 |
invoice_records = gr.DataFrame(label="Invoice Records")
|
95 |
total_amount = gr.Textbox(label="Total Amount", interactive=False)
|
96 |
|
97 |
+
# Section for generating and displaying PDF link
|
98 |
with gr.Row():
|
99 |
generate_pdf_button = gr.Button("Generate PDF")
|
100 |
+
pdf_link = gr.HTML() # To manually display the download link
|
101 |
|
102 |
# Define button functionalities
|
103 |
add_button.click(add_invoice, [company_name, name, invoice_no, date, amount], [invoice_records, total_amount])
|
104 |
+
|
105 |
+
def show_pdf_link(company_name):
|
106 |
+
pdf_path = generate_pdf(company_name)
|
107 |
+
if pdf_path != "Error: PDF generation failed.":
|
108 |
+
return f'<a href="{pdf_path}" target="_blank">Download PDF</a>'
|
109 |
+
else:
|
110 |
+
return "Error generating PDF."
|
111 |
+
|
112 |
+
generate_pdf_button.click(show_pdf_link, [company_name], pdf_link)
|
113 |
|
114 |
# Launch the app
|
115 |
app.launch(share=True)
|
116 |
|
117 |
+
|