Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,36 +3,37 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
-
from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel, WikipediaSearchTool,
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
| 9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 10 |
|
| 11 |
|
| 12 |
# --- Basic Agent Definition ---
|
| 13 |
-
|
| 14 |
class BasicAgent:
|
| 15 |
def __init__(self):
|
| 16 |
print("BasicAgent initialized.")
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
model =
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Tools
|
| 22 |
duckduckgo = DuckDuckGoSearchTool()
|
| 23 |
wikipedia = WikipediaSearchTool()
|
| 24 |
|
| 25 |
-
#
|
| 26 |
self.agent = CodeAgent(
|
| 27 |
-
model=model,
|
| 28 |
tools=[duckduckgo, wikipedia]
|
| 29 |
)
|
| 30 |
|
| 31 |
def __call__(self, question: str) -> str:
|
| 32 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 33 |
-
|
| 34 |
-
print(f"Agent returning
|
| 35 |
-
return
|
| 36 |
|
| 37 |
|
| 38 |
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel, WikipediaSearchTool, InferenceClientModel
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
| 9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 10 |
|
| 11 |
|
| 12 |
# --- Basic Agent Definition ---
|
|
|
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
print("BasicAgent initialized.")
|
| 16 |
|
| 17 |
+
# Load the HF-supported model using InferenceClientModel
|
| 18 |
+
self.model = InferenceClientModel(
|
| 19 |
+
model_id="meta-llama/Meta-Llama-3-8B-Instruct" #meta-llama/Llama-3.1-8B-Instruct
|
| 20 |
+
)
|
| 21 |
|
| 22 |
# Tools
|
| 23 |
duckduckgo = DuckDuckGoSearchTool()
|
| 24 |
wikipedia = WikipediaSearchTool()
|
| 25 |
|
| 26 |
+
# Compose the agent
|
| 27 |
self.agent = CodeAgent(
|
| 28 |
+
model=self.model,
|
| 29 |
tools=[duckduckgo, wikipedia]
|
| 30 |
)
|
| 31 |
|
| 32 |
def __call__(self, question: str) -> str:
|
| 33 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 34 |
+
answer = self.agent.run(question)
|
| 35 |
+
print(f"Agent returning answer: {answer[:80]}...")
|
| 36 |
+
return answer
|
| 37 |
|
| 38 |
|
| 39 |
|