Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,65 @@
|
|
1 |
-
import
|
2 |
import pandas as pd
|
3 |
from itertools import combinations
|
4 |
from copy import deepcopy
|
5 |
-
import
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
# Read Excel
|
14 |
-
df = pd.read_excel(
|
15 |
|
16 |
-
|
|
|
|
|
|
|
17 |
team_a_names = df.iloc[:, 0].dropna().tolist()
|
18 |
team_b_names = df.iloc[:, 1].dropna().tolist()
|
19 |
|
20 |
team_a = [{"name": str(name).strip()} for name in team_a_names]
|
21 |
team_b = [{"name": str(name).strip()} for name in team_b_names]
|
22 |
|
23 |
-
#
|
|
|
|
|
|
|
|
|
24 |
all_teams = []
|
25 |
-
|
26 |
-
|
|
|
|
|
27 |
new_team = deepcopy(team_a)
|
28 |
-
new_team[i] = deepcopy(team_b[j])
|
29 |
all_teams.append({
|
30 |
-
"Team Name": f"Team {
|
31 |
"Players": new_team
|
32 |
})
|
|
|
33 |
|
34 |
-
# Generate 250
|
35 |
full_team_list = []
|
36 |
team_output_counter = 1
|
|
|
37 |
for team in all_teams:
|
38 |
player_list = team["Players"]
|
39 |
team_name = team["Team Name"]
|
|
|
|
|
40 |
cvc_combos = list(combinations(player_list, 2))
|
41 |
|
42 |
for cap, vc in cvc_combos:
|
@@ -53,38 +76,26 @@ def generate_teams(file, use_default):
|
|
53 |
"Player": member['name'],
|
54 |
"Role": role
|
55 |
})
|
|
|
56 |
full_team_list.extend(team_rows)
|
57 |
team_output_counter += 1
|
58 |
|
|
|
59 |
final_df = pd.DataFrame(full_team_list)
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
final_df.to_csv(csv_buffer, index=False)
|
64 |
-
csv_buffer.seek(0)
|
65 |
-
|
66 |
-
return final_df, csv_buffer
|
67 |
-
|
68 |
-
except Exception as e:
|
69 |
-
return f"❌ Error: {str(e)}", None
|
70 |
-
|
71 |
-
# Gradio interface
|
72 |
-
with gr.Blocks() as demo:
|
73 |
-
gr.Markdown("# 🏏 Generate All 250 Captain–Vice-Captain Combinations")
|
74 |
-
gr.Markdown("Upload an Excel file with Team A (Column A) and Team B (Column B) or use a default file.")
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
-
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
def wrapper(file, use_default):
|
86 |
-
return generate_teams(file, use_default)
|
87 |
-
|
88 |
-
generate_btn.click(fn=wrapper, inputs=[file_input, use_default_checkbox], outputs=[output_table, download_button])
|
89 |
-
|
90 |
-
demo.launch()
|
|
|
1 |
+
import os
|
2 |
import pandas as pd
|
3 |
from itertools import combinations
|
4 |
from copy import deepcopy
|
5 |
+
import streamlit as st
|
6 |
|
7 |
+
st.set_page_config(page_title="250 Captain–Vice-Captain Generator", layout="wide")
|
8 |
+
st.title("🏏 Generate All 250 Captain–Vice-Captain Combinations")
|
9 |
+
|
10 |
+
# Default file option
|
11 |
+
default_path = "default.xlsx"
|
12 |
+
use_default = False
|
13 |
+
|
14 |
+
if os.path.exists(default_path):
|
15 |
+
use_default = st.checkbox("✅ Use saved default file (default.xlsx)?")
|
16 |
|
17 |
+
uploaded_file = None
|
18 |
+
if not use_default:
|
19 |
+
uploaded_file = st.file_uploader("📤 Upload Excel File", type=["xlsx"])
|
20 |
+
|
21 |
+
if use_default or uploaded_file is not None:
|
22 |
+
try:
|
23 |
# Read Excel
|
24 |
+
df = pd.read_excel(default_path) if use_default else pd.read_excel(uploaded_file)
|
25 |
|
26 |
+
st.subheader("📄 Uploaded Excel File Preview")
|
27 |
+
st.dataframe(df)
|
28 |
+
|
29 |
+
# Extract team names from columns A & B
|
30 |
team_a_names = df.iloc[:, 0].dropna().tolist()
|
31 |
team_b_names = df.iloc[:, 1].dropna().tolist()
|
32 |
|
33 |
team_a = [{"name": str(name).strip()} for name in team_a_names]
|
34 |
team_b = [{"name": str(name).strip()} for name in team_b_names]
|
35 |
|
36 |
+
# Confirm teams
|
37 |
+
st.write("🔵 **Team A:**", team_a_names)
|
38 |
+
st.write("🟢 **Team B:**", team_b_names)
|
39 |
+
|
40 |
+
# Generate all 25 teams by swapping 1 player
|
41 |
all_teams = []
|
42 |
+
team_number = 1
|
43 |
+
|
44 |
+
for i in range(5): # index in Team A to swap
|
45 |
+
for j in range(5): # index from Team B
|
46 |
new_team = deepcopy(team_a)
|
47 |
+
new_team[i] = deepcopy(team_b[j]) # swap one player
|
48 |
all_teams.append({
|
49 |
+
"Team Name": f"Team {team_number}",
|
50 |
"Players": new_team
|
51 |
})
|
52 |
+
team_number += 1
|
53 |
|
54 |
+
# Generate all 250 combinations (10 per team)
|
55 |
full_team_list = []
|
56 |
team_output_counter = 1
|
57 |
+
|
58 |
for team in all_teams:
|
59 |
player_list = team["Players"]
|
60 |
team_name = team["Team Name"]
|
61 |
+
|
62 |
+
# All C–VC pairs from 5 players
|
63 |
cvc_combos = list(combinations(player_list, 2))
|
64 |
|
65 |
for cap, vc in cvc_combos:
|
|
|
76 |
"Player": member['name'],
|
77 |
"Role": role
|
78 |
})
|
79 |
+
|
80 |
full_team_list.extend(team_rows)
|
81 |
team_output_counter += 1
|
82 |
|
83 |
+
# Create DataFrame
|
84 |
final_df = pd.DataFrame(full_team_list)
|
85 |
|
86 |
+
st.subheader("📋 All 250 Captain–Vice-Captain Combinations")
|
87 |
+
st.dataframe(final_df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
+
# Download button
|
90 |
+
csv = final_df.to_csv(index=False).encode("utf-8")
|
91 |
+
st.download_button(
|
92 |
+
label="📥 Download CSV",
|
93 |
+
data=csv,
|
94 |
+
file_name="250_captain_vc_teams.csv",
|
95 |
+
mime="text/csv"
|
96 |
+
)
|
97 |
|
98 |
+
st.success(f"✅ Total Unique Team Combinations Generated: {team_output_counter - 1}")
|
99 |
|
100 |
+
except Exception as e:
|
101 |
+
st.error(f"❌ Error occurred: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|