Spaces:
Sleeping
Sleeping
Initial POC
Browse files
app.py
CHANGED
|
@@ -4,20 +4,39 @@ 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 |
-
|
| 19 |
-
print(f"Agent
|
| 20 |
-
return
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
@@ -35,7 +54,8 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 35 |
return "Please Login to Hugging Face with the button.", None
|
| 36 |
|
| 37 |
api_url = DEFAULT_API_URL
|
| 38 |
-
questions_url = f"{api_url}/questions"
|
|
|
|
| 39 |
submit_url = f"{api_url}/submit"
|
| 40 |
|
| 41 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
|
@@ -44,7 +64,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 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 (
|
| 48 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 49 |
print(agent_code)
|
| 50 |
|
|
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
+
from smolagents import CodeAgent, WebSearchTool, InferenceClientModel, DuckDuckGoSearchTool, Tool
|
| 8 |
+
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
| 11 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 12 |
|
| 13 |
+
prompt_templates = """
|
| 14 |
+
You are an expert assistant who can find out any fact. You are skilled in using search tools to find information, using reasoning to identify complex relationships and can generate code to find precise answers. You are being asked specific questions and the fate of the world rests in your ability to precisely answer them. Your primary objective is to track down the exact answer required by the question. The number of iterations needed to find the answer is not a concern so long as you are 100% confident in the answer you return.
|
| 15 |
+
|
| 16 |
+
After you identify and validate the exact answer to the question you will return only that with no further explanation. Debugging logs will be used if needed to identify how you arrived at that answer.
|
| 17 |
+
"""
|
| 18 |
# --- Basic Agent Definition ---
|
| 19 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 20 |
class BasicAgent:
|
| 21 |
def __init__(self):
|
| 22 |
+
websearchtool = WebSearchTool()
|
| 23 |
+
search_tool = DuckDuckGoSearchTool()
|
| 24 |
+
model = InferenceClientModel()
|
| 25 |
+
# TODO: add additional tools and or subagents (e.g. OpenAI image recognition)
|
| 26 |
+
master_agent = CodeAgent(
|
| 27 |
+
tools=[websearchtool, search_tool],
|
| 28 |
+
model=model,
|
| 29 |
+
add_base_tools=True,
|
| 30 |
+
planning_interval=3,
|
| 31 |
+
max_steps=10,
|
| 32 |
+
prompt_templates=prompt_templates,
|
| 33 |
+
)
|
| 34 |
print("BasicAgent initialized.")
|
| 35 |
def __call__(self, question: str) -> str:
|
| 36 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 37 |
+
agent_answer = master_agent.run(question)
|
| 38 |
+
print(f"Agent answer: {agent_answer}")
|
| 39 |
+
return agent_answer
|
| 40 |
|
| 41 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 42 |
"""
|
|
|
|
| 54 |
return "Please Login to Hugging Face with the button.", None
|
| 55 |
|
| 56 |
api_url = DEFAULT_API_URL
|
| 57 |
+
#questions_url = f"{api_url}/questions"
|
| 58 |
+
questions_url = f"{api_url}/random-question"
|
| 59 |
submit_url = f"{api_url}/submit"
|
| 60 |
|
| 61 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
|
|
|
| 64 |
except Exception as e:
|
| 65 |
print(f"Error instantiating agent: {e}")
|
| 66 |
return f"Error initializing agent: {e}", None
|
| 67 |
+
# 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)
|
| 68 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 69 |
print(agent_code)
|
| 70 |
|