mobrobro commited on
Commit
26001c8
·
verified ·
1 Parent(s): 5f4a21a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -85
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(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
- # 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: