rianders commited on
Commit
23e82be
·
1 Parent(s): 277eea8

changings for huggingface

Browse files
Files changed (2) hide show
  1. app.py +152 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+ import random
5
+
6
+ # Sample player names
7
+ sample_player_names = ["Alice", "Bob", "Charlie", "Diana", "Ethan", "Fiona", "George", "Hannah", "Ivan", "Julia", "Aisha", "Carlos", "Mei", "Raj", "Lerato", "Dmitry", "Isabella", "Yuto", "Chloe", "Tariq"]
8
+
9
+
10
+ # Generate Fibonacci sequence up to a maximum value
11
+ def generate_fibonacci_sequence(max_value):
12
+ sequence = [0, 1]
13
+ while sequence[-1] + sequence[-2] <= max_value:
14
+ sequence.append(sequence[-1] + sequence[-2])
15
+ return sequence
16
+
17
+ def plot_graph(data, title):
18
+ fig, ax = plt.subplots()
19
+
20
+ # Plotting data points
21
+ for _, row in data.iterrows():
22
+ ax.scatter(x=row['User Value'], y=row['Complexity'], alpha=0.5, label=row['Player']) # Swap X and Y
23
+
24
+ # Setting axis limits
25
+ ax.set_xlim(0, 55)
26
+ ax.set_ylim(0, 55)
27
+
28
+ # Drawing lines for quadrants
29
+ ax.axhline(y=27.5, color='gray', linestyle='--')
30
+ ax.axvline(x=27.5, color='gray', linestyle='--')
31
+
32
+ # Axis labels and title
33
+ ax.set_xlabel("User Value") # Swapped label
34
+ ax.set_ylabel("Complexity") # Swapped label
35
+ ax.set_title(title)
36
+
37
+ # Adding a grid and legend
38
+ ax.legend()
39
+ ax.grid(True)
40
+
41
+ return fig
42
+
43
+
44
+
45
+
46
+
47
+ # Function to display pitch and review for a player
48
+ def display_pitch_and_review(pitcher, player_names, max_fibonacci_value, fibonacci_numbers):
49
+ with st.container():
50
+ # Project Name
51
+ project_key = f'project_{pitcher}'
52
+ if project_key not in st.session_state:
53
+ st.session_state[project_key] = ''
54
+ project_name = st.text_input(f"Project Name by {pitcher}", st.session_state[project_key])
55
+
56
+ # Other players review the pitch
57
+ for reviewer in player_names:
58
+ if reviewer != pitcher:
59
+ st.write(f"{reviewer}'s Review")
60
+
61
+ # Define keys for each input
62
+ complexity_key = f'complexity_{pitcher}_{reviewer}'
63
+ user_value_key = f'user_value_{pitcher}_{reviewer}'
64
+ funding_key = f'funding_{pitcher}_{reviewer}'
65
+
66
+ # Initialize session state variables with randomized default values if not exist
67
+ if complexity_key not in st.session_state:
68
+ st.session_state[complexity_key] = random.choice(fibonacci_numbers)
69
+ if user_value_key not in st.session_state:
70
+ st.session_state[user_value_key] = random.choice(fibonacci_numbers)
71
+ if funding_key not in st.session_state:
72
+ st.session_state[funding_key] = random.choice(fibonacci_numbers)
73
+
74
+ # Sliders with session state
75
+ complexity = st.slider(f"Complexity for {project_name}", 0, max_fibonacci_value, st.session_state[complexity_key], key=complexity_key)
76
+ user_value = st.slider(f"User Value for {project_name}", 0, max_fibonacci_value, st.session_state[user_value_key], key=user_value_key)
77
+ funding_points = st.slider(f"Funding Points for {project_name}", 0, max_fibonacci_value, st.session_state[funding_key], key=funding_key)
78
+
79
+ # Save review data
80
+ new_row = {
81
+ "Player": reviewer,
82
+ "Project": project_name,
83
+ "Complexity": complexity,
84
+ "User Value": user_value,
85
+ "Funding Points": funding_points
86
+ }
87
+ st.session_state['game_data'] = pd.concat([st.session_state['game_data'], pd.DataFrame([new_row])], ignore_index=True)
88
+
89
+ # Function to update game data
90
+ def update_game_data(pitcher, project_name, player_names, max_fibonacci_value):
91
+ for reviewer in player_names:
92
+ if reviewer != pitcher:
93
+ complexity_key = f'complexity_{pitcher}_{reviewer}'
94
+ user_value_key = f'user_value_{pitcher}_{reviewer}'
95
+ funding_key = f'funding_{pitcher}_{reviewer}'
96
+
97
+ new_row = {
98
+ "Player": reviewer,
99
+ "Project": project_name,
100
+ "Complexity": st.session_state[complexity_key],
101
+ "User Value": st.session_state[user_value_key],
102
+ "Funding Points": st.session_state[funding_key]
103
+ }
104
+ st.session_state['game_data'] = pd.concat([st.session_state['game_data'], pd.DataFrame([new_row])], ignore_index=True)
105
+
106
+
107
+ # Initialize Streamlit app
108
+ st.title("Pitch Review Game")
109
+
110
+ # Number of players and their names using the sidebar
111
+ number_of_players = st.sidebar.number_input("Enter number of players", 2, 10, 4)
112
+ player_names = []
113
+ for i in range(number_of_players):
114
+ default_name = random.choice(sample_player_names) # Get a random name
115
+ name = st.sidebar.text_input(f"Name of player {i+1}", value=default_name, key=f'player_{i}')
116
+ player_names.append(name)
117
+
118
+ # Initialize game data if not present
119
+ if 'game_data' not in st.session_state:
120
+ st.session_state['game_data'] = pd.DataFrame(columns=["Player", "Project", "Complexity", "User Value", "Funding Points"])
121
+
122
+ # Fibonacci numbers for scoring
123
+ fibonacci_numbers = generate_fibonacci_sequence(55)
124
+ max_fibonacci_value = max(fibonacci_numbers)
125
+
126
+ # Display pitch and review based on the selected player
127
+ if 'selected_pitcher' in st.session_state and st.session_state['selected_pitcher']:
128
+ display_pitch_and_review(st.session_state['selected_pitcher'], player_names, max_fibonacci_value)
129
+ if st.button("Save Reviews"):
130
+ update_game_data(st.session_state['selected_pitcher'], st.session_state[f'project_{st.session_state["selected_pitcher"]}'], player_names, max_fibonacci_value)
131
+ st.session_state['selected_pitcher'] = None # Reset after saving
132
+
133
+ # Sidebar buttons for each player's pitch
134
+ for pitcher in player_names:
135
+ if st.sidebar.button(f"{pitcher}'s Pitch", key=f'pitch_{pitcher}'):
136
+ st.session_state['selected_pitcher'] = pitcher
137
+
138
+ # Show Results and Restart Game buttons in the sidebar
139
+ if st.sidebar.button("Show Results"):
140
+ st.write(st.session_state['game_data'])
141
+ fig = plot_graph(st.session_state['game_data'], "Project Complexity vs User Value")
142
+ st.pyplot(fig)
143
+
144
+ if st.sidebar.button("Restart Game"):
145
+ st.session_state['game_data'] = pd.DataFrame(columns=["Player", "Project", "Complexity", "User Value", "Funding Points"])
146
+ # Optionally clear all session state
147
+ for key in list(st.session_state.keys()):
148
+ del st.session_state[key]
149
+
150
+ # Ensure all players are named before proceeding
151
+ if not all(player_names):
152
+ st.sidebar.warning("Please enter names for all players.")
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ matplotlib
4
+