Files changed (1) hide show
  1. app.py +45 -2
app.py CHANGED
@@ -5,6 +5,10 @@ import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
 
 
 
 
 
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
@@ -33,6 +37,45 @@ def get_current_time_in_timezone(timezone: str) -> str:
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  final_answer = FinalAnswerTool()
38
 
@@ -42,7 +85,7 @@ final_answer = FinalAnswerTool()
42
  model = HfApiModel(
43
  max_tokens=2096,
44
  temperature=0.5,
45
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
46
  custom_role_conversions=None,
47
  )
48
 
@@ -55,7 +98,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
 
8
+ import requests
9
+ from bs4 import BeautifulSoup
10
+
11
+
12
  from Gradio_UI import GradioUI
13
 
14
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
 
37
  except Exception as e:
38
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
39
 
40
+ @tool
41
+ def get_productName_and_prices_from_amazon_link(Amazon_link: str) -> str:
42
+ """A tool that gets the product name and price from provided amazon link.
43
+ Args:
44
+ Amazon_link: Amazon product link (e.g., 'https://www.amazon.co.uk/s-Oliver-Mens-Weste-Outdoor-Gilet/dp/B0B5HCKFX4?ref_=ast_sto_dp&psc=1').
45
+ """
46
+ try:
47
+
48
+
49
+ # Amazon product URL
50
+ url = Amazon_link
51
+
52
+ # Set headers to mimic a real browser
53
+ headers = {
54
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"
55
+ }
56
+
57
+ # Send a request to the webpage
58
+ response = requests.get(url, headers=headers)
59
+
60
+ # Parse the page
61
+ soup = BeautifulSoup(response.content, "html.parser")
62
+
63
+ # Extract product title
64
+ title = soup.find("span", {"id": "productTitle"}).text.strip()
65
+
66
+ # Extract product price (may vary based on availability)
67
+ price_element = soup.find("span", class_="a-offscreen")
68
+ price = price_element.text.strip() if price_element else "Price not available"
69
+
70
+ # Print results
71
+ print(f"Product Name: {title}")
72
+ print(f"Price: {price}")
73
+
74
+ return f"The Product Name is: {title} and the Price is:{price}"
75
+ except Exception as e:
76
+ return f"Error fetching Product name and price for this link{url}"
77
+
78
+
79
 
80
  final_answer = FinalAnswerTool()
81
 
 
85
  model = HfApiModel(
86
  max_tokens=2096,
87
  temperature=0.5,
88
+ model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded
89
  custom_role_conversions=None,
90
  )
91
 
 
98
 
99
  agent = CodeAgent(
100
  model=model,
101
+ tools=[final_answer,my_custom_tool,get_current_time_in_timezone,get_productName_and_prices_from_amazon_link,image_generation_tool], ## add your tools here (don't remove final answer)
102
  max_steps=6,
103
  verbosity_level=1,
104
  grammar=None,