File size: 18,841 Bytes
7418c14
 
 
075b4b2
dc0fd01
7418c14
075b4b2
7418c14
f8180fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
075b4b2
 
 
 
 
 
88f0e0b
 
 
 
 
 
 
 
 
 
075b4b2
f8180fb
58e7b27
7c4000a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7418c14
 
075b4b2
 
 
 
 
 
 
7418c14
 
 
94172b1
7418c14
 
 
 
075b4b2
7418c14
075b4b2
 
7418c14
 
 
 
 
075b4b2
7418c14
075b4b2
7418c14
075b4b2
 
7418c14
075b4b2
7418c14
 
075b4b2
94172b1
c216029
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7418c14
 
 
 
 
 
075b4b2
7418c14
94172b1
7418c14
c216029
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import gradio as gr
import pandas as pd
import numpy as np
from xgboost import Booster, DMatrix


# Generating the complete `card_images` dictionary
card_numbers = {
    "Archers": 1, "Archer Queen": 2, "Baby Dragon": 3, "Balloon": 4, "Bandit": 5, "Barbarians": 6,
    "Bats": 7, "Battle Healer": 8, "Battle Ram": 9, "Bomber": 10, "Bowler": 11, "Bush Goblins": 12,
    "Cannon Cart": 13, "Cursed Hog": 14, "Dark Prince": 15, "Dart Goblin": 16, "Electro Dragon": 17,
    "Electro Giant": 18, "Electro Spirit": 19, "Electro Wizard": 20, "Elite Barbarians": 21,
    "Elixir Blob": 22, "Elixir Golem": 23, "Elixir Golemite": 24, "Executioner": 25, "Firecracker": 26,
    "Fire Spirit": 27, "Fisherman": 28, "Flying Machine": 29, "Giant": 30, "Giant Skeleton": 31,
    "Goblin Brawler": 32, "Goblin Gang": 33, "Goblin Demolisher": 34, "Goblin Giant": 35,
    "Goblin Machine": 36, "Goblins": 37, "Goblinstein": 38, "Golden Knight": 39, "Golem": 40,
    "Golemite": 41, "Guardienne": 42, "Guards": 43, "Hog Rider": 44, "Hunter": 45, "Heal Spirit": 46,
    "Ice Golem": 47, "Ice Spirit": 48, "Ice Wizard": 49, "Inferno Dragon": 50, "Knight": 51,
    "Lava Hound": 52, "Lava Pup": 53, "Little Prince": 54, "Lumberjack": 55, "Magic Archer": 56,
    "Mega Knight": 57, "Mega Minion": 58, "Mighty Miner": 59, "Miner": 60, "Mini P.E.K.K.A.": 61,
    "Minion Horde": 62, "Minions": 63, "Monk": 64, "Mother Witch": 65, "Monster": 66, "Musketeer": 67,
    "Night Witch": 68, "P.E.K.K.A.": 69, "Phoenix": 70, "Reborn Phoenix": 71, "Prince": 72,
    "Princess": 73, "Ram Rider": 74, "Rascal Boy": 75, "Rascal Girl": 76, "Royal Ghost": 77,
    "Royal Giant": 78, "Royal Hogs": 79, "Royal Recruits": 80, "Skeleton Army": 81,
    "Skeleton Barrel": 82, "Skeleton Dragons": 83, "Skeleton King": 84, "Skeletons": 85, "Sparky": 86,
    "Spear Goblins": 87, "Suspicious Bush": 88, "Three Musketeers": 89, "Valkyrie": 90,
    "Wall Breakers": 91, "Witch": 92, "Wizard": 93, "Zappies": 94, "Bomb Tower": 95, "Cannon": 96, 
    "Cannon Cart (broken)": 97, "Inferno Tower": 98, "Mortar": 99, "Tesla": 100, "X-Bow": 101,
    "Barbarian Hut": 102, "Elixir Collector": 103, "Furnace": 104, "Goblin Cage": 105,
    "Goblin Drill": 106, "Goblin Hut": 107, "Phoenix Egg": 108, "Tombstone": 109, "Arrows": 110, 
    "Barbarian Barrel": 111, "Earthquake": 112, "Fireball": 113, "Freeze": 114, "Giant Snowball": 115, 
    "Goblin Curse": 116, "Lightning": 117, "Poison": 118, "Rage": 119, "Rocket": 120, 
    "Royal Delivery": 121, "The Log": 122, "Tornado": 123, "Void": 124, "Zap": 125#,
    #"Archers/Evolution": 155, "Barbarians/Evolution": 156, "Battle Ram/Evolution": 157,
    #"Bats/Evolution": 158, "Bomber/Evolution": 159, "Cannon/Evolution": 160,
    #"Electro Dragon/Evolution": 161, "Firecracker/Evolution": 162, "Giant Snowball/Evolution": 163,
    #"Goblin Barrel/Evolution": 164, "Goblin Cage/Evolution": 165, "Goblin Drill/Evolution": 166,
    #"Goblin Giant/Evolution": 167, "Ice Spirit/Evolution": 168, "Knight/Evolution": 169,
    #"Mega Knight/Evolution": 170, "Mortar/Evolution": 171, "Musketeer/Evolution": 172,
    #"P.E.K.K.A/Evolution": 173, "Royal Giant/Evolution": 174, "Royal Recruits/Evolution": 175,
    #"Skeletons/Evolution": 176, "Tesla/Evolution": 177, "Valkyrie/Evolution": 178,
    #"Wall Breakers/Evolution": 179, "Wizard/Evolution": 180, "Zap/Evolution": 181
}

