Amalia
commited on
Commit
·
357e9c8
1
Parent(s):
81917a3
initialize codeagent and add some tools
Browse files
app.py
CHANGED
|
@@ -3,21 +3,58 @@ 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 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from smolagents import CodeAgent, tool, InferenceClientModel
|
| 7 |
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
| 10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 11 |
|
| 12 |
+
@tool
|
| 13 |
+
def multiply(a: int, b: int) -> int:
|
| 14 |
+
"""Multiply two numbers.
|
| 15 |
+
Args:
|
| 16 |
+
a: first int
|
| 17 |
+
b: second int
|
| 18 |
+
"""
|
| 19 |
+
return a * b
|
| 20 |
+
|
| 21 |
+
@tool
|
| 22 |
+
def add(a: int, b: int) -> int:
|
| 23 |
+
"""Add two numbers.
|
| 24 |
+
Args:
|
| 25 |
+
a: first int
|
| 26 |
+
b: second int
|
| 27 |
+
"""
|
| 28 |
+
return a + b
|
| 29 |
+
|
| 30 |
+
@tool
|
| 31 |
+
def subtract(a: int, b: int) -> int:
|
| 32 |
+
"""Subtract two numbers.
|
| 33 |
+
Args:
|
| 34 |
+
a: first int
|
| 35 |
+
b: second int
|
| 36 |
+
"""
|
| 37 |
+
return a - b
|
| 38 |
+
|
| 39 |
+
|
| 40 |
# --- Basic Agent Definition ---
|
| 41 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 42 |
class BasicAgent:
|
| 43 |
def __init__(self):
|
| 44 |
+
model_id = "Qwen/Qwen3-32B"
|
| 45 |
+
self.agent = CodeAgent(
|
| 46 |
+
model=InferenceClientModel(model_id=model_id, token=os.getenv("HF_TOKEN")),
|
| 47 |
+
tools=[multiply, add, subtract],
|
| 48 |
+
verbose=True,
|
| 49 |
+
max_steps=10,
|
| 50 |
+
)
|
| 51 |
print("BasicAgent initialized.")
|
| 52 |
def __call__(self, question: str) -> str:
|
| 53 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 54 |
+
# fixed_answer = "This is a default answer."
|
| 55 |
+
answer = self.agent.run(question)
|
| 56 |
+
print(f"Agent returning fixed answer: {answer}")
|
| 57 |
+
return answer
|
| 58 |
|
| 59 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 60 |
"""
|