ArslanFOX commited on
Commit
ca755db
·
verified ·
1 Parent(s): d94cd24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -20
app.py CHANGED
@@ -5,7 +5,6 @@ import yaml
5
  from tools.final_answer import FinalAnswerTool
6
  from Gradio_UI import GradioUI
7
 
8
- # Example tool that provides waste disposal recommendations
9
  @tool
10
  def find_recycling_center(waste_type: str, location: str) -> str:
11
  """
@@ -14,21 +13,15 @@ def find_recycling_center(waste_type: str, location: str) -> str:
14
  waste_type: The type of waste to recycle (e.g., 'plastic bottles').
15
  location: The location where the user is based (e.g., 'Moscow, Russia').
16
  """
17
- # Here you would typically call an external API or database to get the information
18
- # For this example, we'll return a static response
19
  recycling_info = {
20
  "plastic bottles": "You can recycle plastic bottles at your local supermarket or recycling center.",
21
  "paper": "Paper can be recycled at most municipal recycling centers.",
22
  "electronics": "Electronics should be taken to specialized e-waste recycling facilities."
23
  }
24
-
25
- # Check if the waste type is in the dictionary
26
  if waste_type.lower() in recycling_info:
27
  return f"In {location}, {recycling_info[waste_type.lower()]} Please check their website for opening hours."
28
  else:
29
  return f"Sorry, I don't have information about recycling {waste_type} in {location}. Please contact your local waste management service for assistance."
30
-
31
- # Tool to get the current local time in a specified timezone
32
  @tool
33
  def get_current_time_in_timezone(timezone: str) -> str:
34
  """
@@ -42,33 +35,23 @@ def get_current_time_in_timezone(timezone: str) -> str:
42
  return f"The current local time in {timezone} is: {local_time}"
43
  except Exception as e:
44
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
45
-
46
- # Load the final answer tool
47
  final_answer = FinalAnswerTool()
48
-
49
- # Define AI_assistant or import it if it's from another module
50
  AI_assistant = {
51
  'role1': 'conversion1',
52
  'role2': 'conversion2'
53
- # Add other role conversions as needed
54
  }
55
-
56
- # Initialize the model with the defined AI_assistant
57
  model = HfApiModel(
58
  max_tokens=2096,
59
  temperature=0.5,
60
  model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
61
  custom_role_conversions=AI_assistant,
62
  )
63
-
64
- # Load prompt templates from a YAML file
65
  with open("prompts.yaml", 'r') as stream:
66
  prompt_templates = yaml.safe_load(stream)
67
 
68
- # Create the agent with the specified model and tools
69
  agent = CodeAgent(
70
  model=model,
71
- tools=[final_answer, find_recycling_center], # Add the recycling tool here
72
  max_steps=6,
73
  verbosity_level=1,
74
  grammar=None,
@@ -77,9 +60,8 @@ agent = CodeAgent(
77
  description=None,
78
  prompt_templates=prompt_templates
79
  )
 
80
 
81
- # Launch the Gradio UI with the agent
82
- GradioUI(agent).launch(share=False, ssr=False)
83
 
84
 
85
 
 
5
  from tools.final_answer import FinalAnswerTool
6
  from Gradio_UI import GradioUI
7
 
 
8
  @tool
9
  def find_recycling_center(waste_type: str, location: str) -> str:
10
  """
 
13
  waste_type: The type of waste to recycle (e.g., 'plastic bottles').
14
  location: The location where the user is based (e.g., 'Moscow, Russia').
15
  """
 
 
16
  recycling_info = {
17
  "plastic bottles": "You can recycle plastic bottles at your local supermarket or recycling center.",
18
  "paper": "Paper can be recycled at most municipal recycling centers.",
19
  "electronics": "Electronics should be taken to specialized e-waste recycling facilities."
20
  }
 
 
21
  if waste_type.lower() in recycling_info:
22
  return f"In {location}, {recycling_info[waste_type.lower()]} Please check their website for opening hours."
23
  else:
24
  return f"Sorry, I don't have information about recycling {waste_type} in {location}. Please contact your local waste management service for assistance."
 
 
25
  @tool
26
  def get_current_time_in_timezone(timezone: str) -> str:
27
  """
 
35
  return f"The current local time in {timezone} is: {local_time}"
36
  except Exception as e:
37
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
 
 
38
  final_answer = FinalAnswerTool()
 
 
39
  AI_assistant = {
40
  'role1': 'conversion1',
41
  'role2': 'conversion2'
 
42
  }
 
 
43
  model = HfApiModel(
44
  max_tokens=2096,
45
  temperature=0.5,
46
  model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
47
  custom_role_conversions=AI_assistant,
48
  )
 
 
49
  with open("prompts.yaml", 'r') as stream:
50
  prompt_templates = yaml.safe_load(stream)
51
 
 
52
  agent = CodeAgent(
53
  model=model,
54
+ tools=[final_answer, find_recycling_center],
55
  max_steps=6,
56
  verbosity_level=1,
57
  grammar=None,
 
60
  description=None,
61
  prompt_templates=prompt_templates
62
  )
63
+ GradioUI(agent).launch(ssr=False)
64
 
 
 
65
 
66
 
67