Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,22 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
from fpdf import FPDF
|
|
|
4 |
|
5 |
# Initialize an empty DataFrame to store invoice records
|
6 |
-
invoice_data = pd.DataFrame(columns=["Invoice No", "Date", "Amount"])
|
7 |
|
8 |
# Function to add new invoice entry and display total amount
|
9 |
-
def add_invoice(invoice_no, date, amount):
|
10 |
global invoice_data
|
11 |
# Add the new record to the DataFrame
|
12 |
-
new_row = {
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
invoice_data = pd.concat([invoice_data, pd.DataFrame([new_row])], ignore_index=True)
|
14 |
# Calculate the total amount
|
15 |
total_amount = invoice_data["Amount"].sum()
|
@@ -20,26 +27,37 @@ def generate_pdf():
|
|
20 |
global invoice_data
|
21 |
pdf = FPDF()
|
22 |
pdf.add_page()
|
23 |
-
|
24 |
-
|
25 |
-
#
|
26 |
-
pdf.cell(200, 10, txt="Invoice
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
# Table header
|
29 |
-
pdf.cell(
|
30 |
-
pdf.cell(
|
31 |
-
pdf.cell(
|
|
|
|
|
32 |
|
33 |
# Add invoice data to PDF
|
34 |
for index, row in invoice_data.iterrows():
|
35 |
-
pdf.cell(
|
36 |
-
pdf.cell(
|
37 |
-
pdf.cell(
|
|
|
|
|
38 |
|
39 |
# Add total amount at the end
|
40 |
total_amount = invoice_data["Amount"].sum()
|
41 |
-
pdf.cell(
|
42 |
-
pdf.cell(
|
43 |
|
44 |
# Save PDF to file
|
45 |
pdf_file_path = "/content/invoice_records.pdf"
|
@@ -49,8 +67,10 @@ def generate_pdf():
|
|
49 |
|
50 |
# Gradio interface
|
51 |
with gr.Blocks() as app:
|
52 |
-
# Section for adding new invoices
|
53 |
with gr.Row():
|
|
|
|
|
54 |
invoice_no = gr.Textbox(label="Invoice No")
|
55 |
date = gr.Textbox(label="Date")
|
56 |
amount = gr.Number(label="Amount")
|
@@ -67,8 +87,9 @@ with gr.Blocks() as app:
|
|
67 |
pdf_output = gr.File(label="Download PDF")
|
68 |
|
69 |
# Define button functionalities
|
70 |
-
add_button.click(add_invoice, [invoice_no, date, amount], [invoice_records, total_amount])
|
71 |
generate_pdf_button.click(generate_pdf, [], [pdf_output])
|
72 |
|
73 |
# Launch the app
|
74 |
app.launch(share=True)
|
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
from fpdf import FPDF
|
4 |
+
from datetime import datetime
|
5 |
|
6 |
# Initialize an empty DataFrame to store invoice records
|
7 |
+
invoice_data = pd.DataFrame(columns=["Company Name", "Name", "Invoice No", "Date", "Amount"])
|
8 |
|
9 |
# Function to add new invoice entry and display total amount
|
10 |
+
def add_invoice(company_name, name, invoice_no, date, amount):
|
11 |
global invoice_data
|
12 |
# Add the new record to the DataFrame
|
13 |
+
new_row = {
|
14 |
+
"Company Name": company_name,
|
15 |
+
"Name": name,
|
16 |
+
"Invoice No": invoice_no,
|
17 |
+
"Date": date,
|
18 |
+
"Amount": float(amount)
|
19 |
+
}
|
20 |
invoice_data = pd.concat([invoice_data, pd.DataFrame([new_row])], ignore_index=True)
|
21 |
# Calculate the total amount
|
22 |
total_amount = invoice_data["Amount"].sum()
|
|
|
27 |
global invoice_data
|
28 |
pdf = FPDF()
|
29 |
pdf.add_page()
|
30 |
+
|
31 |
+
# Add header
|
32 |
+
pdf.set_font("Arial", 'B', 16) # Bold and larger font for header
|
33 |
+
pdf.cell(200, 10, txt="Invoice Report", ln=True, align="C") # Report title
|
34 |
+
pdf.set_font("Arial", size=12) # Reset to normal font size
|
35 |
+
|
36 |
+
# Dynamic date in header
|
37 |
+
current_date = datetime.now().strftime("%d/%m/%Y")
|
38 |
+
pdf.cell(200, 10, txt="Generated Report", ln=True, align="C")
|
39 |
+
pdf.cell(200, 10, txt=f"Report Date: {current_date}", ln=True, align="C")
|
40 |
+
pdf.ln(10) # Add some space before the table starts
|
41 |
|
42 |
+
# Table header with Company Name and Name
|
43 |
+
pdf.cell(50, 10, txt="Company Name", border=1, align="C")
|
44 |
+
pdf.cell(40, 10, txt="Name", border=1, align="C")
|
45 |
+
pdf.cell(40, 10, txt="Invoice No", border=1, align="C")
|
46 |
+
pdf.cell(30, 10, txt="Date", border=1, align="C")
|
47 |
+
pdf.cell(30, 10, txt="Amount", border=1, ln=True, align="C")
|
48 |
|
49 |
# Add invoice data to PDF
|
50 |
for index, row in invoice_data.iterrows():
|
51 |
+
pdf.cell(50, 10, txt=str(row['Company Name']), border=1, align="C")
|
52 |
+
pdf.cell(40, 10, txt=str(row['Name']), border=1, align="C")
|
53 |
+
pdf.cell(40, 10, txt=str(row['Invoice No']), border=1, align="C")
|
54 |
+
pdf.cell(30, 10, txt=str(row['Date']), border=1, align="C")
|
55 |
+
pdf.cell(30, 10, txt=str(row['Amount']), border=1, ln=True, align="C")
|
56 |
|
57 |
# Add total amount at the end
|
58 |
total_amount = invoice_data["Amount"].sum()
|
59 |
+
pdf.cell(160, 10, txt="Total Amount", border=1, align="R")
|
60 |
+
pdf.cell(30, 10, txt=str(total_amount), border=1, ln=True, align="C")
|
61 |
|
62 |
# Save PDF to file
|
63 |
pdf_file_path = "/content/invoice_records.pdf"
|
|
|
67 |
|
68 |
# Gradio interface
|
69 |
with gr.Blocks() as app:
|
70 |
+
# Section for adding new invoices with Company Name and Name fields
|
71 |
with gr.Row():
|
72 |
+
company_name = gr.Textbox(label="Company Name")
|
73 |
+
name = gr.Textbox(label="Name")
|
74 |
invoice_no = gr.Textbox(label="Invoice No")
|
75 |
date = gr.Textbox(label="Date")
|
76 |
amount = gr.Number(label="Amount")
|
|
|
87 |
pdf_output = gr.File(label="Download PDF")
|
88 |
|
89 |
# Define button functionalities
|
90 |
+
add_button.click(add_invoice, [company_name, name, invoice_no, date, amount], [invoice_records, total_amount])
|
91 |
generate_pdf_button.click(generate_pdf, [], [pdf_output])
|
92 |
|
93 |
# Launch the app
|
94 |
app.launch(share=True)
|
95 |
+
|