Spaces:
Runtime error
Runtime error
Commit ·
05371a1
1
Parent(s): a9cb7eb
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,18 +84,27 @@ def main():
|
|
| 84 |
PAYOFF = PRISONERS_DILEMMA_PAYOFF
|
| 85 |
elif game_option == 'Battle of the Sexes':
|
| 86 |
PAYOFF = BATTLE_SEXES_PAYOFF
|
| 87 |
-
|
| 88 |
jj = st.text_input("Enter payoff for (J, J) as 'x,y':")
|
| 89 |
jf = st.text_input("Enter payoff for (J, F) as 'x,y':")
|
| 90 |
fj = st.text_input("Enter payoff for (F, J) as 'x,y':")
|
| 91 |
ff = st.text_input("Enter payoff for (F, F) as 'x,y':")
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
("
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
model_option = st.selectbox(
|
| 101 |
'Which model version would you like to use?',
|
|
@@ -103,20 +112,23 @@ def main():
|
|
| 103 |
)
|
| 104 |
rounds = st.slider('Number of rounds to play', min_value=1, max_value=100, value=10, step=1)
|
| 105 |
|
| 106 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
player1_move = gpt_play(1, i + 1, last_round, model=model_option)
|
| 111 |
-
player2_move = gpt_play(2, i + 1, last_round, model=model_option)
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
|
| 116 |
-
st.write(
|
| 117 |
-
f"Round {i + 1}: Player 1 chose {player1_move} and won {score_p1} points. Player 2 chose {player2_move} and won {score_p2} points.")
|
| 118 |
|
| 119 |
-
st.
|
|
|
|
| 120 |
|
| 121 |
|
| 122 |
if __name__ == "__main__":
|
|
|
|
| 84 |
PAYOFF = PRISONERS_DILEMMA_PAYOFF
|
| 85 |
elif game_option == 'Battle of the Sexes':
|
| 86 |
PAYOFF = BATTLE_SEXES_PAYOFF
|
| 87 |
+
elif game_option == 'Custom Matrix':
|
| 88 |
jj = st.text_input("Enter payoff for (J, J) as 'x,y':")
|
| 89 |
jf = st.text_input("Enter payoff for (J, F) as 'x,y':")
|
| 90 |
fj = st.text_input("Enter payoff for (F, J) as 'x,y':")
|
| 91 |
ff = st.text_input("Enter payoff for (F, F) as 'x,y':")
|
| 92 |
|
| 93 |
+
# Check if all inputs are filled
|
| 94 |
+
if not all([jj, jf, fj, ff]):
|
| 95 |
+
st.warning("Please fill in all the custom matrix values before starting the simulation.")
|
| 96 |
+
return
|
| 97 |
+
|
| 98 |
+
try:
|
| 99 |
+
PAYOFF = {
|
| 100 |
+
("J", "J"): tuple(map(int, jj.split(','))),
|
| 101 |
+
("J", "F"): tuple(map(int, jf.split(','))),
|
| 102 |
+
("F", "J"): tuple(map(int, fj.split(','))),
|
| 103 |
+
("F", "F"): tuple(map(int, ff.split(',')))
|
| 104 |
+
}
|
| 105 |
+
except ValueError:
|
| 106 |
+
st.error("Invalid custom matrix values. Please provide values in the format 'x,y'.")
|
| 107 |
+
return
|
| 108 |
|
| 109 |
model_option = st.selectbox(
|
| 110 |
'Which model version would you like to use?',
|
|
|
|
| 112 |
)
|
| 113 |
rounds = st.slider('Number of rounds to play', min_value=1, max_value=100, value=10, step=1)
|
| 114 |
|
| 115 |
+
if st.button('Start Simulation'):
|
| 116 |
+
st.write(f"Simulating {game_option} for {rounds} rounds using {model_option}.")
|
| 117 |
+
last_round = None
|
| 118 |
+
for i in range(rounds):
|
| 119 |
+
player1_move = gpt_play(1, i + 1, last_round, model=model_option)
|
| 120 |
+
player2_move = gpt_play(2, i + 1, last_round, model=model_option)
|
| 121 |
|
| 122 |
+
last_round = (player1_move, player2_move)
|
| 123 |
+
score_p1, score_p2 = PAYOFF[last_round]
|
|
|
|
|
|
|
| 124 |
|
| 125 |
+
st.write(
|
| 126 |
+
f"Round {i + 1}: Player 1 chose {player1_move} and won {score_p1} points. Player 2 chose {player2_move} and won {score_p2} points.")
|
| 127 |
|
| 128 |
+
st.write("Simulation complete!")
|
|
|
|
| 129 |
|
| 130 |
+
if st.button('Reset'):
|
| 131 |
+
st.experimental_rerun()
|
| 132 |
|
| 133 |
|
| 134 |
if __name__ == "__main__":
|