Yoann commited on
Commit
963fdfb
1 Parent(s): 623ba43

Added 'Easy' difficulty mode

Browse files
__pycache__/game.cpython-39.pyc CHANGED
Binary files a/__pycache__/game.cpython-39.pyc and b/__pycache__/game.cpython-39.pyc differ
 
__pycache__/sentence.cpython-39.pyc CHANGED
Binary files a/__pycache__/sentence.cpython-39.pyc and b/__pycache__/sentence.cpython-39.pyc differ
 
__pycache__/words.cpython-39.pyc CHANGED
Binary files a/__pycache__/words.cpython-39.pyc and b/__pycache__/words.cpython-39.pyc differ
 
app.py CHANGED
@@ -9,7 +9,7 @@ from sentence import *
9
  from game import *
10
 
11
  ##### Initialize new game
12
- title, _,_,var_dict = new_game(first_game=True)
13
  var_dict["start_time"] = -1
14
 
15
  ##### Display & Events
@@ -27,7 +27,10 @@ with demo:
27
  html_pred = gr.HTML(value=getHTML(var_dict,""))
28
  html_loading = gr.HTML("")
29
  ### 'New Sentence' Button
30
- button = gr.Button("New Sentence",variant="primary")
 
 
 
31
  ### Informations
32
  gr.HTML("<div style=\"display:block; height:30px;\"> </div>")
33
  with gr.Row():
@@ -35,8 +38,9 @@ with demo:
35
 
36
 
37
  ### Events
38
- button.click(loading,inputs=html_loading,outputs=[title,html_pred,html_loading]) # Button -> triggers Loading
39
- html_loading.change(new_game,inputs=[html_loading],outputs=[title,html_pred,image_input,variables]) # Loading -> triggers New game
 
40
  image_input.change(process_img, inputs=[variables,image_input,title], outputs=[html_pred,title,variables])
41
 
42
 
 
9
  from game import *
10
 
11
  ##### Initialize new game
12
+ title, _,_,var_dict = new_game(None, None, first_game=True)
13
  var_dict["start_time"] = -1
14
 
15
  ##### Display & Events
 
27
  html_pred = gr.HTML(value=getHTML(var_dict,""))
28
  html_loading = gr.HTML("")
29
  ### 'New Sentence' Button
30
+ with gr.Row():
31
+ button_new = gr.Button("New Sentence",variant="primary")
32
+ button_mode = gr.Button("Switch Difficulty")
33
+ block = gr.HTML("<div style=\"width:50vw;\"> </div>")
34
  ### Informations
35
  gr.HTML("<div style=\"display:block; height:30px;\"> </div>")
36
  with gr.Row():
 
38
 
39
 
40
  ### Events
41
+ button_mode.click(switch_difficulty,inputs=[variables,html_loading],outputs=[variables,title,html_pred,html_loading])
42
+ button_new.click(loading,inputs=html_loading,outputs=[title,html_pred,html_loading]) # Button -> triggers Loading
43
+ html_loading.change(new_game,inputs=[variables,html_loading],outputs=[title,html_pred,image_input,variables]) # Loading -> triggers New game
44
  image_input.change(process_img, inputs=[variables,image_input,title], outputs=[html_pred,title,variables])
45
 
46
 
game.py CHANGED
@@ -11,6 +11,14 @@ with open("infos.txt") as file:
11
  with open("style.css") as style:
12
  css = "<style>"+ ''.join(style.readlines())+"</style>"
13
 
 
 
 
 
 
 
 
 
14
  ##### 'LOADING' EVENT
15
  def loading(html_loading=None):
16
  ### This is just to make sure the content changes, which triggers the .change event which, itself, will launch a new game
@@ -22,8 +30,12 @@ def loading(html_loading=None):
22
  return "<h1 id=\"loading\">⌛Loading...</h1>",css+"<div id=\"prediction\"><p id=\"infos\">"+info+"</p></div>",new_value
23
 
24
  ##### 'NEW GAME' EVENT
25
- def new_game(img=None,first_game=False):
26
  print("\n----------Launching new game!")
 
 
 
 
27
  var_dict = {
28
  "start_time": time.time(),
29
  "total_time": 0,
@@ -37,7 +49,8 @@ def new_game(img=None,first_game=False):
37
  "prev_norm": float("inf"),
38
  "tip": "",
39
  "loading": False,
40
- "revertedState": False
 
41
  }
