Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
@@ -56,7 +57,7 @@ def load_model(model_path):
|
|
56 |
|
57 |
def deck_to_ids(deck, mapping):
|
58 |
"""Convert card names to IDs based on the mapping."""
|
59 |
-
return [mapping.get(card, 0) - 1 for card in deck]
|
60 |
|
61 |
def preprocess_deck(deck):
|
62 |
"""Prepare the selected deck for the model."""
|
@@ -81,13 +82,22 @@ model = load_model(MODEL_PATH)
|
|
81 |
with gr.Blocks() as interface:
|
82 |
gr.Markdown("## Clash Royale Prediction")
|
83 |
gr.Markdown("Select 8 cards from the opponent's deck to predict the probability of winning!")
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
result = gr.Textbox(label="Prediction Result:", interactive=False)
|
93 |
|
@@ -97,6 +107,6 @@ with gr.Blocks() as interface:
|
|
97 |
return predict_outcome(deck)
|
98 |
|
99 |
predict_button = gr.Button("Make Prediction")
|
100 |
-
predict_button.click(validate_and_predict, inputs=[
|
101 |
|
102 |
interface.launch()
|
|
|
1 |
+
|
2 |
import gradio as gr
|
3 |
import pandas as pd
|
4 |
import numpy as np
|
|
|
57 |
|
58 |
def deck_to_ids(deck, mapping):
|
59 |
"""Convert card names to IDs based on the mapping."""
|
60 |
+
return [mapping.get(card, 0) - 1 for card in deck]
|
61 |
|
62 |
def preprocess_deck(deck):
|
63 |
"""Prepare the selected deck for the model."""
|
|
|
82 |
with gr.Blocks() as interface:
|
83 |
gr.Markdown("## Clash Royale Prediction")
|
84 |
gr.Markdown("Select 8 cards from the opponent's deck to predict the probability of winning!")
|
85 |
+
|
86 |
+
selected_deck = []
|
87 |
+
for card_name, image_url in card_images.items():
|
88 |
+
def toggle_card(card_name):
|
89 |
+
if card_name in selected_deck:
|
90 |
+
selected_deck.remove(card_name)
|
91 |
+
else:
|
92 |
+
selected_deck.append(card_name)
|
93 |
+
|
94 |
+
gr.Image(
|
95 |
+
value=image_url,
|
96 |
+
label=card_name,
|
97 |
+
tool="select",
|
98 |
+
interactive=True,
|
99 |
+
click=toggle_card(card_name),
|
100 |
+
)
|
101 |
|
102 |
result = gr.Textbox(label="Prediction Result:", interactive=False)
|
103 |
|
|
|
107 |
return predict_outcome(deck)
|
108 |
|
109 |
predict_button = gr.Button("Make Prediction")
|
110 |
+
predict_button.click(validate_and_predict, inputs=[selected_deck], outputs=[result])
|
111 |
|
112 |
interface.launch()
|