CindyDelage commited on
Commit
186ee7b
·
verified ·
1 Parent(s): 81917a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -6
app.py CHANGED
@@ -3,6 +3,8 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
 
 
6
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
@@ -15,9 +17,22 @@ class BasicAgent:
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
  """
@@ -146,11 +161,9 @@ with gr.Blocks() as demo:
146
  gr.Markdown(
147
  """
148
  **Instructions:**
149
-
150
  1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
151
  2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
152
  3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
153
-
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).
@@ -192,5 +205,5 @@ if __name__ == "__main__":
192
 
193
  print("-"*(60 + len(" App Starting ")) + "\n")
194
 
195
- print("Launching Gradio Interface for Basic Agent Evaluation...")
196
  demo.launch(debug=True, share=False)
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from tools import Web_research, image_interpreter
7
+ from smolagents import GradioUI, CodeAgent, HfApiModel, PythonInterpreterTool
8
 
9
  # (Keep Constants as is)
10
  # --- Constants ---
 
17
  print("BasicAgent initialized.")
18
  def __call__(self, question: str) -> str:
19
  print(f"Agent received question (first 50 chars): {question[:50]}...")
20
+ web_search = Web_research()
21
+ image_tool = image_interpreter()
22
+ python_code_tool = PythonInterpreterTool()
23
+ alfred=CodeAgent(
24
+ tools=[web_search, image_tool,python_code_tool],
25
+ model=HfApiModel(token=os.environ.get("HF_TOKEN")),
26
+ add_base_tools=True,
27
+ max_print_outputs_length = 100
28
+ )
29
+ HF_TOKEN=os.environ.get("HF_TOKEN")
30
+ headers = {
31
+ "Authorization": f"Bearer {HF_TOKEN}"
32
+ }
33
+ print("Agent initialised") # You have tools, always try to use them to answer.
34
+ answer = alfred.run(f"You are a general AI assistant. I will ask you a question. You have tools to answer them, always check it before anything else. Report your thoughts and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don’t use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don’t use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string. Here are the questions : {question}")
35
+ return answer
36
 
37
  def run_and_submit_all( profile: gr.OAuthProfile | None):
38
  """
 
161
  gr.Markdown(
162
  """
163
  **Instructions:**
 
164
  1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
165
  2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
166
  3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
 
167
  ---
168
  **Disclaimers:**
169
  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).
 
205
 
206
  print("-"*(60 + len(" App Starting ")) + "\n")
207
 
208
+ print("Launching Gradio Interface for Agent Evaluation...")
209
  demo.launch(debug=True, share=False)