xMikeTR/PTypePredictor
0
1import gradio as gr2import pickle3 4 5with open('PokemonModel.pkl','rb') as f:6 model = pickle.load(f)7 8def predict(type1, type2):9 input_data = [[type1,type2]]10 prediction = model.predict(input_data)11 return prediction[0]12## List of types and their corresponding icon paths13type_options = {14 'Fire': 'icons/fire.svg',15 'Water': 'icons/water.svg',16 'Grass': 'icons/grass.svg',17 'Electric': 'icons/electric.svg',18 'Ice': 'icons/ice.svg',19 'Fighting': 'icons/fighting.svg',20 'Poison': 'icons/poison.svg',21 'Ground': 'icons/ground.svg',22 'Flying': 'icons/flying.svg',23 'Psychic': 'icons/psychic.svg',24 'Bug': 'icons/bug.svg',25 'Rock': 'icons/rock.svg',26 'Ghost': 'icons/ghost.svg',27 'Dragon': 'icons/dragon.svg',28 'Dark': 'icons/dark.svg',29 'Steel': 'icons/steel.svg',30 'Fairy': 'icons/fairy.svg'31}32 33# Store the selected types34selected_types = [None, None]35 36# Function to handle type selection37def select_type(type_name, index):38 selected_types[index] = type_name39 return f"Selected Type 1: {selected_types[0]}, Selected Type 2: {selected_types[1]}"40 41# Function to predict the winner42def predict_and_display():43 type1, type2 = selected_types44 if type1 and type2:45 input_data = [[type1, type2]]46 prediction = model.predict(input_data)47 return f"The predicted winner is: {prediction[0]}"48 else:49 return "Please select both types."50 51# Create Gradio interface52def create_interface():53 with gr.Blocks() as demo:54 gr.Markdown("## Pokemon Type Predictor")55 gr.Markdown("### Select Type 1")56 type1_output = gr.Textbox(label="Selected Type 1")57 type2_output = gr.Textbox(label="Selected Type 2")58 59 with gr.Row():60 for type_name in type_options.keys():61 btn = gr.Button(type_name)62 btn.click(fn=lambda tn=type_name: select_type(tn, 0), inputs=None, outputs=type1_output)63 64 gr.Markdown("### Select Type 2")65 with gr.Row():66 for type_name in type_options.keys():67 btn = gr.Button(type_name)68 btn.click(fn=lambda tn=type_name: select_type(tn, 1), inputs=None, outputs=type2_output)69 70 predict_button = gr.Button("Predict")71 prediction_output = gr.Textbox(label="Prediction")72 predict_button.click(predict_and_display, inputs=None, outputs=prediction_output)73 74 return demo75 76# Launch the interface77demo = create_interface()78demo.launch()79 