MasterOfHugs commited on
Commit
8140829
·
verified ·
1 Parent(s): f184ab8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -23
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  from smolagents import Tool, CodeAgent
3
  import requests
 
4
 
5
  # ---------------------------
6
  # TOOLS
@@ -8,45 +9,38 @@ import requests
8
 
9
  @Tool
10
  def web_search(query: str, max_results: int = 5) -> str:
11
- """
12
- Perform a web search.
13
-
14
- Args:
15
- query (str): The search query.
16
- max_results (int): Maximum number of results to return.
17
-
18
- Returns:
19
- str: A string with the search results.
20
- """
21
- # Dummy search implementation (replace with real API call if needed)
22
  return f"Search results for '{query}' (top {max_results} results)."
23
 
24
  @Tool
25
  def visit_webpage(url: str) -> str:
26
- """
27
- Visit a webpage and return its HTML content.
28
-
29
- Args:
30
- url (str): The webpage URL.
31
-
32
- Returns:
33
- str: The HTML text of the page.
34
- """
35
  try:
36
  response = requests.get(url, timeout=5)
37
- return response.text[:2000] # limit output size
38
  except Exception as e:
39
  return f"Error visiting {url}: {e}"
40
 
 
 
 
 
 
 
 
 
 
 
41
  # ---------------------------
42
  # AGENT SETUP
43
  # ---------------------------
44
 
45
  agent = CodeAgent(
46
- model="google/flan-t5-small", # modèle gratuit
47
  tools=[web_search, visit_webpage],
48
  max_steps=6,
49
- prompt_config_path="config.yaml", # le yaml corrigé
 
50
  )
51
 
52
  # ---------------------------
 
1
  import gradio as gr
2
  from smolagents import Tool, CodeAgent
3
  import requests
4
+ import yaml
5
 
6
  # ---------------------------
7
  # TOOLS
 
9
 
10
  @Tool
11
  def web_search(query: str, max_results: int = 5) -> str:
12
+ """Perform a web search (dummy implementation)."""
 
 
 
 
 
 
 
 
 
 
13
  return f"Search results for '{query}' (top {max_results} results)."
14
 
15
  @Tool
16
  def visit_webpage(url: str) -> str:
17
+ """Visit a webpage and return its HTML content."""
 
 
 
 
 
 
 
 
18
  try:
19
  response = requests.get(url, timeout=5)
20
+ return response.text[:2000]
21
  except Exception as e:
22
  return f"Error visiting {url}: {e}"
23
 
24
+ # ---------------------------
25
+ # LOAD CONFIG.YAML
26
+ # ---------------------------
27
+
28
+ with open("config.yaml", "r") as f:
29
+ config = yaml.safe_load(f)
30
+
31
+ system_prompt = config.get("system_prompt", "")
32
+ prompt_templates = config.get("prompt_templates", {})
33
+
34
  # ---------------------------
35
  # AGENT SETUP
36
  # ---------------------------
37
 
38
  agent = CodeAgent(
39
+ model="google/flan-t5-small",
40
  tools=[web_search, visit_webpage],
41
  max_steps=6,
42
+ system_prompt=system_prompt,
43
+ prompt_templates=prompt_templates,
44
  )
45
 
46
  # ---------------------------