Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,29 +8,7 @@ import requests
|
|
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,
|
11 |
-
|
12 |
-
"Electro Giant": 18, "Electro Spirit": 19, "Electro Wizard": 20, "Elite Barbarians": 21,
|
13 |
-
"Elixir Blob": 22, "Elixir Golem": 23, "Elixir Golemite": 24, "Executioner": 25, "Firecracker": 26,
|
14 |
-
"Fire Spirit": 27, "Fisherman": 28, "Flying Machine": 29, "Giant": 30, "Giant Skeleton": 31,
|
15 |
-
"Goblin Brawler": 32, "Goblin Gang": 33, "Goblin Demolisher": 34, "Goblin Giant": 35,
|
16 |
-
"Goblin Machine": 36, "Goblins": 37, "Goblinstein": 38, "Golden Knight": 39, "Golem": 40,
|
17 |
-
"Golemite": 41, "Guardienne": 42, "Guards": 43, "Hog Rider": 44, "Hunter": 45, "Heal Spirit": 46,
|
18 |
-
"Ice Golem": 47, "Ice Spirit": 48, "Ice Wizard": 49, "Inferno Dragon": 50, "Knight": 51,
|
19 |
-
"Lava Hound": 52, "Lava Pup": 53, "Little Prince": 54, "Lumberjack": 55, "Magic Archer": 56,
|
20 |
-
"Mega Knight": 57, "Mega Minion": 58, "Mighty Miner": 59, "Miner": 60, "Mini P.E.K.K.A.": 61,
|
21 |
-
"Minion Horde": 62, "Minions": 63, "Monk": 64, "Mother Witch": 65, "Monster": 66, "Musketeer": 67,
|
22 |
-
"Night Witch": 68, "P.E.K.K.A.": 69, "Phoenix": 70, "Reborn Phoenix": 71, "Prince": 72,
|
23 |
-
"Princess": 73, "Ram Rider": 74, "Rascal Boy": 75, "Rascal Girl": 76, "Royal Ghost": 77,
|
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
|
@@ -104,8 +82,8 @@ with gr.Blocks(css="""
|
|
104 |
# State for tracking selected cards
|
105 |
selected_cards_display = gr.Markdown("Selected cards: 0/8")
|
106 |
|
107 |
-
def update_selection(checkbox_values):
|
108 |
-
selected_count = sum(
|
109 |
return f"Selected cards: {selected_count}/8"
|
110 |
|
111 |
# Create card grid using rows and columns
|
@@ -120,11 +98,6 @@ with gr.Blocks(css="""
|
|
120 |
gr.Image(value=url, show_label=False)
|
121 |
checkbox = gr.Checkbox(label=card, elem_classes="checkbox-container")
|
122 |
all_checkboxes.append(checkbox)
|
123 |
-
checkbox.change(
|
124 |
-
update_selection,
|
125 |
-
inputs=all_checkboxes,
|
126 |
-
outputs=selected_cards_display
|
127 |
-
)
|
128 |
|
129 |
with gr.Row():
|
130 |
result = gr.Textbox(label="Prediction Result:", interactive=False)
|
@@ -145,7 +118,7 @@ with gr.Blocks(css="""
|
|
145 |
if checked
|
146 |
]
|
147 |
if len(selected_cards) != 8:
|
148 |
-
return "Error: Please select exactly 8 cards"
|
149 |
return predict_outcome(selected_cards)
|
150 |
|
151 |
predict_btn.click(
|
@@ -154,4 +127,12 @@ with gr.Blocks(css="""
|
|
154 |
outputs=result
|
155 |
)
|
156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
interface.launch()
|
|
|
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,
|
11 |
+
# Add other cards...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
}
|
13 |
|
14 |
# Generate card_images with normalized filenames
|
|
|
82 |
# State for tracking selected cards
|
83 |
selected_cards_display = gr.Markdown("Selected cards: 0/8")
|
84 |
|
85 |
+
def update_selection(*checkbox_values):
|
86 |
+
selected_count = sum(checkbox_values)
|
87 |
return f"Selected cards: {selected_count}/8"
|
88 |
|
89 |
# Create card grid using rows and columns
|
|
|
98 |
gr.Image(value=url, show_label=False)
|
99 |
checkbox = gr.Checkbox(label=card, elem_classes="checkbox-container")
|
100 |
all_checkboxes.append(checkbox)
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
with gr.Row():
|
103 |
result = gr.Textbox(label="Prediction Result:", interactive=False)
|
|
|
118 |
if checked
|
119 |
]
|
120 |
if len(selected_cards) != 8:
|
121 |
+
return f"Error: Please select exactly 8 cards. You selected {len(selected_cards)}."
|
122 |
return predict_outcome(selected_cards)
|
123 |
|
124 |
predict_btn.click(
|
|
|
127 |
outputs=result
|
128 |
)
|
129 |
|
130 |
+
# Update the card count display
|
131 |
+
for checkbox in all_checkboxes:
|
132 |
+
checkbox.change(
|
133 |
+
update_selection,
|
134 |
+
inputs=all_checkboxes,
|
135 |
+
outputs=selected_cards_display
|
136 |
+
)
|
137 |
+
|
138 |
interface.launch()
|