Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
-
from smolagents import DuckDuckGoSearchTool, HfApiModel, PythonInterpreterTool, VisitWebpageTool, CodeAgent
|
| 7 |
import hashlib
|
| 8 |
import json
|
| 9 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, TransformersEngine
|
|
@@ -21,6 +21,7 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 21 |
cache = {}
|
| 22 |
|
| 23 |
web_search = DuckDuckGoSearchTool()
|
|
|
|
| 24 |
python_interpreter = PythonInterpreterTool(authorized_imports = [
|
| 25 |
# standard library
|
| 26 |
'os', # For file path manipulation, checking existence, deletion
|
|
@@ -56,6 +57,13 @@ yt_transcript_fetcher = YoutubeTranscriptFetcher()
|
|
| 56 |
math_model_querer = MathModelQuerer()
|
| 57 |
code_model_querer = CodeModelQuerer()
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
def load_cached_answer(question_id: str) -> str:
|
| 61 |
if question_id in cache.keys():
|
|
@@ -106,6 +114,10 @@ model = HfApiModel()
|
|
| 106 |
# max_new_tokens=256)
|
| 107 |
|
| 108 |
# model = HfApiModel()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
|
| 111 |
class BasicAgent:
|
|
@@ -113,7 +125,7 @@ class BasicAgent:
|
|
| 113 |
print("BasicAgent initialized.")
|
| 114 |
self.agent = CodeAgent(
|
| 115 |
model=model,
|
| 116 |
-
tools=[web_search, python_interpreter, visit_webpage_tool, wiki_tool, code_model_querer, math_model_querer],
|
| 117 |
max_steps=5,
|
| 118 |
verbosity_level=1,
|
| 119 |
grammar=None,
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from smolagents import DuckDuckGoSearchTool,GoogleSearchTool, HfApiModel, PythonInterpreterTool, VisitWebpageTool, CodeAgent
|
| 7 |
import hashlib
|
| 8 |
import json
|
| 9 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, TransformersEngine
|
|
|
|
| 21 |
cache = {}
|
| 22 |
|
| 23 |
web_search = DuckDuckGoSearchTool()
|
| 24 |
+
google_search = GoogleSearchTool(provider="serper")
|
| 25 |
python_interpreter = PythonInterpreterTool(authorized_imports = [
|
| 26 |
# standard library
|
| 27 |
'os', # For file path manipulation, checking existence, deletion
|
|
|
|
| 57 |
math_model_querer = MathModelQuerer()
|
| 58 |
code_model_querer = CodeModelQuerer()
|
| 59 |
|
| 60 |
+
# batch of tools fromm Langchain. Credits DataDiva88
|
| 61 |
+
lc_ddg_search = Tool.from_langchain(load_tools(["ddg-search"])[0])
|
| 62 |
+
lc_wikipedia = Tool.from_langchain(load_tools(["wikipedia"])[0])
|
| 63 |
+
lc_arxiv = Tool.from_langchain(load_tools(["arxiv"])[0])
|
| 64 |
+
lc_pubmed = Tool.from_langchain(load_tools(["pubmed"])[0])
|
| 65 |
+
lc_stackechange = Tool.from_langchain(load_tools(["stackexchange"])[0])
|
| 66 |
+
|
| 67 |
|
| 68 |
def load_cached_answer(question_id: str) -> str:
|
| 69 |
if question_id in cache.keys():
|
|
|
|
| 114 |
# max_new_tokens=256)
|
| 115 |
|
| 116 |
# model = HfApiModel()
|
| 117 |
+
lc_ddg_search = Tool.from_langchain(load_tools(["ddg-search"])[0])
|
| 118 |
+
lc_wikipedia = Tool.from_langchain(load_tools(["wikipedia"])[0])
|
| 119 |
+
lc_arxiv = Tool.from_langchain(load_tools(["arxiv"])[0])
|
| 120 |
+
lc_pubmed = Tool.from_langchain(load_tools(["pubmed"])[0])
|
| 121 |
|
| 122 |
|
| 123 |
class BasicAgent:
|
|
|
|
| 125 |
print("BasicAgent initialized.")
|
| 126 |
self.agent = CodeAgent(
|
| 127 |
model=model,
|
| 128 |
+
tools=[google_search,web_search, python_interpreter, visit_webpage_tool, wiki_tool, code_model_querer, math_model_querer,lc_wikipedia,lc_arxiv,lc_pubmed,lc_stackechange],
|
| 129 |
max_steps=5,
|
| 130 |
verbosity_level=1,
|
| 131 |
grammar=None,
|