import difflib from difflib import SequenceMatcher as SM import gradio as gr from gradio.components import Textbox import pokemons POKEMON_EVOLUTIONS, NAME_MAP = pokemons.get_pokemon_evolutions() with open("all pokemons.txt", "r", encoding="utf-8") as f: POKENAMES = [pokemon.strip().lower() for pokemon in f.readlines()] for name in POKEMON_EVOLUTIONS: assert name in POKENAMES, name def can_it_evolve(pokemon: str): pokemon = pokemon.lower().strip() if len(pokemon) == 0: return "Enter the name of the pokemon" matches = difflib.get_close_matches(pokemon, POKENAMES, n=1, cutoff=0) if len(matches) == 0: return f'Pokemon "{pokemon}" was not found, like not even a fuzzy match' # if SM(None, matches[0], pokemon).ratio() < 0.6: # return f'Pokemon "{pokemon}" was not found, did you mean {matches[0]}?' pokemon = matches[0] if pokemon in POKEMON_EVOLUTIONS: evo_methods = '\n - '.join(POKEMON_EVOLUTIONS[pokemon]) return f"{NAME_MAP[pokemon]} can evolve:\n - {evo_methods}" assert pokemon not in NAME_MAP return f"{pokemon.title()} doesn't evolve." demo = gr.Interface( can_it_evolve, [ Textbox(label="Enter the name of the pokemon"), ], [ Textbox(label="Does it evolve?", lines=4), ], live=True, title="Does this Pokemon evolve?", description="This shows you if a Pokemon can evolve and how. Unlike using Wiki, this doesn't spoil what it evolves into and at what level.\nI also used real time fuzzy search so that you don't have to enter exact name of a Pokemon.", article="""data was scrapped from https://pokemondb.net/evolution/level and contains all 1,025 pokemons. Most pokemon evolve upon reaching a certain level. A few Pokémon also need to meet a condition such as gender to evolve; these are also listed. To evolve a Pokémon via stone, simply select the item to use in your bag, then select the Pokémon to apply it to - they will evolve straight away. A Pokémon's Friendship (aka happiness) can be increased in many ways. The simplest is walking around with the Pokémon in your party, battling and growing them, but not letting them faint. Massages and haircuts increase Friendship by a larger amount. Giving them a Soothe Bell to hold increases the effect of the other methods. See more in the glossary or this PokéBase question. For special conditions, once the condition is met, the Pokémon needs to level up once more in order to evolve.""", ) demo.launch()