Skip to content

Commit fff64d3

Browse files
authored
FIX: HTML output error (#1) (#7)
Fix bug
1 parent 8dfda85 commit fff64d3

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import tensorflow as tf
55
import numpy as np
66
import rps_battle
7+
import os
78

89
model = tf.keras.models.load_model('MobileNet_Colab.h5')
9-
class_names = {0: 'paper', 1: 'rock', 2: 'scissor'}
10+
class_names = {0: 'paper', 1: 'rock', 2: 'scissors'}
1011

1112
app = Flask(__name__)
1213

@@ -24,11 +25,10 @@ def index():
2425
f.save(file_path)
2526
probability = ml.rps_predict(file_path, model)
2627
user_str = class_names[np.argmax(probability)]
27-
com, com_path, result = rps_battle.checkWin(np.argmax(probability))
28+
result, com_path, com = rps_battle.checkWin(np.argmax(probability))
2829
com_str = class_names[com]
29-
move = 'Battle'
3030
return render_template("index.html", img=file_path, ret_=user_str, com=com_str, com_path=com_path,
31-
result=result, move=move)
31+
result=result)
3232

3333

3434
if __name__ == "__main__":

rps_battle.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@
22
import os
33

44
sample_path = 'static/cpu'
5-
sample_list = os.listdir(sample_path)
5+
sample_file_list = os.listdir(sample_path)
6+
sample_label_list = list(map(lambda x: x.split('.')[0], sample_file_list))
7+
class_names = {'paper': 0, 'rock': 1, 'scissors': 2}
68

7-
class_names = {0: 'paper', 1: 'rock', 2: 'scissor'}
9+
class_map = list(map(lambda x: class_names[x], sample_label_list))
810
result = {0: 'WIN', 1: 'LOSE', 2: 'DRAW'}
911

1012

1113
def checkWin(user):
12-
cpu = random.randint(0, 2)
13-
cpu_path = sample_path + '/' + sample_list[cpu]
14-
15-
if user == cpu:
14+
random_idx = random.randint(0, 2)
15+
com_path = sample_path + '/' + sample_file_list[random_idx]
16+
com = class_map[random_idx]
17+
if user == com:
1618
state = 2
17-
elif user == 2 and cpu == 1:
19+
elif user == 2 and com == 1:
1820
state = 1
19-
elif user == 1 and cpu == 0:
21+
elif user == 1 and com == 0:
2022
state = 1
21-
elif user == 0 and cpu == 2:
23+
elif user == 0 and com == 2:
2224
state = 1
2325
else:
2426
state = 0
2527

26-
return cpu, cpu_path, result[state]
28+
return result[state], com_path, com
2729

File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)