alexandraroze commited on
Commit
c6179a2
·
1 Parent(s): a839ed6

fixed pixtral

Browse files
Files changed (3) hide show
  1. app.py +8 -3
  2. src/model.py +2 -2
  3. src/prompts.py +6 -5
app.py CHANGED
@@ -55,8 +55,8 @@ if "pipeline" not in st.session_state:
55
  reranker_model="monovlm",
56
  device=device,
57
  invoice_json_path=invoice_json_path,
58
- gpu_memory_utilization=0.8,
59
- max_tokens=4096,
60
  )
61
  pipeline = st.session_state.pipeline
62
 
@@ -114,6 +114,11 @@ def display_invoice(image_path):
114
  return None
115
 
116
 
 
 
 
 
 
117
  st.title("Upload FNOL photo")
118
 
119
  col1, col2, col3 = st.columns([4, 1, 4])
@@ -124,7 +129,7 @@ with col1:
124
  try:
125
  image = Image.open(uploaded_image)
126
  image_path = f"{output_folder}/{str(uuid4())[:5]}.png"
127
- image.save(image_path)
128
  print(f"Image: {image_path}")
129
  st.image(image, caption="Uploaded photo", width=300)
130
  st.session_state["image"] = image_path
 
55
  reranker_model="monovlm",
56
  device=device,
57
  invoice_json_path=invoice_json_path,
58
+ gpu_memory_utilization=0.65,
59
+ max_tokens=2048,
60
  )
61
  pipeline = st.session_state.pipeline
62
 
 
114
  return None
115
 
116
 
117
+ def resize_image_and_save(img: Image, image_path: str, max_width: int = 800, max_height: int = 800):
118
+ img.thumbnail((max_width, max_height))
119
+ img.save(image_path, "PNG", quality=85)
120
+
121
+
122
  st.title("Upload FNOL photo")
123
 
124
  col1, col2, col3 = st.columns([4, 1, 4])
 
129
  try:
130
  image = Image.open(uploaded_image)
131
  image_path = f"{output_folder}/{str(uuid4())[:5]}.png"
132
+ resize_image_and_save(image, image_path)
133
  print(f"Image: {image_path}")
134
  st.image(image, caption="Uploaded photo", width=300)
135
  st.session_state["image"] = image_path
src/model.py CHANGED
@@ -9,10 +9,10 @@ def encode_image(image_path: str):
9
 
10
 
11
  class Pixtral:
12
- def __init__(self, max_model_len=4096, max_tokens=4096, gpu_memory_utilization=0.95, temperature=0.4):
13
  self.model_name = "mistralai/Pixtral-12B-2409"
14
 
15
- self.sampling_params = SamplingParams(max_tokens=max_tokens, temperature=temperature, top_p=0.8, top_k=40)
16
 
17
  self.llm = LLM(
18
  model=self.model_name,
 
9
 
10
 
11
  class Pixtral:
12
+ def __init__(self, max_model_len=4096, max_tokens=2048, gpu_memory_utilization=0.65, temperature=0.35):
13
  self.model_name = "mistralai/Pixtral-12B-2409"
14
 
15
+ self.sampling_params = SamplingParams(max_tokens=max_tokens, temperature=temperature)
16
 
17
  self.llm = LLM(
18
  model=self.model_name,
src/prompts.py CHANGED
@@ -4,6 +4,7 @@ The invoice should include details on the parts needing replacement, labor hours
4
  Include only repair and cost information, with no contact details or extra data.
5
 
6
  Important: Use the example invoice as a reference only. Do not copy it directly, but you can use labor costs and part names as a reference, if they are relevant to the image.
 
7
 
8
  The invoice should include a list of items, where each item has the following fields:
9
 
@@ -26,16 +27,16 @@ Gesamtkosten (Total Cost, EUR)
26
  ---
27
 
28
  **Guidelines for Generation:**
29
- 1. **Unique Response**: Generate reasonable variations in part types, costs, and labor hours based on the damage visible in the provided image.
30
- 2. **Check Calculations**: Ensure that **Gesamtkosten** for each item is calculated as:
 
31
  \[
32
  Gesamtkosten = Teilkosten + (Arbeitsstunden x Arbeitskosten)
33
  \]
34
  The **Gesamtsumme** should reflect the sum of all **Gesamtkosten** entries.
 
35
 
36
- Generate a detailed and realistic invoice tailored specifically to the image, without replicating the example.
37
-
38
- OUTPUT REQUIREMENTS:
39
  Your output should be a table in markdown format WITHOUT ANY ADDITIONAL COMMENTS. The format of a table is provided in reference invoice examle.
40
  """.format
41
 
 
4
  Include only repair and cost information, with no contact details or extra data.
5
 
6
  Important: Use the example invoice as a reference only. Do not copy it directly, but you can use labor costs and part names as a reference, if they are relevant to the image.
7
+ Pay attention to little details which are included in reference invoice. It's the granularity level which you must follow (but, again, do not copy all the details directly, only if they are indeed needed).
8
 
9
  The invoice should include a list of items, where each item has the following fields:
10
 
 
27
  ---
28
 
29
  **Guidelines for Generation:**
30
+ 1. **Adhere to Granularity**: Ensure that each damaged component is itemized in the invoice. Follow the level of granularity in the example invoice, avoiding broad categories like "front end" or "bumper assembly."
31
+ 2. **Realistic Labor and Costs**: Base labor hours and part costs on the visible damage described or implied in the image. Use reasonable values consistent with the invoice example.
32
+ 3. **Check Calculations**: Ensure that **Gesamtkosten** for each item is calculated as:
33
  \[
34
  Gesamtkosten = Teilkosten + (Arbeitsstunden x Arbeitskosten)
35
  \]
36
  The **Gesamtsumme** should reflect the sum of all **Gesamtkosten** entries.
37
+ 4. **Unique Response**: Generate variations in part names, costs, and labor hours specific to the image, while adhering to the reference invoice’s level of granularity.
38
 
39
+ **OUTPUT REQUIREMENTS:**
 
 
40
  Your output should be a table in markdown format WITHOUT ANY ADDITIONAL COMMENTS. The format of a table is provided in reference invoice examle.
41
  """.format
42