42
  target = iniSentence(var_dict,first_game=first_game)
43
  ### Return TITLE, PREDICTION TEXT, CANVAS IMG, VAR DICT
 
11
  with open("style.css") as style:
12
  css = "<style>"+ ''.join(style.readlines())+"</style>"
13
 
14
+ ##### 'DIFFICULTY SWITCH' EVENT
15
+ def switch_difficulty(var_dict, html_loading):
16
+
17
+ var_dict["difficulty"] = 1 - var_dict["difficulty"]
18
+
19
+ title, infos, new_value = loading(html_loading)
20
+ return var_dict, title, infos, new_value
21
+
22
  ##### 'LOADING' EVENT
23
  def loading(html_loading=None):
24
  ### This is just to make sure the content changes, which triggers the .change event which, itself, will launch a new game
 
30
  return "<h1 id=\"loading\">⌛Loading...</h1>",css+"<div id=\"prediction\"><p id=\"infos\">"+info+"</p></div>",new_value
31
 
32
  ##### 'NEW GAME' EVENT
33
+ def new_game(var_dict,img=None,first_game=False):
34
  print("\n----------Launching new game!")
35
+
36
+ if None is not var_dict: difficulty = var_dict["difficulty"]
37
+ else: difficulty = 1
38
+
39
  var_dict = {
40
  "start_time": time.time(),
41
  "total_time": 0,
 
49
  "prev_norm": float("inf"),
50
  "tip": "",
51
  "loading": False,
52
+ "revertedState": False,
53
+ "difficulty": difficulty
54
  }
55
  target = iniSentence(var_dict,first_game=first_game)
56
  ### Return TITLE, PREDICTION TEXT, CANVAS IMG, VAR DICT
sentence.py CHANGED
@@ -40,7 +40,7 @@ def iniSentence(var_dict,input="",first_game=False):
40
  var_dict["parts"] = []
41
  var_dict["step"] = 0
42
  prefix = ""
43
- N = 2
44
 
45
  if first_game:
46
  link = "a drawing of a"
 
40
  var_dict["parts"] = []
41
  var_dict["step"] = 0
42
  prefix = ""
43
+ N = (2 if var_dict["difficulty"] == 1 else 1)
44
 
45
  if first_game:
46
  link = "a drawing of a"
words.py CHANGED
@@ -2,9 +2,9 @@
2
  # A DRAWING OF A ...
3
  shapes = ["triangle","square","circle","heart","star","diamond"]
4
  animals = ["cat","dog","duck","bee","butterfly","bird","pig","cow","fish","frog","shark","snake","mouse","monkey","snail"]
5
- objects = ["wine glass","eye","plane","spoon","basket ball","chair","pen","computer","hat","soccer ball","phone","sword","axe","umbrella","bell","dumbbell","scissors","fork","bag","clock","key","shopping cart","car","boat","house","mug","sun","moon","atom","hand"]
6
  plants = ["tree","flower","leaf","palm tree","mushroom"] # I know that mushrooms are not plants stop coming to my house
7
- food = ["donut","coconut","banana","apple","bottle","sausage","icecream","burger","egg","lollypop","pizza"]
8
  instruments = ["drum","guitar","piano","flute","trumpet","accordion"]
9
 
10
  # FEELING ...
 
2
  # A DRAWING OF A ...
3
  shapes = ["triangle","square","circle","heart","star","diamond"]
4
  animals = ["cat","dog","duck","bee","butterfly","bird","pig","cow","fish","frog","shark","snake","mouse","monkey","snail"]
5
+ objects = ["bottle","wine glass","plane","spoon","basket ball","chair","pen","computer","hat","soccer ball","phone","sword","axe","umbrella","bell","dumbbell","scissors","fork","bag","clock","key","shopping cart","car","boat","house","mug","sun","moon","atom","hand"]
6
  plants = ["tree","flower","leaf","palm tree","mushroom"] # I know that mushrooms are not plants stop coming to my house
7
+ food = ["donut","coconut","banana","apple","sausage","icecream","burger","egg","pizza"]
8
  instruments = ["drum","guitar","piano","flute","trumpet","accordion"]
9
 
10
  # FEELING ...