Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,99 +9,35 @@ 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 animal_battle(
|
| 13 |
"""A tool that takes two animals and decides who would win in a fight and why
|
| 14 |
Args:
|
| 15 |
-
|
| 16 |
-
|
| 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": {"
|
| 23 |
-
"elephant": {"
|
| 24 |
-
"gorilla": {"
|
| 25 |
-
"tiger": {"
|
| 26 |
-
"bear": {"
|
| 27 |
-
"wolf": {"
|
| 28 |
-
"
|
| 29 |
-
"
|
| 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 |
-
|
| 39 |
-
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 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 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
return
|
| 49 |
-
|
| 50 |
-
|
| 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 |
-
# Special case for extreme size differences
|
| 73 |
-
size_difference = abs(animal_stats[animal1]["size"] - animal_stats[animal2]["size"])
|
| 74 |
-
if size_difference > 5:
|
| 75 |
-
bigger_animal = animal1 if animal_stats[animal1]["size"] > animal_stats[animal2]["size"] else animal2
|
| 76 |
-
smaller_animal = animal2 if bigger_animal == animal1 else animal1
|
| 77 |
-
return f"The {bigger_animal} would win against the {smaller_animal}! The size difference is too great - " \
|
| 78 |
-
f"the {bigger_animal}'s sheer mass and strength would overwhelm the {smaller_animal}."
|
| 79 |
-
|
| 80 |
-
# Determine winner and create detailed response
|
| 81 |
-
if abs(score1 - score2) < 2:
|
| 82 |
-
return f"It would be a close battle between the {animal1} and {animal2}! Both have their advantages: " \
|
| 83 |
-
f"the {animal1} with its {animal_stats[animal1]['weapons']}, and " \
|
| 84 |
-
f"the {animal2} with its {animal_stats[animal2]['weapons']}."
|
| 85 |
-
|
| 86 |
-
winner = animal1 if score1 > score2 else animal2
|
| 87 |
-
loser = animal2 if score1 > score2 else animal1
|
| 88 |
-
winner_stats = animal_stats[winner]
|
| 89 |
-
|
| 90 |
-
# Create detailed battle description
|
| 91 |
-
advantages = []
|
| 92 |
-
if winner_stats["strength"] > animal_stats[loser]["strength"]:
|
| 93 |
-
advantages.append("superior strength")
|
| 94 |
-
if winner_stats["speed"] > animal_stats[loser]["speed"]:
|
| 95 |
-
advantages.append("greater speed")
|
| 96 |
-
if winner_stats["size"] > animal_stats[loser]["size"]:
|
| 97 |
-
advantages.append("larger size")
|
| 98 |
-
if winner_stats["intelligence"] > animal_stats[loser]["intelligence"]:
|
| 99 |
-
advantages.append("better tactical ability")
|
| 100 |
-
|
| 101 |
-
advantages_text = ", ".join(advantages[:-1]) + f" and {advantages[-1]}" if len(advantages) > 1 else advantages[0]
|
| 102 |
-
|
| 103 |
-
return f"The {winner} would win against the {loser}! With its {winner_stats['weapons']}, " \
|
| 104 |
-
f"{advantages_text}, the {winner} has the clear advantage in this battle."
|
| 105 |
|
| 106 |
@tool
|
| 107 |
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(arg1: str, arg2: str) -> str:
|
| 13 |
"""A tool that takes two animals and decides who would win in a fight and why
|
| 14 |
Args:
|
| 15 |
+
arg1: the first animal
|
| 16 |
+
arg2: the second animal
|
|
|
|
|
|
|
| 17 |
"""
|
|
|
|
| 18 |
animal_stats = {
|
| 19 |
+
"lion": {"power": 9, "special": "claws and teeth"},
|
| 20 |
+
"elephant": {"power": 10, "special": "size and strength"},
|
| 21 |
+
"gorilla": {"power": 8, "special": "strength and arms"},
|
| 22 |
+
"tiger": {"power": 9, "special": "speed and power"},
|
| 23 |
+
"bear": {"power": 9, "special": "claws and bulk"},
|
| 24 |
+
"wolf": {"power": 7, "special": "pack tactics"},
|
| 25 |
+
"eagle": {"power": 6, "special": "flight and talons"},
|
| 26 |
+
"komodo dragon": {"power": 7, "special": "venom and bite"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
|
| 29 |
+
arg1 = arg1.lower()
|
| 30 |
+
arg2 = arg2.lower()
|
| 31 |
|
| 32 |
+
if arg1 not in animal_stats or arg2 not in animal_stats:
|
| 33 |
+
return f"Sorry, I don't have information about one or both of these animals."
|
|
|
|
| 34 |
|
| 35 |
+
if animal_stats[arg1]["power"] > animal_stats[arg2]["power"]:
|
| 36 |
+
return f"The {arg1} would win with its {animal_stats[arg1]['special']}!"
|
| 37 |
+
elif animal_stats[arg2]["power"] > animal_stats[arg1]["power"]:
|
| 38 |
+
return f"The {arg2} would win with its {animal_stats[arg2]['special']}!"
|
| 39 |
+
else:
|
| 40 |
+
return f"It would be a close fight between the {arg1} and {arg2}!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
@tool
|
| 43 |
def get_current_time_in_timezone(timezone: str) -> str:
|