andreagemelli commited on
Commit
be13e49
·
1 Parent(s): 9ef7cb6

prettify output

Browse files
Files changed (2) hide show
  1. Gradio_UI.py +5 -1
  2. app.py +23 -13
Gradio_UI.py CHANGED
@@ -24,6 +24,9 @@ from smolagents.agents import ActionStep, MultiStepAgent
24
  from smolagents.memory import MemoryStep
25
  from smolagents.utils import _is_package_available
26
 
 
 
 
27
 
28
  def pull_messages_from_step(
29
  step_log: MemoryStep,
@@ -262,6 +265,7 @@ class GradioUI:
262
  import gradio as gr
263
 
264
  with gr.Blocks(fill_height=True) as demo:
 
265
  stored_messages = gr.State([])
266
  file_uploads_log = gr.State([])
267
  chatbot = gr.Chatbot(
@@ -283,7 +287,7 @@ class GradioUI:
283
  [upload_file, file_uploads_log],
284
  [upload_status, file_uploads_log],
285
  )
286
- text_input = gr.Textbox(lines=1, label="Chat Message")
287
  text_input.submit(
288
  self.log_user_message,
289
  [text_input, file_uploads_log],
 
24
  from smolagents.memory import MemoryStep
25
  from smolagents.utils import _is_package_available
26
 
27
+ greeting_message = "👩🏼‍🍳 I know all the recipes out there! Let's cook together!"
28
+ example_user_message = "Let's cook a carbonara! 🍝"
29
+
30
 
31
  def pull_messages_from_step(
32
  step_log: MemoryStep,
 
265
  import gradio as gr
266
 
267
  with gr.Blocks(fill_height=True) as demo:
268
+ gr.Markdown(greeting_message)
269
  stored_messages = gr.State([])
270
  file_uploads_log = gr.State([])
271
  chatbot = gr.Chatbot(
 
287
  [upload_file, file_uploads_log],
288
  [upload_status, file_uploads_log],
289
  )
290
+ text_input = gr.Textbox(lines=1, label="Chat Message", placeholder=example_user_message)
291
  text_input.submit(
292
  self.log_user_message,
293
  [text_input, file_uploads_log],
app.py CHANGED
@@ -1,4 +1,4 @@
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
@@ -8,20 +8,30 @@ from Gradio_UI import GradioUI
8
 
9
  @tool
10
  def grandma_secret_sauce(url: str) -> str:
11
- """This tool look at the url provided and returns the recipe from the page.
12
  Args:
13
- url: The url of the page to scrape.
14
- """
15
- html = urlopen(url).read().decode("utf-8")
16
- scraper = scrape_html(html, org_url=url)
17
-
18
- recipe = f"""Title: {scraper.title()}
19
- Total Time: {scraper.total_time()}
20
- Yields: {scraper.yields()}
21
- Ingredients: {scraper.ingredients()}
22
- Instructions: {scraper.instructions()}
23
  """
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  return recipe
26
 
27
  final_answer = FinalAnswerTool()
@@ -42,7 +52,7 @@ with open("prompts.yaml", 'r') as stream:
42
  agent = CodeAgent(
43
  model=model,
44
  tools=[final_answer, DuckDuckGoSearchTool(), grandma_secret_sauce],
45
- max_steps=6,
46
  verbosity_level=1,
47
  grammar=None,
48
  planning_interval=None,
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, tool
2
  import yaml
3
  from tools.final_answer import FinalAnswerTool
4
  from recipe_scrapers import scrape_html
 
8
 
9
  @tool
10
  def grandma_secret_sauce(url: str) -> str:
11
+ """This tool look at the urls provided and returns the recipe from a wroking, existing page.
12
  Args:
13
+ url: list of url pages to scrape the recipe from.
 
 
 
 
 
 
 
 
 
14
  """
15
 
16
+ scraper = None
17
+ try:
18
+ html = urlopen(url).read().decode("utf-8")
19
+ scraper = scrape_html(html, org_url=url)
20
+ except:
21
+ return f"Recipe not found for provided url: {url}."
22
+
23
+ ingredients = [f" - {ing}\n" for ing in scraper.ingredients()]
24
+
25
+ recipe = f"""
26
+ 👩🏼‍🍳 Et voilà! The {scraper.title()}!
27
+ Preparation requires {scraper.total_time()} minutes, and it is for {scraper.yields()} people.
28
+
29
+ 🧂 Ingredients:\n
30
+ {''.join(ingredients)}
31
+ 🥘 Instructions:
32
+ {scraper.instructions()}
33
+ """
34
+
35
  return recipe
36
 
37
  final_answer = FinalAnswerTool()
 
52
  agent = CodeAgent(
53
  model=model,
54
  tools=[final_answer, DuckDuckGoSearchTool(), grandma_secret_sauce],
55
+ max_steps=10,
56
  verbosity_level=1,
57
  grammar=None,
58
  planning_interval=None,