app.py
CHANGED
|
@@ -5,7 +5,7 @@ from CustomAgent import CustomAgent
|
|
| 5 |
from utils import get_agents, run_and_submit_all
|
| 6 |
|
| 7 |
# Get all available agents
|
| 8 |
-
AGENTS = get_agents()
|
| 9 |
|
| 10 |
# Demo app
|
| 11 |
with gr.Blocks() as demo:
|
|
|
|
| 5 |
from utils import get_agents, run_and_submit_all
|
| 6 |
|
| 7 |
# Get all available agents
|
| 8 |
+
AGENTS = get_agents(globals(), BasicAgent)
|
| 9 |
|
| 10 |
# Demo app
|
| 11 |
with gr.Blocks() as demo:
|
utils.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import inspect
|
| 2 |
import os
|
| 3 |
-
import sys
|
| 4 |
from typing import Any
|
| 5 |
|
| 6 |
import gradio as gr
|
|
@@ -13,14 +12,14 @@ from BasicAgent import BasicAgent
|
|
| 13 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 14 |
|
| 15 |
|
| 16 |
-
def get_agents() -> dict[str, type]:
|
| 17 |
"""
|
| 18 |
Get all agents that inherit from BasicAgent, including imported ones.
|
| 19 |
"""
|
| 20 |
return {
|
| 21 |
name: obj
|
| 22 |
-
for name, obj in
|
| 23 |
-
if inspect.isclass(obj) and issubclass(obj,
|
| 24 |
}
|
| 25 |
|
| 26 |
|
|
|
|
| 1 |
import inspect
|
| 2 |
import os
|
|
|
|
| 3 |
from typing import Any
|
| 4 |
|
| 5 |
import gradio as gr
|
|
|
|
| 12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 13 |
|
| 14 |
|
| 15 |
+
def get_agents(namespace: dict[str, type], parent_cls: object) -> dict[str, type]:
|
| 16 |
"""
|
| 17 |
Get all agents that inherit from BasicAgent, including imported ones.
|
| 18 |
"""
|
| 19 |
return {
|
| 20 |
name: obj
|
| 21 |
+
for name, obj in namespace.items()
|
| 22 |
+
if inspect.isclass(obj) and issubclass(obj, parent_cls)
|
| 23 |
}
|
| 24 |
|
| 25 |
|