Spaces:
Sleeping
Sleeping
Commit
·
c541cf3
1
Parent(s):
a1a06bd
latex
Browse files- app.py +25 -11
- invoice_generator.py +2 -0
- requirements.txt +2 -1
- output/template.tex → template.tex +0 -0
app.py
CHANGED
@@ -7,7 +7,7 @@ from invoice_generator import generate_invoice
|
|
7 |
|
8 |
st.set_page_config(page_title="Invoice generator", layout="wide")
|
9 |
output_folder = "output"
|
10 |
-
template =
|
11 |
|
12 |
|
13 |
def get_image_from_pdf(pdf_path):
|
@@ -20,9 +20,11 @@ def get_image_from_pdf(pdf_path):
|
|
20 |
|
21 |
def display_invoice(image_path):
|
22 |
output_pdf = "invoice_" + os.path.basename(image_path).split(".")[0] + ".pdf"
|
|
|
23 |
generate_invoice(image_path, output_pdf, template, output_folder)
|
24 |
-
print(f"Generated invoice: {
|
25 |
-
|
|
|
26 |
|
27 |
|
28 |
st.title("Upload FNOL photo")
|
@@ -32,22 +34,34 @@ col1, col2, col3 = st.columns([4, 1, 4])
|
|
32 |
with col1:
|
33 |
uploaded_image = st.file_uploader("Upload photo", type=["jpg", "jpeg", "png"])
|
34 |
if uploaded_image:
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
41 |
|
42 |
with col2:
|
43 |
if st.query_params.get("image"):
|
44 |
if st.button("Generate invoice"):
|
45 |
with st.spinner("Generating..."):
|
46 |
-
other_image = display_invoice(st.query_params["image"])
|
47 |
st.query_params["status"] = "loaded"
|
48 |
else:
|
49 |
st.button("Generate invoice", disabled=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
with col3:
|
52 |
if st.query_params.get("status") == "loaded":
|
53 |
-
st.image(other_image, caption="Generated invoice", use_column_width=True)
|
|
|
7 |
|
8 |
st.set_page_config(page_title="Invoice generator", layout="wide")
|
9 |
output_folder = "output"
|
10 |
+
template = "template.tex"
|
11 |
|
12 |
|
13 |
def get_image_from_pdf(pdf_path):
|
|
|
20 |
|
21 |
def display_invoice(image_path):
|
22 |
output_pdf = "invoice_" + os.path.basename(image_path).split(".")[0] + ".pdf"
|
23 |
+
path_to_output_pdf = f"{output_folder}/{output_pdf}"
|
24 |
generate_invoice(image_path, output_pdf, template, output_folder)
|
25 |
+
print(f"Generated invoice: {path_to_output_pdf}")
|
26 |
+
st.query_params["generated_pdf"] = path_to_output_pdf
|
27 |
+
return get_image_from_pdf(path_to_output_pdf)
|
28 |
|
29 |
|
30 |
st.title("Upload FNOL photo")
|
|
|
34 |
with col1:
|
35 |
uploaded_image = st.file_uploader("Upload photo", type=["jpg", "jpeg", "png"])
|
36 |
if uploaded_image:
|
37 |
+
try:
|
38 |
+
image = Image.open(uploaded_image)
|
39 |
+
image_path = f"{output_folder}/{str(uuid4())[:5]}.png"
|
40 |
+
image.save(image_path)
|
41 |
+
print(f"Image: {image_path}")
|
42 |
+
st.image(image, caption="Uploaded photo", width=300)
|
43 |
+
st.query_params["image"] = image_path
|
44 |
+
except Exception as e:
|
45 |
+
st.write(f"Coudn't load image: {e}")
|
46 |
|
47 |
with col2:
|
48 |
if st.query_params.get("image"):
|
49 |
if st.button("Generate invoice"):
|
50 |
with st.spinner("Generating..."):
|
51 |
+
st.session_state["other_image"] = display_invoice(st.query_params["image"])
|
52 |
st.query_params["status"] = "loaded"
|
53 |
else:
|
54 |
st.button("Generate invoice", disabled=True)
|
55 |
+
if st.query_params.get("generated_pdf"):
|
56 |
+
with open(st.query_params["generated_pdf"], "rb") as f:
|
57 |
+
file_data = f.read()
|
58 |
+
st.download_button(
|
59 |
+
label="Download invoice",
|
60 |
+
data=file_data,
|
61 |
+
file_name="generated_invoice.pdf",
|
62 |
+
mime="application/pdf"
|
63 |
+
)
|
64 |
|
65 |
with col3:
|
66 |
if st.query_params.get("status") == "loaded":
|
67 |
+
st.image(st.session_state["other_image"], caption="Generated invoice", use_column_width=True)
|
invoice_generator.py
CHANGED
@@ -121,6 +121,8 @@ def compile_latex(invoice_table, template, output_folder, output_pdf_name):
|
|
121 |
try:
|
122 |
subprocess.run(
|
123 |
[
|
|
|
|
|
124 |
"pdflatex",
|
125 |
"-interaction=nonstopmode",
|
126 |
"-output-directory",
|
|
|
121 |
try:
|
122 |
subprocess.run(
|
123 |
[
|
124 |
+
# "xelatex",
|
125 |
+
# "-interaction=batchmode",
|
126 |
"pdflatex",
|
127 |
"-interaction=nonstopmode",
|
128 |
"-output-directory",
|
requirements.txt
CHANGED
@@ -2,4 +2,5 @@ streamlit
|
|
2 |
pillow
|
3 |
tqdm
|
4 |
PyMuPDF
|
5 |
-
openai
|
|
|
|
2 |
pillow
|
3 |
tqdm
|
4 |
PyMuPDF
|
5 |
+
openai
|
6 |
+
texlive-full
|
output/template.tex → template.tex
RENAMED
File without changes
|