Spaces:
Sleeping
Sleeping
andreagemelli
commited on
Commit
·
d18f44e
1
Parent(s):
c95fdd7
first try cooking agent using a recipe scraper
Browse files- app.py +18 -12
- requirements.txt +2 -0
app.py
CHANGED
|
@@ -1,19 +1,29 @@
|
|
| 1 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
import yaml
|
| 3 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
|
|
| 4 |
|
| 5 |
from Gradio_UI import GradioUI
|
| 6 |
|
| 7 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 8 |
@tool
|
| 9 |
-
def
|
| 10 |
-
|
| 11 |
-
"""A tool that does nothing yet
|
| 12 |
Args:
|
| 13 |
-
|
| 14 |
-
arg2: the second argument
|
| 15 |
"""
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
final_answer = FinalAnswerTool()
|
| 19 |
|
|
@@ -23,20 +33,16 @@ final_answer = FinalAnswerTool()
|
|
| 23 |
model = HfApiModel(
|
| 24 |
max_tokens=2096,
|
| 25 |
temperature=0.5,
|
| 26 |
-
model_id='
|
| 27 |
custom_role_conversions=None,
|
| 28 |
)
|
| 29 |
|
| 30 |
-
|
| 31 |
-
# Import tool from Hub
|
| 32 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 33 |
-
|
| 34 |
with open("prompts.yaml", 'r') as stream:
|
| 35 |
prompt_templates = yaml.safe_load(stream)
|
| 36 |
|
| 37 |
agent = CodeAgent(
|
| 38 |
model=model,
|
| 39 |
-
tools=[final_answer,
|
| 40 |
max_steps=6,
|
| 41 |
verbosity_level=1,
|
| 42 |
grammar=None,
|
|
|
|
| 1 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
import yaml
|
| 3 |
from tools.final_answer import FinalAnswerTool
|
| 4 |
+
from recipe_scrapers import scrape_html
|
| 5 |
+
from urllib.request import urlopen
|
| 6 |
|
| 7 |
from Gradio_UI import GradioUI
|
| 8 |
|
| 9 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 10 |
@tool
|
| 11 |
+
def grandma_secret_sauce(url: str) -> str:
|
| 12 |
+
"""This tool look at the url provided and returns the recipe from the page.
|
|
|
|
| 13 |
Args:
|
| 14 |
+
url (str): The url of the page to scrape.
|
|
|
|
| 15 |
"""
|
| 16 |
+
html = urlopen(url).read().decode("utf-8")
|
| 17 |
+
scraper = scrape_html(html, org_url=url)
|
| 18 |
+
|
| 19 |
+
recipe = f"""Title: {scraper.title()}
|
| 20 |
+
Total Time: {scraper.total_time()}
|
| 21 |
+
Yields: {scraper.yields()}
|
| 22 |
+
Ingredients: {scraper.ingredients()}
|
| 23 |
+
Instructions: {scraper.instructions()}
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
return recipe
|
| 27 |
|
| 28 |
final_answer = FinalAnswerTool()
|
| 29 |
|
|
|
|
| 33 |
model = HfApiModel(
|
| 34 |
max_tokens=2096,
|
| 35 |
temperature=0.5,
|
| 36 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 37 |
custom_role_conversions=None,
|
| 38 |
)
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
with open("prompts.yaml", 'r') as stream:
|
| 41 |
prompt_templates = yaml.safe_load(stream)
|
| 42 |
|
| 43 |
agent = CodeAgent(
|
| 44 |
model=model,
|
| 45 |
+
tools=[final_answer, DuckDuckGoSearchTool()], ## add your tools here (don't remove final answer)
|
| 46 |
max_steps=6,
|
| 47 |
verbosity_level=1,
|
| 48 |
grammar=None,
|
requirements.txt
CHANGED
|
@@ -3,3 +3,5 @@ smolagents
|
|
| 3 |
requests
|
| 4 |
duckduckgo_search
|
| 5 |
pandas
|
|
|
|
|
|
|
|
|
| 3 |
requests
|
| 4 |
duckduckgo_search
|
| 5 |
pandas
|
| 6 |
+
recipe-scrapers
|
| 7 |
+
|