Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,40 +7,38 @@ from duckduckgo_search import DDGS
|
|
| 7 |
from transformers import pipeline
|
| 8 |
|
| 9 |
# --- Tool Definitions ---
|
| 10 |
-
from tools.search_tool import
|
| 11 |
-
from tools.citation_tool import
|
| 12 |
-
from tools.summarizer_tool import
|
| 13 |
-
from tools.math_tool import
|
| 14 |
-
from tools.fallback_tool import
|
| 15 |
|
| 16 |
class BasicAgent:
|
| 17 |
def __init__(self):
|
| 18 |
-
|
| 19 |
-
self.cite = CiteTool()
|
| 20 |
-
self.summarizer = SummarizerTool()
|
| 21 |
-
self.math = PythonTool()
|
| 22 |
-
self.fallback = FallbackTool()
|
| 23 |
|
| 24 |
def __call__(self, question: str) -> str:
|
| 25 |
question_lower = question.lower()
|
| 26 |
|
| 27 |
try:
|
| 28 |
if any(keyword in question_lower for keyword in ["latest", "news", "who", "what", "where", "when"]):
|
| 29 |
-
return
|
| 30 |
elif any(keyword in question_lower for keyword in ["summarize", "summary", "explain"]):
|
| 31 |
-
return
|
| 32 |
elif any(char.isdigit() for char in question) and any(op in question for op in ["+", "-", "*", "/"]):
|
| 33 |
-
return
|
| 34 |
elif "|||" in question:
|
| 35 |
-
return
|
| 36 |
else:
|
| 37 |
-
return
|
| 38 |
except Exception as e:
|
| 39 |
return f"Error during processing: {str(e)}"
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
|
|
|
|
|
|
| 44 |
# --- Evaluation Logic ---
|
| 45 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 46 |
|
|
|
|
| 7 |
from transformers import pipeline
|
| 8 |
|
| 9 |
# --- Tool Definitions ---
|
| 10 |
+
from tools.search_tool import web_search
|
| 11 |
+
from tools.citation_tool import cite
|
| 12 |
+
from tools.summarizer_tool import summarize
|
| 13 |
+
from tools.math_tool import python
|
| 14 |
+
from tools.fallback_tool import fallback
|
| 15 |
|
| 16 |
class BasicAgent:
|
| 17 |
def __init__(self):
|
| 18 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
def __call__(self, question: str) -> str:
|
| 21 |
question_lower = question.lower()
|
| 22 |
|
| 23 |
try:
|
| 24 |
if any(keyword in question_lower for keyword in ["latest", "news", "who", "what", "where", "when"]):
|
| 25 |
+
return web_search(question)
|
| 26 |
elif any(keyword in question_lower for keyword in ["summarize", "summary", "explain"]):
|
| 27 |
+
return summarize(question)
|
| 28 |
elif any(char.isdigit() for char in question) and any(op in question for op in ["+", "-", "*", "/"]):
|
| 29 |
+
return python(question)
|
| 30 |
elif "|||" in question:
|
| 31 |
+
return cite(question)
|
| 32 |
else:
|
| 33 |
+
return fallback(question)
|
| 34 |
except Exception as e:
|
| 35 |
return f"Error during processing: {str(e)}"
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
+
|
| 41 |
+
|
| 42 |
# --- Evaluation Logic ---
|
| 43 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 44 |
|