Spaces:
Runtime error
Runtime error
implement serpapi youtube and other tools properly
Browse files- app.py +5 -3
- tools/visit_webpage.py +1 -0
app.py
CHANGED
|
@@ -4,13 +4,15 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
|
|
| 7 |
import requests
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
import os
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
load_dotenv()
|
| 12 |
|
| 13 |
-
|
| 14 |
|
| 15 |
@tool
|
| 16 |
def youtube_search(query: str, max_results: int = 5) -> str:
|
|
@@ -27,7 +29,7 @@ def youtube_search(query: str, max_results: int = 5) -> str:
|
|
| 27 |
|
| 28 |
try:
|
| 29 |
# Replace with your actual SerpAPI key or set it as an environment variable
|
| 30 |
-
api_key =
|
| 31 |
url = "https://serpapi.com/search.json"
|
| 32 |
params = {
|
| 33 |
"engine": "youtube",
|
|
@@ -95,7 +97,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 95 |
|
| 96 |
agent = CodeAgent(
|
| 97 |
model=model,
|
| 98 |
-
tools=[final_answer, DuckDuckGoSearchTool,
|
| 99 |
max_steps=6,
|
| 100 |
verbosity_level=1,
|
| 101 |
grammar=None,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from tools.visit_webpage import VisitWebpageTool
|
| 8 |
+
from tools.web_search import DuckDuckGoSearchTool
|
| 9 |
import requests
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
import os
|
| 12 |
from dotenv import load_dotenv
|
| 13 |
load_dotenv()
|
| 14 |
|
| 15 |
+
SERPAPI_KEY = os.getenv("SERPAPI_KEY")
|
| 16 |
|
| 17 |
@tool
|
| 18 |
def youtube_search(query: str, max_results: int = 5) -> str:
|
|
|
|
| 29 |
|
| 30 |
try:
|
| 31 |
# Replace with your actual SerpAPI key or set it as an environment variable
|
| 32 |
+
api_key = SERPAPI_KEY # Add your SerpAPI key here
|
| 33 |
url = "https://serpapi.com/search.json"
|
| 34 |
params = {
|
| 35 |
"engine": "youtube",
|
|
|
|
| 97 |
|
| 98 |
agent = CodeAgent(
|
| 99 |
model=model,
|
| 100 |
+
tools=[final_answer, get_current_time_in_timezone, youtube_search, DuckDuckGoSearchTool(), VisitWebpageTool()], ## add your tools here (don't remove final answer)
|
| 101 |
max_steps=6,
|
| 102 |
verbosity_level=1,
|
| 103 |
grammar=None,
|
tools/visit_webpage.py
CHANGED
|
@@ -3,6 +3,7 @@ from smolagents.tools import Tool
|
|
| 3 |
import requests
|
| 4 |
import markdownify
|
| 5 |
import smolagents
|
|
|
|
| 6 |
|
| 7 |
class VisitWebpageTool(Tool):
|
| 8 |
name = "visit_webpage"
|
|
|
|
| 3 |
import requests
|
| 4 |
import markdownify
|
| 5 |
import smolagents
|
| 6 |
+
import re
|
| 7 |
|
| 8 |
class VisitWebpageTool(Tool):
|
| 9 |
name = "visit_webpage"
|