fmr-aeg commited on
Commit
61b219b
·
verified ·
1 Parent(s): 125de54

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. .idea/workspace.xml +1 -1
  2. app.py +4 -6
  3. src/aiagent/utils/ecom_tools.py +9 -19
.idea/workspace.xml CHANGED
@@ -267,7 +267,7 @@
267
  <workItem from="1747779058058" duration="9506000" />
268
  <workItem from="1747841281902" duration="245000" />
269
  <workItem from="1749511880222" duration="3463000" />
270
- <workItem from="1749582965687" duration="10202000" />
271
  </task>
272
  <task id="LOCAL-00001" summary="Last commit before refacto">
273
  <option name="closed" value="true" />
 
267
  <workItem from="1747779058058" duration="9506000" />
268
  <workItem from="1747841281902" duration="245000" />
269
  <workItem from="1749511880222" duration="3463000" />
270
+ <workItem from="1749582965687" duration="12333000" />
271
  </task>
272
  <task id="LOCAL-00001" summary="Last commit before refacto">
273
  <option name="closed" value="true" />
app.py CHANGED
@@ -6,13 +6,11 @@ from src.aiagent.utils.ecom_tools import (search_on_amazon,
6
  from src.aiagent.ui.main_gradio import GradioUI
7
  import yaml
8
  from src.aiagent.core.custom_python_executor import LocalPythonExecutor
9
- import requests
10
 
11
- # Machine localisation for debugging
12
- ip = requests.get("https://api.ipify.org").text
13
- location = requests.get(f"https://ipinfo.io/{ip}/json").json()
14
- print("IP:", ip)
15
- print("Localisation:", location)
16
 
17
  tools_model = LiteLLMModel(model_id='gemini/gemini-2.0-flash')
18
  # reasoning_model = LiteLLMModel(model_id='gpt-4o-mini')
 
6
  from src.aiagent.ui.main_gradio import GradioUI
7
  import yaml
8
  from src.aiagent.core.custom_python_executor import LocalPythonExecutor
 
9
 
10
+ # with open('config/secrets.yaml') as f:
11
+ # SECRETS = yaml.safe_load(f)
12
+ #
13
+ # os.environ['GEMINI_API_KEY'] = SECRETS['gemini_token']
 
14
 
15
  tools_model = LiteLLMModel(model_id='gemini/gemini-2.0-flash')
16
  # reasoning_model = LiteLLMModel(model_id='gpt-4o-mini')
src/aiagent/utils/ecom_tools.py CHANGED
@@ -5,7 +5,6 @@ import json
5
  import pandas as pd
6
  import re
7
  from typing import Any, Optional
8
- import random
9
 
10
 
11
  class ParserProductDescriptionWithGuideTool(Tool):
@@ -90,13 +89,11 @@ class GetProductDescriptionTool(Tool):
90
  def __init__(self):
91
  super().__init__()
92
  self.headers = {
93
- 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_3_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15',
94
- 'Accept-Language': 'en-US;q=0.9,en;q=0.8',
95
- 'Accept-Encoding': 'gzip, deflate, br',
96
- 'Connection': 'keep-alive',
97
- 'Upgrade-Insecure-Requests': '1',
98
  }
99
 
 
100
  @staticmethod
101
  def _clean_product_url(product_url: str) -> str:
102
  pattern = r"(https://www\.amazon\.[a-z.]+/[^/]+/dp/[^/]+)"
@@ -172,26 +169,19 @@ def search_on_amazon(keyword: str) -> list[dict]:
172
  """
173
 
174
  headers = {
175
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
176
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
177
- 'Accept-Language': 'en-US,en;q=0.9',
178
  'Accept-Encoding': 'gzip, deflate, br',
179
  'Connection': 'keep-alive',
180
  'Upgrade-Insecure-Requests': '1',
181
- 'Sec-Fetch-Dest': 'document',
182
- 'Sec-Fetch-Mode': 'navigate',
183
- 'Sec-Fetch-Site': 'none',
184
- 'Sec-Fetch-User': '?1',
185
  }
186
 
187
- url = f"https://www.amazon.com/s?k={keyword.replace(' ', '+')}" # Could be adapted for other countries
188
-
189
- print('debugging url', url)
190
 
191
  response = requests.get(url, headers=headers)
192
 
193
  if response.status_code != 200:
194
- print("Error during page loading")
195
 
196
  # Parsing using beautifulSoup
197
  soup = BeautifulSoup(response.text, 'html.parser')
@@ -220,7 +210,7 @@ def search_on_amazon(keyword: str) -> list[dict]:
220
  product_json['image_url'] = image_element.get('src')
221
 
222
  if link_element:
223
- product_json['product_link'] = 'https://www.amazon.com' + link_element['href']
224
 
225
  if price_element:
226
  product_json['price'] = price_element.get_text().replace("\\xa0", " ").replace("\xa0", " ")
@@ -305,7 +295,7 @@ class FilterProduct(Tool):
305
  "Tu dois répondre uniquement par 'oui' ou 'non' (sans autre explication), selon que le produit satisfait la condition ou non en t'aidant des differents champs du dictionnaire."
306
  "La réponse doit être exactement 'oui' ou 'non', en minuscules."
307
  )},
308
- {"role": "user", "content": f"Product : {product}\n Condition : {condition}"}
309
  ]
310
 
311
  result = self.model(messages).content.strip().lower()
 
5
  import pandas as pd
6
  import re
7
  from typing import Any, Optional
 
8
 
9
 
10
  class ParserProductDescriptionWithGuideTool(Tool):
 
89
  def __init__(self):
90
  super().__init__()
91
  self.headers = {
92
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
93
+ "Accept-Language": "en-US,en;q=0.9"
 
 
 
94
  }
95
 
96
+
97
  @staticmethod
98
  def _clean_product_url(product_url: str) -> str:
99
  pattern = r"(https://www\.amazon\.[a-z.]+/[^/]+/dp/[^/]+)"
 
169
  """
170
 
171
  headers = {
172
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
173
+ 'Accept-Language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7',
 
174
  'Accept-Encoding': 'gzip, deflate, br',
175
  'Connection': 'keep-alive',
176
  'Upgrade-Insecure-Requests': '1',
 
 
 
 
177
  }
178
 
179
+ url = f"https://www.amazon.fr/s?k={keyword.replace(' ', '+')}" # Could be adapted for other countries
 
 
180
 
181
  response = requests.get(url, headers=headers)
182
 
183
  if response.status_code != 200:
184
+ print("Error during page loading", response.status_code)
185
 
186
  # Parsing using beautifulSoup
187
  soup = BeautifulSoup(response.text, 'html.parser')
 
210
  product_json['image_url'] = image_element.get('src')
211
 
212
  if link_element:
213
+ product_json['product_link'] = 'https://www.amazon.fr' + link_element['href']
214
 
215
  if price_element:
216
  product_json['price'] = price_element.get_text().replace("\\xa0", " ").replace("\xa0", " ")
 
295
  "Tu dois répondre uniquement par 'oui' ou 'non' (sans autre explication), selon que le produit satisfait la condition ou non en t'aidant des differents champs du dictionnaire."
296
  "La réponse doit être exactement 'oui' ou 'non', en minuscules."
297
  )},
298
+ {"role": "user", "content": f"Produit : {product}\n Condition : {condition}"}
299
  ]
300
 
301
  result = self.model(messages).content.strip().lower()