kndambuki commited on
Commit
73ed319
·
verified ·
1 Parent(s): 8739567

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -46
app.py CHANGED
@@ -11,56 +11,66 @@ from Gradio_UI import GradioUI
11
 
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
  @tool
14
- def destiny_still_arrives(name:str, age_or_dob:str)-> str: #it's import to specify the return type
15
- #Keep this format for the description / args / args description but feel free to modify the tool
16
- # """A tool that takes a name, age or date of birth as input. It outputs the meaning of the name, an image of that person's birthstone and a horoscope reading of the day.
17
- # Args:
18
- # name: A string representing a person's age
19
- # age_or_dob: A string representing a person's age or date of birth
20
- # """
21
- # def get_birthstone(name: str, age_or_dob: str):
22
- # birthstones = {
23
- # "January": "Garnet",
24
- # "February": "Amethyst",
25
- # "March": "Aquamarine",
26
- # "April": "Diamond",
27
- # "May": "Emerald",
28
- # "June": "Pearl",
29
- # "July": "Ruby",
30
- # "August": "Peridot",
31
- # "September": "Sapphire",
32
- # "October": "Opal",
33
- # "November": "Topaz",
34
- # "December": "Turquoise"
35
- # }
 
 
 
 
 
 
 
 
 
 
36
 
37
- # month = datetime.strptime(age_or_dob, "%Y-%m-%d").strftime("%B")
38
- # birthstone = birthstones.get(month, "Unknown")
39
 
40
- # image_urls = {
41
- # "Garnet": "https://upload.wikimedia.org/wikipedia/commons/1/12/Garnet_rough.jpg",
42
- # "Amethyst": "https://upload.wikimedia.org/wikipedia/commons/8/8b/Amethyst.jpg",
43
- # "Aquamarine": "https://upload.wikimedia.org/wikipedia/commons/d/d5/Aquamarine_Brazil.jpg",
44
- # "Diamond": "https://upload.wikimedia.org/wikipedia/commons/a/a7/Loose_diamond.png",
45
- # "Emerald": "https://upload.wikimedia.org/wikipedia/commons/4/4f/Emerald.jpg",
46
- # "Pearl": "https://upload.wikimedia.org/wikipedia/commons/1/17/Pearl_macro.jpg",
47
- # "Ruby": "https://upload.wikimedia.org/wikipedia/commons/0/0d/Ruby.jpg",
48
- # "Peridot": "https://upload.wikimedia.org/wikipedia/commons/8/8a/Peridot.jpg",
49
- # "Sapphire": "https://upload.wikimedia.org/wikipedia/commons/3/35/Sapphire.jpg",
50
- # "Opal": "https://upload.wikimedia.org/wikipedia/commons/2/2f/Opal_macro.jpg",
51
- # "Topaz": "https://upload.wikimedia.org/wikipedia/commons/5/56/Topaz.jpg",
52
- # "Turquoise": "https://upload.wikimedia.org/wikipedia/commons/d/d6/Turquoise.jpg"
53
- # }
 
 
 
 
 
54
 
55
- # if birthstone in image_urls:
56
- # response = requests.get(image_urls[birthstone])
57
- # img = Image.open(BytesIO(response.content))
58
- # img.show()
59
- # return f"Hello {name}, your birthstone is {birthstone}!"
60
- # else:
61
- # return f"Hello {name}, we could not determine your birthstone."
62
 
63
- return get_birthstone
64
 
65
  @tool
66
  def get_current_time_in_timezone(timezone: str) -> str:
 
11
 
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
  @tool
14
+ def destiny_still_arrives(name:str, dob:str)-> str: #it's import to specify the return type
15
+ # Keep this format for the description / args / args description but feel free to modify the tool
16
+ """A tool that takes a name, age or date of birth as input. It outputs the meaning of the name, an image of that person's birthstone and a horoscope reading of the day.
17
+ Args:
18
+ name: A string representing a person's age
19
+ age_or_dob: A string representing a person's age or date of birth
20
+ """
21
+ def get_birthstone(name: str, dob: str):
22
+ birthstones = {
23
+ "January": "Garnet",
24
+ "February": "Amethyst",
25
+ "March": "Aquamarine",
26
+ "April": "Diamond",
27
+ "May": "Emerald",
28
+ "June": "Pearl",
29
+ "July": "Ruby",
30
+ "August": "Peridot",
31
+ "September": "Sapphire",
32
+ "October": "Opal",
33
+ "November": "Topaz",
34
+ "December": "Turquoise"
35
+ }
36
+
37
+ month = datetime.strptime(dob, "%Y-%m-%d").strftime("%B")
38
+ birthstone = birthstones.get(month, "Unknown")
39
+
40
+ model = HfApiModel(
41
+ max_tokens=2096,
42
+ temperature=0.5,
43
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
44
+ custom_role_conversions=None,
45
+ )
46
 
 
 
47
 
48
+ # Import tool from Hub
49
+ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
50
+
51
+ with open("prompts.yaml", 'r') as stream:
52
+ prompt_templates = yaml.safe_load(stream)
53
+
54
+ agent = CodeAgent(
55
+ model=model,
56
+ tools=[final_answer,image_generation_tool], ## add your tools here (don't remove final answer)
57
+ max_steps=6,
58
+ verbosity_level=1,
59
+ grammar=None,
60
+ planning_interval=None,
61
+ name=None,
62
+ description=None,
63
+ prompt_templates=prompt_templates
64
+ )
65
+
66
+
67
 
68
+ if birthstone in image_urls:
69
+ response = agent.run(f"Generate an image of the following birthstone: {birthstone}")
70
+ else:
71
+ response = agent.run("Generate an image of the following birthstone: Sapphire")
 
 
 
72
 
73
+ return response
74
 
75
  @tool
76
  def get_current_time_in_timezone(timezone: str) -> str: