zerito commited on
Commit
9ddf866
·
verified ·
1 Parent(s): c1b6b5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -1,8 +1,9 @@
1
-
2
- from smolagents import CodeAgent, HfApiModel, load_tool, tool
3
  import requests
4
  from tools.final_answer import FinalAnswerTool
5
  from Gradio_UI import GradioUI
 
 
6
 
7
  @tool
8
  def get_btc_price() -> str:
@@ -18,8 +19,6 @@ def get_btc_price() -> str:
18
  return f"The current Bitcoin price is ${price:.2f} USD."
19
 
20
 
21
-
22
-
23
  @tool
24
  def visit_webpage(url: str) -> str:
25
  """Visits a webpage at the given URL and returns its content as a markdown string.
@@ -36,20 +35,19 @@ def visit_webpage(url: str) -> str:
36
  response.raise_for_status() # Raise an exception for bad status codes
37
 
38
  # Convert the HTML content to Markdown
39
- markdown_content = markdownify(response.text).strip()
40
 
41
  # Remove multiple line breaks
42
  markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content)
43
 
44
  return markdown_content
45
 
46
- except RequestException as e:
47
  return f"Error fetching the webpage: {str(e)}"
48
  except Exception as e:
49
  return f"An unexpected error occurred: {str(e)}"
50
 
51
 
52
-
53
  # Initialize the FinalAnswerTool
54
  final_answer = FinalAnswerTool()
55
 
@@ -61,10 +59,6 @@ model = HfApiModel(
61
  custom_role_conversions=None,
62
  )
63
 
64
- # Load additional tools if needed
65
- # For example, to load an image generation tool:
66
- # image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
67
-
68
  # Create the agent
69
  agent = CodeAgent(
70
  model=model,
 
1
+ from smolagents import CodeAgent, HfApiModel, tool
 
2
  import requests
3
  from tools.final_answer import FinalAnswerTool
4
  from Gradio_UI import GradioUI
5
+ import markdownify
6
+ import re
7
 
8
  @tool
9
  def get_btc_price() -> str:
 
19
  return f"The current Bitcoin price is ${price:.2f} USD."
20
 
21
 
 
 
22
  @tool
23
  def visit_webpage(url: str) -> str:
24
  """Visits a webpage at the given URL and returns its content as a markdown string.
 
35
  response.raise_for_status() # Raise an exception for bad status codes
36
 
37
  # Convert the HTML content to Markdown
38
+ markdown_content = markdownify.markdownify(response.text).strip()
39
 
40
  # Remove multiple line breaks
41
  markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content)
42
 
43
  return markdown_content
44
 
45
+ except requests.exceptions.RequestException as e:
46
  return f"Error fetching the webpage: {str(e)}"
47
  except Exception as e:
48
  return f"An unexpected error occurred: {str(e)}"
49
 
50
 
 
51
  # Initialize the FinalAnswerTool
52
  final_answer = FinalAnswerTool()
53
 
 
59
  custom_role_conversions=None,
60
  )
61
 
 
 
 
 
62
  # Create the agent
63
  agent = CodeAgent(
64
  model=model,