Andrew-Gl commited on
Commit
d1fb17c
·
1 Parent(s): 806cb2d

08.09.2025

Browse files
Files changed (3) hide show
  1. a_tools.py +14 -0
  2. app.py +16 -11
  3. requirements.txt +3 -0
a_tools.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from langchain.agents import load_tools
3
+ from smolagents import Tool
4
+
5
+ os.environ["SERPAPI_API_KEY"] = "06da1dedae2ed008f4d95e857c123fb1a3a6b20abd3a88de357d37a586fb70f3"
6
+
7
+ image_generation_tool = Tool.from_space(
8
+ "black-forest-labs/FLUX.1-schnell",
9
+ name="image_generator",
10
+ description="Generate an image from a prompt"
11
+ )
12
+
13
+ search_tool = load_tools(["serpapi"])[0]
14
+
app.py CHANGED
@@ -3,21 +3,25 @@ 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("AG Agent 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,11 +44,12 @@ 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
47
- # In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
48
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
49
  print(agent_code)
50
 
@@ -154,7 +159,7 @@ with gr.Blocks() as demo:
154
  ---
155
  **Disclaimers:**
156
  Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
157
- This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a seperate action or even to answer the questions in async.
158
  """
159
  )
160
 
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from smolagents import CodeAgent, InferenceClientModel
7
+ from a_tools import search_tool, image_generation_tool
8
 
9
  # (Keep Constants as is)
10
  # --- Constants ---
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
 
13
  # --- Basic Agent Definition ---
14
+ # ----- THIS IS WhERE YOU CAN BUILD WHAT YOU WANT ------
15
+ class AGAgent(CodeAgent):
16
+ def __init__(self, **kwargs):
17
+ a_model = InferenceClientModel(
18
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
19
+ max_tokens=1024,
20
+ temperature=0.7
21
+ )
22
+ super().__init__([search_tool,image_generation_tool], model = a_model, name="Andrey Agent", **kwargs)
23
  print("AG Agent initialized.")
24
+
 
 
 
 
25
 
26
  def run_and_submit_all( profile: gr.OAuthProfile | None):
27
  """
 
44
 
45
  # 1. Instantiate Agent ( modify this part to create your agent)
46
  try:
47
+ agent = AGAgent(
48
+ tools=[search_tool],)
49
  except Exception as e:
50
  print(f"Error instantiating agent: {e}")
51
  return f"Error initializing agent: {e}", None
52
+ # In the case of an app running as a hugging Face space, this link points toward your codebase ( useful for others so please keep it public)
53
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
54
  print(agent_code)
55
 
 
159
  ---
160
  **Disclaimers:**
161
  Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
162
+ This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a separate action or even to answer the questions in async.
163
  """
164
  )
165
 
requirements.txt CHANGED
@@ -1,2 +1,5 @@
 
 
 
1
  gradio
2
  requests
 
1
+ pandas
2
+ langchain
3
+ smolagents
4
  gradio
5
  requests