Grandediw commited on
Commit
bc61848
·
verified ·
1 Parent(s): 6afba73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -32
app.py CHANGED
@@ -81,29 +81,23 @@ model = load_model(MODEL_PATH)
81
 
82
  # Create Gradio Interface
83
  with gr.Blocks(css="""
84
- .container {
85
- display: grid;
86
- grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
87
- gap: 10px;
88
- padding: 10px;
89
  }
90
- .card-container {
91
- display: flex;
92
- flex-direction: column;
93
- align-items: center;
94
  padding: 5px;
95
  border: 1px solid #ddd;
96
  border-radius: 8px;
97
- transition: all 0.3s ease;
98
- }
99
- img.card-image {
100
- width: 80px !important;
101
- height: 80px !important;
102
- object-fit: contain;
103
  }
104
- .selected {
105
- background-color: #e3f2fd;
106
- border-color: #2196f3;
 
107
  }
108
  """) as interface:
109
  gr.Markdown("## Clash Royale Prediction")
@@ -124,20 +118,24 @@ with gr.Blocks(css="""
124
  return current_deck, f"Selected cards: {len(current_deck)}/8"
125
 
126
  # Create card grid using rows and columns
127
- with gr.Column():
128
- cards_per_row = 8
129
- cards_list = list(valid_card_images.items())
130
-
131
- for i in range(0, len(cards_list), cards_per_row):
132
- with gr.Row():
133
- for card, url in cards_list[i:i + cards_per_row]:
134
- with gr.Column():
135
- btn = gr.Button(image=url, label=card)
136
- btn.click(
137
- toggle_card,
138
- inputs=[gr.Textbox(value=card, visible=False), selected_deck],
139
- outputs=[selected_deck, selected_cards_display]
140
- )
 
 
 
 
141
 
142
  with gr.Row():
143
  result = gr.Textbox(label="Prediction Result:", interactive=False)
 
81
 
82
  # Create Gradio Interface
83
  with gr.Blocks(css="""
84
+ .image-container img {
85
+ width: 80px !important;
86
+ height: 80px !important;
87
+ object-fit: contain;
88
+ cursor: pointer;
89
  }
90
+ .image-container {
91
+ text-align: center;
92
+ margin: 5px;
 
93
  padding: 5px;
94
  border: 1px solid #ddd;
95
  border-radius: 8px;
 
 
 
 
 
 
96
  }
97
+ .card-label {
98
+ font-size: 12px;
99
+ margin-top: 5px;
100
+ text-align: center;
101
  }
102
  """) as interface:
103
  gr.Markdown("## Clash Royale Prediction")
 
118
  return current_deck, f"Selected cards: {len(current_deck)}/8"
119
 
120
  # Create card grid using rows and columns
121
+ cards_per_row = 8
122
+ cards_list = list(valid_card_images.items())
123
+
124
+ for i in range(0, len(cards_list), cards_per_row):
125
+ with gr.Row():
126
+ for card, url in cards_list[i:i + cards_per_row]:
127
+ with gr.Column(elem_classes="image-container"):
128
+ img = gr.Image(value=url, interactive=False, show_label=False)
129
+ gr.Markdown(card, elem_classes="card-label")
130
+ # Create a hidden button for click handling
131
+ click_btn = gr.Button(visible=False)
132
+ click_btn.click(
133
+ toggle_card,
134
+ inputs=[gr.Textbox(value=card, visible=False), selected_deck],
135
+ outputs=[selected_deck, selected_cards_display]
136
+ )
137
+ # Trigger the hidden button when the image is clicked
138
+ img.click(lambda: None, None, click_btn.click)
139
 
140
  with gr.Row():
141
  result = gr.Textbox(label="Prediction Result:", interactive=False)