# Normalize card names and generate the full URLs
card_images = {"Archers": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/archers.png",
"Archer Queen": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/archer-queen.png",
"Baby Dragon": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/baby-dragon.png",
"Balloon": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/balloon.png",
"Bandit": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/bandit.png",
"Barbarians": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/barbarians.png",
"Bats": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/bats.png",
"Battle Healer": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/battle-healer.png",
"Battle Ram": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/battle-ram.png",
"Bomber": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/bomber.png",
"Bowler": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/bowler.png",
"Bush Goblins": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/bush-goblins.png",
"Cannon Cart": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/cannon-cart.png",
"Cursed Hog": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/cursed-hog.png",
"Dark Prince": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/dark-prince.png",
"Dart Goblin": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/dart-goblin.png",
"Electro Dragon": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/electro-dragon.png",
"Electro Giant": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/electro-giant.png",
"Electro Spirit": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/electro-spirit.png",
"Electro Wizard": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/electro-wizard.png",
"Elite Barbarians": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/elite-barbarians.png",
"Elixir Blob": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/elixir-blob.png",
"Elixir Golem": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/elixir-golem.png",
"Elixir Golemite": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/elixir-golemite.png",
"Executioner": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/executioner.png",
"Firecracker": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/firecracker.png",
"Fire Spirit": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/fire-spirit.png",
"Fisherman": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/fisherman.png",
"Flying Machine": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/flying-machine.png",
"Giant": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/giant.png",
"Giant Skeleton": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/giant-skeleton.png",
"Goblin Brawler": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-brawler.png",
"Goblin Gang": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-gang.png",
"Goblin Demolisher": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-demolisher.png",
"Goblin Giant": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-giant.png",
"Goblin Machine": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-machine.png",
"Goblins": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblins.png",
"Goblinstein": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblinstein.png",
"Golden Knight": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/golden-knight.png",
"Golem": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/golem.png",
"Golemite": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/golemite.png",
"Guardienne": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/guardienne.png",
"Guards": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/guards.png",
"Hog Rider": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/hog-rider.png",
"Hunter": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/hunter.png",
"Heal Spirit": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/heal-spirit.png",
"Ice Golem": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/ice-golem.png",
"Ice Spirit": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/ice-spirit.png",
"Ice Wizard": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/ice-wizard.png",
"Inferno Dragon": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/inferno-dragon.png",
"Knight": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/knight.png",
"Lava Hound": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/lava-hound.png",
"Lava Pup": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/lava-pup.png",
"Little Prince": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/little-prince.png",
"Lumberjack": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/lumberjack.png",
"Magic Archer": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/magic-archer.png",
"Mega Knight": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/mega-knight.png",
"Mega Minion": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/mega-minion.png",
"Mighty Miner": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/mighty-miner.png",
"Miner": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/miner.png",
"Mini P.E.K.K.A.": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/mini-pekka.png",
"Minion Horde": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/minion-horde.png",
"Minions": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/minions.png",
"Monk": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/monk.png",
"Mother Witch": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/mother-witch.png",
"Monster": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/monster.png",
"Musketeer": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/musketeer.png",
"Night Witch": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/night-witch.png",
"P.E.K.K.A.": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/pekka.png",
"Phoenix": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/phoenix.png",
"Reborn Phoenix": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/reborn-phoenix.png",
"Prince": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/prince.png",
"Princess": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/princess.png",
"Ram Rider": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/ram-rider.png",
"Rascal Boy": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/rascal-boy.png",
"Rascal Girl": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/rascal-girl.png",
"Royal Ghost": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/royal-ghost.png",
"Royal Giant": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/royal-giant.png",
"Royal Hogs": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/royal-hogs.png",
"Royal Recruits": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/royal-recruits.png",
"Skeleton Army": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/skeleton-army.png",
"Skeleton Barrel": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/skeleton-barrel.png",
"Skeleton Dragons": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/skeleton-dragons.png",
"Skeleton King": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/skeleton-king.png",
"Skeletons": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/skeletons.png",
"Sparky": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/sparky.png",
"Spear Goblins": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/spear-goblins.png",
"Suspicious Bush": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/suspicious-bush.png",
"Three Musketeers": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/three-musketeers.png",
"Valkyrie": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/valkyrie.png",
"Wall Breakers": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/wall-breakers.png",
"Witch": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/witch.png",
"Wizard": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/wizard.png",
"Zappies": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/zappies.png",
"Bomb Tower": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/bomb-tower.png",
"Cannon": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/cannon.png",
"Cannon Cart (broken)": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/cannon-cart-(broken).png",
"Inferno Tower": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/inferno-tower.png",
"Mortar": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/mortar.png",
"Tesla": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/tesla.png",
"X-Bow": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/x-bow.png",
"Barbarian Hut": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/barbarian-hut.png",
"Elixir Collector": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/elixir-collector.png",
"Furnace": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/furnace.png",
"Goblin Cage": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-cage.png",
"Goblin Drill": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-drill.png",
"Goblin Hut": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-hut.png",
"Phoenix Egg": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/phoenix-egg.png",
"Tombstone": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/tombstone.png",
"Arrows": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/arrows.png",
"Barbarian Barrel": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/barbarian-barrel.png",
"Earthquake": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/earthquake.png",
"Fireball": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/fireball.png",
"Freeze": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/freeze.png",
"Giant Snowball": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/giant-snowball.png",
"Goblin Curse": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-curse.png",
"Lightning": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/lightning.png",
"Poison": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/poison.png",
"Rage": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/rage.png",
"Rocket": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/rocket.png",
"Royal Delivery": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/royal-delivery.png",
"The Log": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/the-log.png",
"Tornado": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/tornado.png",
"Void": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/void.png",
"Zap": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/zap.png",
"Goblin Barrel": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-barrel.png",
"Graveyard": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/graveyard.png"
}

