Commit
·
e8b6d9f
1
Parent(s):
b5eadfd
updated app
Browse files- Dockerfile +2 -4
- app.py +12 -8
- src/pipelines.py +5 -4
Dockerfile
CHANGED
@@ -1,10 +1,8 @@
|
|
1 |
FROM nvidia/cuda:12.3.2-cudnn9-devel-ubuntu22.04
|
2 |
|
3 |
-
ENV DEBIAN_FRONTEND=noninteractive
|
4 |
|
5 |
RUN apt-get update && apt-get install -y \
|
6 |
-
python3 python3-pip python3-venv build-essential curl git
|
7 |
-
weasyprint tzdata \
|
8 |
&& rm -rf /var/lib/apt/lists/*
|
9 |
|
10 |
RUN pip install --no-cache-dir --upgrade pip \
|
@@ -20,7 +18,7 @@ COPY pyproject.toml ./
|
|
20 |
|
21 |
RUN poetry install --no-interaction --no-ansi \
|
22 |
&& pip install --no-build-isolation flash-attn \
|
23 |
-
&& pip install "rerankers[all]"
|
24 |
|
25 |
RUN useradd -m -u 1000 user
|
26 |
USER user
|
|
|
1 |
FROM nvidia/cuda:12.3.2-cudnn9-devel-ubuntu22.04
|
2 |
|
|
|
3 |
|
4 |
RUN apt-get update && apt-get install -y \
|
5 |
+
python3 python3-pip python3-venv build-essential curl git \
|
|
|
6 |
&& rm -rf /var/lib/apt/lists/*
|
7 |
|
8 |
RUN pip install --no-cache-dir --upgrade pip \
|
|
|
18 |
|
19 |
RUN poetry install --no-interaction --no-ansi \
|
20 |
&& pip install --no-build-isolation flash-attn \
|
21 |
+
&& pip install "rerankers[all]"
|
22 |
|
23 |
RUN useradd -m -u 1000 user
|
24 |
USER user
|
app.py
CHANGED
@@ -7,7 +7,6 @@ import fitz
|
|
7 |
import json
|
8 |
from src.pipelines import InvoiceGenerator
|
9 |
|
10 |
-
print("HERE")
|
11 |
|
12 |
st.set_page_config(page_title="Invoice generator", layout="wide")
|
13 |
output_folder = "output"
|
@@ -39,26 +38,30 @@ def get_image_from_pdf(pdf_path):
|
|
39 |
img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
|
40 |
return img
|
41 |
|
|
|
|
|
|
|
|
|
42 |
|
43 |
def display_invoice(image_path):
|
44 |
-
|
45 |
-
|
46 |
try:
|
47 |
result = pipeline.generate_invoice(
|
48 |
-
image_path=image_path, output_path=
|
49 |
)
|
50 |
if result is None:
|
51 |
st.write("Image is irrelevant, upload another one")
|
52 |
st.session_state["status"] = "irrelevant"
|
53 |
return
|
54 |
-
print(f"Generated invoice: {
|
55 |
-
st.session_state["
|
56 |
st.session_state["invoice_info"] = result["invoice_info"]
|
57 |
st.session_state["invoice_path"] = f"{data_folder}/invoices/{result['invoice_path']}"
|
58 |
st.session_state["similar_image"] = f"{data_folder}/images/{result['similar_image']}"
|
59 |
st.session_state["damage_description"] = result["damage_description"]
|
60 |
st.session_state["detailed_damage_description"] = result["detailed_damage_description"]
|
61 |
-
return
|
62 |
except Exception as e:
|
63 |
st.write("Could not generate invoice, please try again")
|
64 |
print(e)
|
@@ -103,7 +106,8 @@ with col2:
|
|
103 |
|
104 |
with col3:
|
105 |
if st.session_state.get("status") == "loaded":
|
106 |
-
st.image(st.session_state["invoice"], caption="Generated invoice", use_container_width=True)
|
|
|
107 |
st.image(st.session_state["similar_image"], caption="Similar accident", width=300)
|
108 |
st.write(f"Detailed damage description: {st.session_state['detailed_damage_description']}")
|
109 |
st.write(f"Damage description: {st.session_state['damage_description']}")
|
|
|
7 |
import json
|
8 |
from src.pipelines import InvoiceGenerator
|
9 |
|
|
|
10 |
|
11 |
st.set_page_config(page_title="Invoice generator", layout="wide")
|
12 |
output_folder = "output"
|
|
|
38 |
img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
|
39 |
return img
|
40 |
|
41 |
+
def read_markdown_file(file_path):
|
42 |
+
with open(file_path, "r") as f:
|
43 |
+
return f.read()
|
44 |
+
|
45 |
|
46 |
def display_invoice(image_path):
|
47 |
+
output_md = "invoice_" + os.path.basename(image_path).split(".")[0] + ".md"
|
48 |
+
path_to_output_md = f"{output_folder}/{output_md}"
|
49 |
try:
|
50 |
result = pipeline.generate_invoice(
|
51 |
+
image_path=image_path, output_path=path_to_output_md, car_parts=car_parts
|
52 |
)
|
53 |
if result is None:
|
54 |
st.write("Image is irrelevant, upload another one")
|
55 |
st.session_state["status"] = "irrelevant"
|
56 |
return
|
57 |
+
print(f"Generated invoice: {path_to_output_md}")
|
58 |
+
st.session_state["generated_md"] = path_to_output_md
|
59 |
st.session_state["invoice_info"] = result["invoice_info"]
|
60 |
st.session_state["invoice_path"] = f"{data_folder}/invoices/{result['invoice_path']}"
|
61 |
st.session_state["similar_image"] = f"{data_folder}/images/{result['similar_image']}"
|
62 |
st.session_state["damage_description"] = result["damage_description"]
|
63 |
st.session_state["detailed_damage_description"] = result["detailed_damage_description"]
|
64 |
+
return read_markdown_file(path_to_output_md)
|
65 |
except Exception as e:
|
66 |
st.write("Could not generate invoice, please try again")
|
67 |
print(e)
|
|
|
106 |
|
107 |
with col3:
|
108 |
if st.session_state.get("status") == "loaded":
|
109 |
+
# st.image(st.session_state["invoice"], caption="Generated invoice", use_container_width=True)
|
110 |
+
st.markdown(st.session_state["invoice"])
|
111 |
st.image(st.session_state["similar_image"], caption="Similar accident", width=300)
|
112 |
st.write(f"Detailed damage description: {st.session_state['detailed_damage_description']}")
|
113 |
st.write(f"Damage description: {st.session_state['damage_description']}")
|
src/pipelines.py
CHANGED
@@ -2,7 +2,6 @@ from src.RAG import RAG
|
|
2 |
from src.model import Pixtral
|
3 |
from src.prompts import GENERATE_INVOICE_PROMPT, GENERATE_BRIEF_DAMAGE_DESCRIPTION_PROMPT, \
|
4 |
GENERATE_DETAILED_DAMAGE_DESCRIPTION_PROMPT
|
5 |
-
from md2pdf.core import md2pdf
|
6 |
from rerankers import Reranker
|
7 |
import re
|
8 |
from fuzzywuzzy import fuzz
|
@@ -39,7 +38,10 @@ class InvoiceGenerator:
|
|
39 |
with open(template_path, "r") as f:
|
40 |
md_text = f.read()
|
41 |
md_text = md_text.replace(r"<<table>>", generated_invoice)
|
42 |
-
|
|
|
|
|
|
|
43 |
|
44 |
@staticmethod
|
45 |
def check_within_range(generated_invoice, car_parts):
|
@@ -143,7 +145,6 @@ class InvoiceGenerator:
|
|
143 |
print(comparing_results)
|
144 |
|
145 |
if output_path:
|
146 |
-
self.format_invoice(generated_invoice=generated_invoice, output_path=output_path,
|
147 |
-
template_path=template_path)
|
148 |
|
149 |
return result
|
|
|
2 |
from src.model import Pixtral
|
3 |
from src.prompts import GENERATE_INVOICE_PROMPT, GENERATE_BRIEF_DAMAGE_DESCRIPTION_PROMPT, \
|
4 |
GENERATE_DETAILED_DAMAGE_DESCRIPTION_PROMPT
|
|
|
5 |
from rerankers import Reranker
|
6 |
import re
|
7 |
from fuzzywuzzy import fuzz
|
|
|
38 |
with open(template_path, "r") as f:
|
39 |
md_text = f.read()
|
40 |
md_text = md_text.replace(r"<<table>>", generated_invoice)
|
41 |
+
with open(output_path, "w") as f:
|
42 |
+
f.write(md_text)
|
43 |
+
# md2pdf(output_path, md_content=md_text)
|
44 |
+
return md_text
|
45 |
|
46 |
@staticmethod
|
47 |
def check_within_range(generated_invoice, car_parts):
|
|
|
145 |
print(comparing_results)
|
146 |
|
147 |
if output_path:
|
148 |
+
self.format_invoice(generated_invoice=generated_invoice, output_path=output_path, template_path=template_path)
|
|
|
149 |
|
150 |
return result
|