lucasnseq commited on
Commit
3504f9d
·
verified ·
1 Parent(s): 81917a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -10
app.py CHANGED
@@ -1,23 +1,59 @@
1
  import os
2
  import gradio as gr
3
  import requests
4
- import inspect
5
  import pandas as pd
6
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
- # --- Basic Agent Definition ---
12
- # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
- class BasicAgent:
 
 
 
 
 
 
 
 
 
 
 
 
14
  def __init__(self):
15
- print("BasicAgent initialized.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  def __call__(self, question: str) -> str:
17
- print(f"Agent received question (first 50 chars): {question[:50]}...")
18
- fixed_answer = "This is a default answer."
19
- print(f"Agent returning fixed answer: {fixed_answer}")
20
- return fixed_answer
 
 
 
 
 
 
21
 
22
  def run_and_submit_all( profile: gr.OAuthProfile | None):
23
  """
@@ -40,7 +76,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
40
 
41
  # 1. Instantiate Agent ( modify this part to create your agent)
42
  try:
43
- agent = BasicAgent()
44
  except Exception as e:
45
  print(f"Error instantiating agent: {e}")
46
  return f"Error initializing agent: {e}", None
 
1
  import os
2
  import gradio as gr
3
  import requests
 
4
  import pandas as pd
5
 
6
  # (Keep Constants as is)
7
  # --- Constants ---
8
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
9
 
10
+ from smolagents import (
11
+ CodeAgent,
12
+ DuckDuckGoSearchTool,
13
+ VisitWebpageTool,
14
+ OpenAIServerModel,
15
+ ToolCallingAgent,
16
+ )
17
+
18
+ def get_model():
19
+ """Initialize and return the Hugging Face model."""
20
+
21
+ # Initialize model with specific configuration
22
+ return OpenAIServerModel("gpt-4.1-mini", max_tokens=8096, api_key=os.getenv("OPENAI_API_KEY"))
23
+
24
+ class MultiAgent:
25
  def __init__(self):
26
+
27
+
28
+ # Create the web agent
29
+ web_agent = ToolCallingAgent(
30
+ tools=[DuckDuckGoSearchTool(), VisitWebpageTool()],
31
+ model=get_model(),
32
+ max_steps=10,
33
+ name="web_agent",
34
+ description="Browses the web to find information, it can also visit webpages.",
35
+ )
36
+
37
+ # Create the code agent
38
+ self.agent = CodeAgent(
39
+ tools=[],
40
+ managed_agents=[web_agent],
41
+ model=get_model(),
42
+ max_steps=20,
43
+ additional_authorized_imports=["os", "shutil", "PyPDF2", "docx", "bs4", "requests", "numpy", "pandas"],
44
+ )
45
+
46
  def __call__(self, question: str) -> str:
47
+ print(f"MultiAgent received question (first 50 chars): {question[:50]}...")
48
+ try:
49
+ answer = self.agent.run(question)
50
+ print(f"MultiAgent returning answer: {answer}")
51
+ return str(answer)
52
+ except Exception as e:
53
+ print(f"MultiAgent error: {e}")
54
+ return f"MultiAgent error: {e}"
55
+
56
+ # To use this agent in your pipeline, replace BasicAgent with MultiAgent in run_and_submit_all.
57
 
58
  def run_and_submit_all( profile: gr.OAuthProfile | None):
59
  """
 
76
 
77
  # 1. Instantiate Agent ( modify this part to create your agent)
78
  try:
79
+ agent = MultiAgent()
80
  except Exception as e:
81
  print(f"Error instantiating agent: {e}")
82
  return f"Error initializing agent: {e}", None