FredinVázquez commited on
Commit
2319ff0
·
1 Parent(s): 80842e9

update mise en place

Browse files
src/agents/mise_en_place.py CHANGED
@@ -6,6 +6,7 @@ import io
6
  import json
7
  import logging
8
  from typing import Optional
 
9
 
10
  from src import config
11
  from src.models.loader import get_vision_model
@@ -21,10 +22,9 @@ def _prompt() -> str:
21
 
22
  def _img_to_data_url(img) -> str:
23
  buf = io.BytesIO()
24
- img.save(buf, "JPEG", quality=85)
25
  b64 = base64.b64encode(buf.getvalue()).decode()
26
- return f"data:image/jpeg;base64,{b64}"
27
-
28
 
29
  _MOCK_INGREDIENTS = [
30
  "nothing",
@@ -43,18 +43,17 @@ def identify_ingredients(image: Optional[object]) -> list[str]:
43
  return list(_MOCK_INGREDIENTS)
44
 
45
  try:
 
46
  out = llm.create_chat_completion(
47
  messages=[
48
  {
49
  "role": "user",
50
  "content": [
51
- {"type": "image_url", "image_url": {"url": _img_to_data_url(image)}},
52
  {"type": "text", "text": _prompt()},
53
  ],
54
  }
55
  ],
56
- temperature=0.2,
57
- response_format={"type": "json_object"},
58
  )
59
  print(out)
60
  raw = out["choices"][0]["message"]["content"]
 
6
  import json
7
  import logging
8
  from typing import Optional
9
+ from PIL import Image
10
 
11
  from src import config
12
  from src.models.loader import get_vision_model
 
22
 
23
  def _img_to_data_url(img) -> str:
24
  buf = io.BytesIO()
25
+ img.save(buf, "PNG") # Probar con PNG
26
  b64 = base64.b64encode(buf.getvalue()).decode()
27
+ return f"data:image/png;base64,{b64}"
 
28
 
29
  _MOCK_INGREDIENTS = [
30
  "nothing",
 
43
  return list(_MOCK_INGREDIENTS)
44
 
45
  try:
46
+ image_url = _img_to_data_url(image)
47
  out = llm.create_chat_completion(
48
  messages=[
49
  {
50
  "role": "user",
51
  "content": [
52
+ {"type": "image_url", "image_url": {"url": image_url}},
53
  {"type": "text", "text": _prompt()},
54
  ],
55
  }
56
  ],
 
 
57
  )
58
  print(out)
59
  raw = out["choices"][0]["message"]["content"]
src/prompts/vision_prompt.txt CHANGED
@@ -1 +1 @@
1
- Describe the given image in detail, and identify any kind of food detected.
 
1
+ Describe the given image in detail. Be honest, do not say liers.