MODEL_PATH = "model.json"

def load_model(model_path):
    """Load the saved XGBoost model."""
    model = Booster()
    model.load_model(model_path)
    return model

def deck_to_ids(deck, mapping):
    """Convert card names to IDs based on the mapping."""
    return [mapping.get(card, 0) - 1 for card in deck]

def preprocess_deck(deck):
    """Prepare the selected deck for the model."""
    deck_ids = deck_to_ids(deck, card_numbers)
    num_choices = len(card_numbers)
    one_hot = np.zeros(num_choices, dtype=int)
    one_hot[np.array(deck_ids)] = 1
    features = np.concatenate(([0, 0], one_hot))
    return pd.DataFrame([features])

def predict_outcome(opponent_deck):
    """Make a prediction based on the opponent's deck."""
    deck_data = preprocess_deck(opponent_deck)
    dmatrix = DMatrix(deck_data)
    prediction = model.predict(dmatrix)
    return f"Probability of Winning: {prediction[0] * 100:.2f}%"

# Load the model
model = load_model(MODEL_PATH)

# Create Gradio Interface
with gr.Blocks() as interface:
    gr.Markdown("## Clash Royale Prediction")
    gr.Markdown("Select 8 cards from the opponent's deck to predict the probability of winning!")

    selected_deck = gr.State([])  # To store selected cards

    card_buttons = []
    with gr.Row():
        for card_name, image_url in card_images.items():
            def select_card(card_name):
                def toggle(state):
                    if card_name in state:
                        state.remove(card_name)
                    else:
                        state.append(card_name)
                    return state
                return toggle

            button = gr.Image(
                value=image_url,
                label=card_name,
                interactive=True,
            )
            button.change(select_card(card_name), inputs=[selected_deck], outputs=[selected_deck])
            card_buttons.append(button)

    result = gr.Textbox(label="Prediction Result:", interactive=False)

    def validate_and_predict(deck):
        if len(deck) != 8:
            return "Error: Select exactly 8 cards."
        return predict_outcome(deck)

    predict_button = gr.Button("Make Prediction")
    predict_button.click(validate_and_predict, inputs=[selected_deck], outputs=[result])

interface.launch()