Commit
·
7a67260
1
Parent(s):
2093584
fixed invoices display
Browse files- app.py +46 -21
- data/car_parts.json +0 -0
- src/pipelines.py +4 -4
app.py
CHANGED
@@ -68,30 +68,55 @@ def read_markdown_file(file_path):
|
|
68 |
with open(file_path, "r") as f:
|
69 |
return f.read()
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
def display_invoice(image_path):
|
73 |
output_pdf = "invoice_" + os.path.basename(image_path).split(".")[0] + ".pdf"
|
74 |
path_to_output_pdf = f"{output_folder}/{output_pdf}"
|
75 |
-
try:
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
except Exception as e:
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
|
97 |
st.title("Upload FNOL photo")
|
@@ -136,4 +161,4 @@ with col3:
|
|
136 |
st.image(st.session_state["similar_image"], caption="Similar accident", width=300)
|
137 |
st.write(f"Detailed damage description: {st.session_state['detailed_damage_description']}")
|
138 |
st.write(f"Damage description: {st.session_state['damage_description']}")
|
139 |
-
st.
|
|
|
68 |
with open(file_path, "r") as f:
|
69 |
return f.read()
|
70 |
|
71 |
+
def get_similar_invoice(invoice_name):
|
72 |
+
try:
|
73 |
+
with open(invoice_json_path, "r") as f:
|
74 |
+
invoice_json = json.load(f)
|
75 |
+
return invoice_json[invoice_name]
|
76 |
+
except Exception as e:
|
77 |
+
print(e)
|
78 |
+
return ""
|
79 |
+
|
80 |
|
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"] = f"{data_folder}/invoices/{result['invoice_path']}"
|
96 |
+
# st.session_state["similar_image"] = f"{data_folder}/images/{result['similar_image']}"
|
97 |
+
# st.session_state["damage_description"] = result["damage_description"]
|
98 |
+
# st.session_state["detailed_damage_description"] = result["detailed_damage_description"]
|
99 |
+
# return get_image_from_pdf(path_to_output_pdf)
|
100 |
+
# except Exception as e:
|
101 |
+
# st.write("Could not generate invoice, please try again")
|
102 |
+
# print(e)
|
103 |
+
# return None
|
104 |
+
result = pipeline.generate_invoice(
|
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 |
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.md(get_similar_invoice(st.session_state["invoice_path"]))
|
data/car_parts.json
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
src/pipelines.py
CHANGED
@@ -72,10 +72,10 @@ class InvoiceGenerator:
|
|
72 |
found_part = get_part_info(part, car_parts)
|
73 |
if found_part:
|
74 |
comparing_results[part] = {
|
75 |
-
"cost_within_range": car_parts[found_part]["
|
76 |
-
car_parts[found_part]["
|
77 |
-
"hours_within_range": car_parts[found_part]["
|
78 |
-
car_parts[found_part]["
|
79 |
"cost_diff": float(cost) - car_parts[found_part]["average_cost"],
|
80 |
"hours_diff": float(hours) - car_parts[found_part]["average_hours"],
|
81 |
"part_info": found_part
|
|
|
72 |
found_part = get_part_info(part, car_parts)
|
73 |
if found_part:
|
74 |
comparing_results[part] = {
|
75 |
+
"cost_within_range": car_parts[found_part]["cost_min"] <= float(cost) <=
|
76 |
+
car_parts[found_part]["cost_max"],
|
77 |
+
"hours_within_range": car_parts[found_part]["hours_min"] <= float(hours) <=
|
78 |
+
car_parts[found_part]["hours_max"],
|
79 |
"cost_diff": float(cost) - car_parts[found_part]["average_cost"],
|
80 |
"hours_diff": float(hours) - car_parts[found_part]["average_hours"],
|
81 |
"part_info": found_part
|