Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,9 +2,9 @@ import gradio as gr
|
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
4 |
from xgboost import Booster, DMatrix
|
|
|
5 |
|
6 |
-
|
7 |
-
# Generating the complete `card_images` dictionary
|
8 |
card_numbers = {
|
9 |
"Archers": 1, "Archer Queen": 2, "Baby Dragon": 3, "Balloon": 4, "Bandit": 5, "Barbarians": 6,
|
10 |
"Bats": 7, "Battle Healer": 8, "Battle Ram": 9, "Bomber": 10, "Bowler": 11, "Bush Goblins": 12,
|
@@ -24,154 +24,30 @@ card_numbers = {
|
|
24 |
"Royal Giant": 78, "Royal Hogs": 79, "Royal Recruits": 80, "Skeleton Army": 81,
|
25 |
"Skeleton Barrel": 82, "Skeleton Dragons": 83, "Skeleton King": 84, "Skeletons": 85, "Sparky": 86,
|
26 |
"Spear Goblins": 87, "Suspicious Bush": 88, "Three Musketeers": 89, "Valkyrie": 90,
|
27 |
-
"Wall Breakers": 91, "Witch": 92, "Wizard": 93, "Zappies": 94, "Bomb Tower": 95, "Cannon": 96,
|
28 |
-
"
|
29 |
-
"
|
30 |
-
"Goblin
|
31 |
-
"
|
32 |
-
"
|
33 |
-
"
|
34 |
-
#"Archers/Evolution": 155, "Barbarians/Evolution": 156, "Battle Ram/Evolution": 157,
|
35 |
-
#"Bats/Evolution": 158, "Bomber/Evolution": 159, "Cannon/Evolution": 160,
|
36 |
-
#"Electro Dragon/Evolution": 161, "Firecracker/Evolution": 162, "Giant Snowball/Evolution": 163,
|
37 |
-
#"Goblin Barrel/Evolution": 164, "Goblin Cage/Evolution": 165, "Goblin Drill/Evolution": 166,
|
38 |
-
#"Goblin Giant/Evolution": 167, "Ice Spirit/Evolution": 168, "Knight/Evolution": 169,
|
39 |
-
#"Mega Knight/Evolution": 170, "Mortar/Evolution": 171, "Musketeer/Evolution": 172,
|
40 |
-
#"P.E.K.K.A/Evolution": 173, "Royal Giant/Evolution": 174, "Royal Recruits/Evolution": 175,
|
41 |
-
#"Skeletons/Evolution": 176, "Tesla/Evolution": 177, "Valkyrie/Evolution": 178,
|
42 |
-
#"Wall Breakers/Evolution": 179, "Wizard/Evolution": 180, "Zap/Evolution": 181
|
43 |
}
|
44 |
|
45 |
-
#
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
"Bandit": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/bandit.png",
|
51 |
-
"Barbarians": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/barbarians.png",
|
52 |
-
"Bats": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/bats.png",
|
53 |
-
"Battle Healer": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/battle-healer.png",
|
54 |
-
"Battle Ram": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/battle-ram.png",
|
55 |
-
"Bomber": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/bomber.png",
|
56 |
-
"Bowler": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/bowler.png",
|
57 |
-
"Bush Goblins": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/bush-goblins.png",
|
58 |
-
"Cannon Cart": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/cannon-cart.png",
|
59 |
-
"Cursed Hog": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/cursed-hog.png",
|
60 |
-
"Dark Prince": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/dark-prince.png",
|
61 |
-
"Dart Goblin": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/dart-goblin.png",
|
62 |
-
"Electro Dragon": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/electro-dragon.png",
|
63 |
-
"Electro Giant": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/electro-giant.png",
|
64 |
-
"Electro Spirit": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/electro-spirit.png",
|
65 |
-
"Electro Wizard": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/electro-wizard.png",
|
66 |
-
"Elite Barbarians": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/elite-barbarians.png",
|
67 |
-
"Elixir Blob": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/elixir-blob.png",
|
68 |
-
"Elixir Golem": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/elixir-golem.png",
|
69 |
-
"Elixir Golemite": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/elixir-golemite.png",
|
70 |
-
"Executioner": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/executioner.png",
|
71 |
-
"Firecracker": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/firecracker.png",
|
72 |
-
"Fire Spirit": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/fire-spirit.png",
|
73 |
-
"Fisherman": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/fisherman.png",
|
74 |
-
"Flying Machine": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/flying-machine.png",
|
75 |
-
"Giant": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/giant.png",
|
76 |
-
"Giant Skeleton": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/giant-skeleton.png",
|
77 |
-
"Goblin Brawler": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-brawler.png",
|
78 |
-
"Goblin Gang": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-gang.png",
|
79 |
-
"Goblin Demolisher": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-demolisher.png",
|
80 |
-
"Goblin Giant": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-giant.png",
|
81 |
-
"Goblin Machine": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-machine.png",
|
82 |
-
"Goblins": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblins.png",
|
83 |
-
"Goblinstein": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblinstein.png",
|
84 |
-
"Golden Knight": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/golden-knight.png",
|
85 |
-
"Golem": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/golem.png",
|
86 |
-
"Golemite": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/golemite.png",
|
87 |
-
"Guardienne": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/guardienne.png",
|
88 |
-
"Guards": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/guards.png",
|
89 |
-
"Hog Rider": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/hog-rider.png",
|
90 |
-
"Hunter": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/hunter.png",
|
91 |
-
"Heal Spirit": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/heal-spirit.png",
|
92 |
-
"Ice Golem": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/ice-golem.png",
|
93 |
-
"Ice Spirit": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/ice-spirit.png",
|
94 |
-
"Ice Wizard": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/ice-wizard.png",
|
95 |
-
"Inferno Dragon": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/inferno-dragon.png",
|
96 |
-
"Knight": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/knight.png",
|
97 |
-
"Lava Hound": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/lava-hound.png",
|
98 |
-
"Lava Pup": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/lava-pup.png",
|
99 |
-
"Little Prince": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/little-prince.png",
|
100 |
-
"Lumberjack": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/lumberjack.png",
|
101 |
-
"Magic Archer": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/magic-archer.png",
|
102 |
-
"Mega Knight": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/mega-knight.png",
|
103 |
-
"Mega Minion": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/mega-minion.png",
|
104 |
-
"Mighty Miner": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/mighty-miner.png",
|
105 |
-
"Miner": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/miner.png",
|
106 |
-
"Mini P.E.K.K.A.": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/mini-pekka.png",
|
107 |
-
"Minion Horde": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/minion-horde.png",
|
108 |
-
"Minions": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/minions.png",
|
109 |
-
"Monk": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/monk.png",
|
110 |
-
"Mother Witch": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/mother-witch.png",
|
111 |
-
"Monster": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/monster.png",
|
112 |
-
"Musketeer": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/musketeer.png",
|
113 |
-
"Night Witch": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/night-witch.png",
|
114 |
-
"P.E.K.K.A.": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/pekka.png",
|
115 |
-
"Phoenix": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/phoenix.png",
|
116 |
-
"Reborn Phoenix": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/reborn-phoenix.png",
|
117 |
-
"Prince": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/prince.png",
|
118 |
-
"Princess": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/princess.png",
|
119 |
-
"Ram Rider": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/ram-rider.png",
|
120 |
-
"Rascal Boy": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/rascal-boy.png",
|
121 |
-
"Rascal Girl": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/rascal-girl.png",
|
122 |
-
"Royal Ghost": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/royal-ghost.png",
|
123 |
-
"Royal Giant": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/royal-giant.png",
|
124 |
-
"Royal Hogs": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/royal-hogs.png",
|
125 |
-
"Royal Recruits": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/royal-recruits.png",
|
126 |
-
"Skeleton Army": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/skeleton-army.png",
|
127 |
-
"Skeleton Barrel": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/skeleton-barrel.png",
|
128 |
-
"Skeleton Dragons": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/skeleton-dragons.png",
|
129 |
-
"Skeleton King": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/skeleton-king.png",
|
130 |
-
"Skeletons": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/skeletons.png",
|
131 |
-
"Sparky": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/sparky.png",
|
132 |
-
"Spear Goblins": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/spear-goblins.png",
|
133 |
-
"Suspicious Bush": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/suspicious-bush.png",
|
134 |
-
"Three Musketeers": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/three-musketeers.png",
|
135 |
-
"Valkyrie": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/valkyrie.png",
|
136 |
-
"Wall Breakers": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/wall-breakers.png",
|
137 |
-
"Witch": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/witch.png",
|
138 |
-
"Wizard": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/wizard.png",
|
139 |
-
"Zappies": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/zappies.png",
|
140 |
-
"Bomb Tower": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/bomb-tower.png",
|
141 |
-
"Cannon": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/cannon.png",
|
142 |
-
"Cannon Cart (broken)": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/cannon-cart-(broken).png",
|
143 |
-
"Inferno Tower": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/inferno-tower.png",
|
144 |
-
"Mortar": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/mortar.png",
|
145 |
-
"Tesla": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/tesla.png",
|
146 |
-
"X-Bow": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/x-bow.png",
|
147 |
-
"Barbarian Hut": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/barbarian-hut.png",
|
148 |
-
"Elixir Collector": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/elixir-collector.png",
|
149 |
-
"Furnace": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/furnace.png",
|
150 |
-
"Goblin Cage": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-cage.png",
|
151 |
-
"Goblin Drill": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-drill.png",
|
152 |
-
"Goblin Hut": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-hut.png",
|
153 |
-
"Phoenix Egg": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/phoenix-egg.png",
|
154 |
-
"Tombstone": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/tombstone.png",
|
155 |
-
"Arrows": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/arrows.png",
|
156 |
-
"Barbarian Barrel": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/barbarian-barrel.png",
|
157 |
-
"Earthquake": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/earthquake.png",
|
158 |
-
"Fireball": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/fireball.png",
|
159 |
-
"Freeze": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/freeze.png",
|
160 |
-
"Giant Snowball": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/giant-snowball.png",
|
161 |
-
"Goblin Curse": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-curse.png",
|
162 |
-
"Lightning": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/lightning.png",
|
163 |
-
"Poison": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/poison.png",
|
164 |
-
"Rage": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/rage.png",
|
165 |
-
"Rocket": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/rocket.png",
|
166 |
-
"Royal Delivery": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/royal-delivery.png",
|
167 |
-
"The Log": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/the-log.png",
|
168 |
-
"Tornado": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/tornado.png",
|
169 |
-
"Void": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/void.png",
|
170 |
-
"Zap": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/zap.png",
|
171 |
-
"Goblin Barrel": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/goblin-barrel.png",
|
172 |
-
"Graveyard": "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/graveyard.png"
|
173 |
}
|
174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
MODEL_PATH = "model.json"
|
176 |
|
177 |
def load_model(model_path):
|
@@ -210,34 +86,32 @@ with gr.Blocks() as interface:
|
|
210 |
|
211 |
selected_deck = gr.State([]) # To store selected cards
|
212 |
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
state.remove(card_name)
|
220 |
-
else:
|
221 |
-
state.append(card_name)
|
222 |
-
return state
|
223 |
-
return toggle
|
224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
button = gr.Image(
|
226 |
value=image_url,
|
227 |
-
label=card_name,
|
228 |
interactive=True,
|
|
|
|
|
229 |
)
|
230 |
-
button.
|
231 |
-
card_buttons.append(button)
|
232 |
|
|
|
233 |
result = gr.Textbox(label="Prediction Result:", interactive=False)
|
234 |
|
235 |
-
def validate_and_predict(deck):
|
236 |
-
if len(deck) != 8:
|
237 |
-
return "Error: Select exactly 8 cards."
|
238 |
-
return predict_outcome(deck)
|
239 |
-
|
240 |
-
predict_button = gr.Button("Make Prediction")
|
241 |
predict_button.click(validate_and_predict, inputs=[selected_deck], outputs=[result])
|
242 |
|
243 |
-
interface.launch()
|
|
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
4 |
from xgboost import Booster, DMatrix
|
5 |
+
import requests
|
6 |
|
7 |
+
# Generate card_numbers
|
|
|
8 |
card_numbers = {
|
9 |
"Archers": 1, "Archer Queen": 2, "Baby Dragon": 3, "Balloon": 4, "Bandit": 5, "Barbarians": 6,
|
10 |
"Bats": 7, "Battle Healer": 8, "Battle Ram": 9, "Bomber": 10, "Bowler": 11, "Bush Goblins": 12,
|
|
|
24 |
"Royal Giant": 78, "Royal Hogs": 79, "Royal Recruits": 80, "Skeleton Army": 81,
|
25 |
"Skeleton Barrel": 82, "Skeleton Dragons": 83, "Skeleton King": 84, "Skeletons": 85, "Sparky": 86,
|
26 |
"Spear Goblins": 87, "Suspicious Bush": 88, "Three Musketeers": 89, "Valkyrie": 90,
|
27 |
+
"Wall Breakers": 91, "Witch": 92, "Wizard": 93, "Zappies": 94, "Bomb Tower": 95, "Cannon": 96,
|
28 |
+
"Inferno Tower": 98, "Mortar": 99, "Tesla": 100, "X-Bow": 101, "Barbarian Hut": 102,
|
29 |
+
"Elixir Collector": 103, "Furnace": 104, "Goblin Cage": 105, "Goblin Drill": 106,
|
30 |
+
"Goblin Hut": 107, "Phoenix Egg": 108, "Tombstone": 109, "Arrows": 110, "Barbarian Barrel": 111,
|
31 |
+
"Earthquake": 112, "Fireball": 113, "Freeze": 114, "Giant Snowball": 115, "Lightning": 117,
|
32 |
+
"Poison": 118, "Rage": 119, "Rocket": 120, "Royal Delivery": 121, "The Log": 122, "Tornado": 123,
|
33 |
+
"Zap": 125, "Goblin Barrel": 132, "Graveyard": 139,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
}
|
35 |
|
36 |
+
# Generate card_images with normalized filenames
|
37 |
+
base_url = "https://raw.githubusercontent.com/RoyaleAPI/cr-api-assets/master/cards/"
|
38 |
+
card_images = {
|
39 |
+
card_name: f"{base_url}{card_name.lower().replace(' ', '-').replace('/', '-').replace('.', '')}.png"
|
40 |
+
for card_name in card_numbers.keys()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
}
|
42 |
|
43 |
+
# Validate URLs
|
44 |
+
valid_card_images = {}
|
45 |
+
for card, url in card_images.items():
|
46 |
+
response = requests.head(url)
|
47 |
+
if response.status_code == 200:
|
48 |
+
valid_card_images[card] = url
|
49 |
+
|
50 |
+
# Define model-related functions
|
51 |
MODEL_PATH = "model.json"
|
52 |
|
53 |
def load_model(model_path):
|
|
|
86 |
|
87 |
selected_deck = gr.State([]) # To store selected cards
|
88 |
|
89 |
+
def toggle_card(card_name, state):
|
90 |
+
if card_name in state:
|
91 |
+
state.remove(card_name)
|
92 |
+
else:
|
93 |
+
state.append(card_name)
|
94 |
+
return state
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
+
def validate_and_predict(deck):
|
97 |
+
if len(deck) != 8:
|
98 |
+
return "Error: Select exactly 8 cards."
|
99 |
+
return predict_outcome(deck)
|
100 |
+
|
101 |
+
# Create card selection grid
|
102 |
+
with gr.Row():
|
103 |
+
for card_name, image_url in valid_card_images.items():
|
104 |
button = gr.Image(
|
105 |
value=image_url,
|
|
|
106 |
interactive=True,
|
107 |
+
label=card_name,
|
108 |
+
type="pil",
|
109 |
)
|
110 |
+
button.click(toggle_card, inputs=[card_name, selected_deck], outputs=[selected_deck])
|
|
|
111 |
|
112 |
+
predict_button = gr.Button("Make Prediction")
|
113 |
result = gr.Textbox(label="Prediction Result:", interactive=False)
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
predict_button.click(validate_and_predict, inputs=[selected_deck], outputs=[result])
|
116 |
|
117 |
+
interface.launch()
|