Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,14 +9,91 @@ from Gradio_UI import GradioUI
|
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
@tool
|
12 |
-
def
|
13 |
-
|
14 |
-
"""A tool that does nothing yet
|
15 |
Args:
|
16 |
-
|
17 |
-
|
|
|
|
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
@tool
|
12 |
+
def animal_battle(animal1: str, animal2: str) -> str:
|
13 |
+
"""A tool that takes two animals and decides who would win in a fight and why
|
|
|
14 |
Args:
|
15 |
+
animal1: the first animal
|
16 |
+
animal2: the second animal
|
17 |
+
Returns:
|
18 |
+
str: A description of the battle outcome and reasoning
|
19 |
"""
|
20 |
+
# Dictionary of animals and their characteristics
|
21 |
+
animal_stats = {
|
22 |
+
"lion": {"strength": 9, "speed": 8, "size": 7, "weapons": "claws and teeth", "habitat": "savanna", "intelligence": 7},
|
23 |
+
"elephant": {"strength": 10, "speed": 5, "size": 10, "weapons": "tusks and trunk", "habitat": "savanna/forest", "intelligence": 9},
|
24 |
+
"gorilla": {"strength": 8, "speed": 6, "size": 6, "weapons": "strength and arms", "habitat": "forest", "intelligence": 8},
|
25 |
+
"tiger": {"strength": 9, "speed": 9, "size": 7, "weapons": "claws and teeth", "habitat": "jungle", "intelligence": 7},
|
26 |
+
"bear": {"strength": 9, "speed": 6, "size": 8, "weapons": "claws and strength", "habitat": "forest", "intelligence": 7},
|
27 |
+
"wolf": {"strength": 6, "speed": 8, "size": 5, "weapons": "teeth and pack tactics", "habitat": "forest", "intelligence": 8},
|
28 |
+
"rhinoceros": {"strength": 9, "speed": 6, "size": 9, "weapons": "horn and bulk", "habitat": "savanna", "intelligence": 6},
|
29 |
+
"hippopotamus": {"strength": 9, "speed": 5, "size": 9, "weapons": "jaws and bulk", "habitat": "water/land", "intelligence": 6},
|
30 |
+
"crocodile": {"strength": 8, "speed": 7, "size": 7, "weapons": "jaws and ambush", "habitat": "water", "intelligence": 5},
|
31 |
+
"anaconda": {"strength": 7, "speed": 6, "size": 6, "weapons": "constriction", "habitat": "water/jungle", "intelligence": 4},
|
32 |
+
"cheetah": {"strength": 6, "speed": 10, "size": 5, "weapons": "speed and agility", "habitat": "savanna", "intelligence": 7},
|
33 |
+
"kangaroo": {"strength": 7, "speed": 7, "size": 6, "weapons": "kicks and balance", "habitat": "grassland", "intelligence": 6},
|
34 |
+
"komodo dragon": {"strength": 6, "speed": 6, "size": 5, "weapons": "bacteria and venom", "habitat": "islands", "intelligence": 4},
|
35 |
+
"eagle": {"strength": 5, "speed": 9, "size": 4, "weapons": "talons and beak", "habitat": "air", "intelligence": 7},
|
36 |
+
}
|
37 |
+
|
38 |
+
animal1 = animal1.lower()
|
39 |
+
animal2 = animal2.lower()
|
40 |
+
|
41 |
+
# Check if both animals are in our database
|
42 |
+
if animal1 not in animal_stats or animal2 not in animal_stats:
|
43 |
+
return f"Sorry, I don't have enough information about {'both' if animal1 not in animal_stats and animal2 not in animal_stats else animal1 if animal1 not in animal_stats else animal2} to determine the outcome."
|
44 |
+
|
45 |
+
# Calculate total combat score with weighted attributes
|
46 |
+
def calculate_combat_score(animal):
|
47 |
+
stats = animal_stats[animal]
|
48 |
+
return (stats["strength"] * 1.5 +
|
49 |
+
stats["speed"] * 1.2 +
|
50 |
+
stats["size"] * 1.3 +
|
51 |
+
stats["intelligence"] * 0.8)
|
52 |
+
|
53 |
+
score1 = calculate_combat_score(animal1)
|
54 |
+
score2 = calculate_combat_score(animal2)
|
55 |
+
|
56 |
+
# Consider habitat advantage
|
57 |
+
def has_habitat_advantage(attacker, defender):
|
58 |
+
attacker_habitat = animal_stats[attacker]["habitat"]
|
59 |
+
defender_habitat = animal_stats[defender]["habitat"]
|
60 |
+
if "water" in attacker_habitat and "water" not in defender_habitat:
|
61 |
+
return True
|
62 |
+
if "air" in attacker_habitat and "air" not in defender_habitat:
|
63 |
+
return True
|
64 |
+
return False
|
65 |
+
|
66 |
+
# Adjust scores based on habitat advantage
|
67 |
+
if has_habitat_advantage(animal1, animal2):
|
68 |
+
score1 *= 1.2
|
69 |
+
if has_habitat_advantage(animal2, animal1):
|
70 |
+
score2 *= 1.2
|
71 |
+
|
72 |
+
# Determine winner and create detailed response
|
73 |
+
if abs(score1 - score2) < 2:
|
74 |
+
return f"It would be a close battle between the {animal1} and {animal2}! Both have their advantages: " \
|
75 |
+
f"the {animal1} with its {animal_stats[animal1]['weapons']}, and " \
|
76 |
+
f"the {animal2} with its {animal_stats[animal2]['weapons']}."
|
77 |
+
|
78 |
+
winner = animal1 if score1 > score2 else animal2
|
79 |
+
loser = animal2 if score1 > score2 else animal1
|
80 |
+
winner_stats = animal_stats[winner]
|
81 |
+
|
82 |
+
# Create detailed battle description
|
83 |
+
advantages = []
|
84 |
+
if winner_stats["strength"] > animal_stats[loser]["strength"]:
|
85 |
+
advantages.append("superior strength")
|
86 |
+
if winner_stats["speed"] > animal_stats[loser]["speed"]:
|
87 |
+
advantages.append("greater speed")
|
88 |
+
if winner_stats["size"] > animal_stats[loser]["size"]:
|
89 |
+
advantages.append("larger size")
|
90 |
+
if winner_stats["intelligence"] > animal_stats[loser]["intelligence"]:
|
91 |
+
advantages.append("better tactical ability")
|
92 |
+
|
93 |
+
advantages_text = ", ".join(advantages[:-1]) + f" and {advantages[-1]}" if len(advantages) > 1 else advantages[0]
|
94 |
+
|
95 |
+
return f"The {winner} would win against the {loser}! With its {winner_stats['weapons']}, " \
|
96 |
+
f"{advantages_text}, the {winner} has the clear advantage in this battle."
|
97 |
|
98 |
@tool
|
99 |
def get_current_time_in_timezone(timezone: str) -> str:
|