Commit
·
c4c635a
1
Parent(s):
7a67260
fixed invoices display
Browse files- app.py +22 -37
- requirements.txt +2 -1
- src/pipelines.py +2 -0
app.py
CHANGED
@@ -81,42 +81,27 @@ def get_similar_invoice(invoice_name):
|
|
81 |
def display_invoice(image_path):
|
82 |
output_pdf = "invoice_" + os.path.basename(image_path).split(".")[0] + ".pdf"
|
83 |
path_to_output_pdf = f"{output_folder}/{output_pdf}"
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
image_path=image_path, output_path=path_to_output_pdf, car_parts=car_parts
|
106 |
-
)
|
107 |
-
if result is None:
|
108 |
-
st.write("Image is irrelevant, upload another one")
|
109 |
-
st.session_state["status"] = "irrelevant"
|
110 |
-
return
|
111 |
-
print(f"Generated invoice: {path_to_output_pdf}")
|
112 |
-
st.session_state["generated_pdf"] = path_to_output_pdf
|
113 |
-
st.session_state["invoice_info"] = result["invoice_info"]
|
114 |
-
st.session_state["invoice_path"] = result['invoice_path']
|
115 |
-
print(f"Invoice path: {result['invoice_path']}")
|
116 |
-
st.session_state["similar_image"] = f"{data_folder}/images/{result['similar_image']}"
|
117 |
-
st.session_state["damage_description"] = result["damage_description"]
|
118 |
-
st.session_state["detailed_damage_description"] = result["detailed_damage_description"]
|
119 |
-
return get_image_from_pdf(path_to_output_pdf)
|
120 |
|
121 |
|
122 |
st.title("Upload FNOL photo")
|
@@ -161,4 +146,4 @@ with col3:
|
|
161 |
st.image(st.session_state["similar_image"], caption="Similar accident", width=300)
|
162 |
st.write(f"Detailed damage description: {st.session_state['detailed_damage_description']}")
|
163 |
st.write(f"Damage description: {st.session_state['damage_description']}")
|
164 |
-
st.
|
|
|
81 |
def display_invoice(image_path):
|
82 |
output_pdf = "invoice_" + os.path.basename(image_path).split(".")[0] + ".pdf"
|
83 |
path_to_output_pdf = f"{output_folder}/{output_pdf}"
|
84 |
+
try:
|
85 |
+
result = pipeline.generate_invoice(
|
86 |
+
image_path=image_path, output_path=path_to_output_pdf, car_parts=car_parts
|
87 |
+
)
|
88 |
+
if result is None:
|
89 |
+
st.write("Image is irrelevant, upload another one")
|
90 |
+
st.session_state["status"] = "irrelevant"
|
91 |
+
return
|
92 |
+
print(f"Generated invoice: {path_to_output_pdf}")
|
93 |
+
st.session_state["generated_pdf"] = path_to_output_pdf
|
94 |
+
st.session_state["invoice_info"] = result["invoice_info"]
|
95 |
+
st.session_state["invoice_path"] = result['invoice_path']
|
96 |
+
print(f"Invoice path: {result['invoice_path']}")
|
97 |
+
st.session_state["similar_image"] = f"{data_folder}/images/{result['similar_image']}"
|
98 |
+
st.session_state["damage_description"] = result["damage_description"]
|
99 |
+
st.session_state["detailed_damage_description"] = result["detailed_damage_description"]
|
100 |
+
return get_image_from_pdf(path_to_output_pdf)
|
101 |
+
except Exception as e:
|
102 |
+
st.write("Could not generate invoice, please try again")
|
103 |
+
print(e)
|
104 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
|
107 |
st.title("Upload FNOL photo")
|
|
|
146 |
st.image(st.session_state["similar_image"], caption="Similar accident", width=300)
|
147 |
st.write(f"Detailed damage description: {st.session_state['detailed_damage_description']}")
|
148 |
st.write(f"Damage description: {st.session_state['damage_description']}")
|
149 |
+
st.markdown(get_similar_invoice(st.session_state["invoice_path"]))
|
requirements.txt
CHANGED
@@ -15,4 +15,5 @@ streamlit==1.40.1
|
|
15 |
fuzzywuzzy==0.18.0
|
16 |
openai==1.55.3
|
17 |
pandas==2.2.3
|
18 |
-
pypdf==5.1.0
|
|
|
|
15 |
fuzzywuzzy==0.18.0
|
16 |
openai==1.55.3
|
17 |
pandas==2.2.3
|
18 |
+
pypdf==5.1.0
|
19 |
+
tqdm==4.67.1
|
src/pipelines.py
CHANGED
@@ -93,6 +93,7 @@ class InvoiceGenerator:
|
|
93 |
total_cost_line = all_lines[last_cost_line]
|
94 |
lines = generated_invoice.split("\n")[first_cost_line:last_cost_line]
|
95 |
cost_lines = [[line.strip() for line in cost_line.split("|")] for cost_line in lines]
|
|
|
96 |
costs = [int(line[1]) + int(line[2]) * int(line[3]) for line in cost_lines]
|
97 |
cost_lines = list(map(lambda x, y: [x[0], x[1], x[2], x[3], str(y)], cost_lines, costs))
|
98 |
total_cost = sum(costs)
|
@@ -137,6 +138,7 @@ class InvoiceGenerator:
|
|
137 |
generated_invoice = self.model.generate_message_from_image(
|
138 |
GENERATE_INVOICE_PROMPT(invoice_info, detailed_damage_description), image_path
|
139 |
).replace("```markdown", "").replace("```", "")
|
|
|
140 |
generated_invoice = self.check_calculations(generated_invoice)
|
141 |
|
142 |
result["generated_invoice"] = generated_invoice
|
|
|
93 |
total_cost_line = all_lines[last_cost_line]
|
94 |
lines = generated_invoice.split("\n")[first_cost_line:last_cost_line]
|
95 |
cost_lines = [[line.strip() for line in cost_line.split("|")] for cost_line in lines]
|
96 |
+
print(f"Cost lines: \n{cost_lines}\n")
|
97 |
costs = [int(line[1]) + int(line[2]) * int(line[3]) for line in cost_lines]
|
98 |
cost_lines = list(map(lambda x, y: [x[0], x[1], x[2], x[3], str(y)], cost_lines, costs))
|
99 |
total_cost = sum(costs)
|
|
|
138 |
generated_invoice = self.model.generate_message_from_image(
|
139 |
GENERATE_INVOICE_PROMPT(invoice_info, detailed_damage_description), image_path
|
140 |
).replace("```markdown", "").replace("```", "")
|
141 |
+
print(f"Generated invoice: \n{generated_invoice}\n")
|
142 |
generated_invoice = self.check_calculations(generated_invoice)
|
143 |
|
144 |
result["generated_invoice"] = generated_invoice
|