darwinharianto commited on
Commit
912a5ea
·
1 Parent(s): 35a4ed7

added japanese

Browse files
Files changed (1) hide show
  1. app.py +51 -27
app.py CHANGED
@@ -9,7 +9,19 @@ from flow_game_solver import (
9
  initiate_model_with_param,
10
  solve_model,
11
  )
 
12
 
 
 
 
 
 
 
 
 
 
 
 
13
  # use canvas for user input, read the input, and connect those dots!!
14
 
15
 
@@ -56,20 +68,20 @@ def draw_grid(img: Image, columns: int, rows: int):
56
  return img
57
 
58
 
59
- st.title("Connect the dots")
60
 
61
  WIDTH = 300
62
  HEIGHT = 300
63
 
64
  col1, col2, col3 = st.columns(3)
65
  with col1:
66
- COLUMNS = st.number_input("Columns", min_value=1, max_value=100, value=3)
67
  with col2:
68
- ROWS = st.number_input("Rows", min_value=1, max_value=100, value=3)
69
  with col3:
70
- fill = st.slider("Fill", min_value=0.0, max_value=1.0, value=1.0)
71
  waitLimit = st.number_input(
72
- "Max wait time in seconds", value=1, min_value=1, max_value=100
73
  )
74
 
75
  bg_image = Image.fromarray((np.ones((HEIGHT, WIDTH, 3)) * 0).astype(np.uint8))
@@ -78,30 +90,42 @@ bg_image = Image.fromarray((np.ones((HEIGHT, WIDTH, 3)) * 0).astype(np.uint8))
78
  bg_image = draw_grid(bg_image, COLUMNS, ROWS)
79
  # draw.line((0, 0, 100, 100), fill=128)
80
 
81
- stroke_color = st.color_picker("Point Color: ", "#eab")
82
  # Create a canvas component
83
- canvas_result = st_canvas(
84
- # fill_color="rgba(255, 165, 0, 0.3)", # Fixed fill color with some opacity
85
- fill_color=stroke_color, # Fixed fill color with some opacity
86
- stroke_width=5,
87
- stroke_color=stroke_color,
88
- background_color="#fff",
89
- background_image=bg_image,
90
- update_streamlit=True,
91
- height=HEIGHT,
92
- width=WIDTH,
93
- drawing_mode="point",
94
- point_display_radius=min(WIDTH / COLUMNS, HEIGHT / ROWS) / 3,
95
- key="canvas",
96
- )
97
- st.info("""
98
- Click on the board to add pair of color source(s).
99
- Change color for different source(s).
100
- Use White color for unpassable path.
101
- """)
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
 
104
- clicked = st.button("Show result")
105
 
106
 
107
  if clicked:
@@ -142,5 +166,5 @@ if clicked:
142
  if ax is not None:
143
  st.pyplot(ax.get_figure())
144
  else:
145
- st.error("Solution does not exist")
146
  # connect dots using or tools
 
9
  initiate_model_with_param,
10
  solve_model,
11
  )
12
+ from enum import Enum
13
 
14
+ class Language(Enum):
15
+ English = 1
16
+ Japanese = 2
17
+
18
+ if 'language' not in st.session_state:
19
+ st.session_state['language'] = Language.English
20
+ _, col2 = st.columns([5,1])
21
+
22
+ with col2:
23
+ language = st.selectbox("Language" if st.session_state['language'] == Language.English else "言語", ("English", "日本語"))
24
+ st.session_state['language'] = Language.English if language == "English" else Language.Japanese
25
  # use canvas for user input, read the input, and connect those dots!!
26
 
27
 
 
68
  return img
69
 
70
 
71
+ st.title("Connect the dots" if st.session_state['language'] == Language.English else "ドットを繋ごう")
72
 
73
  WIDTH = 300
74
  HEIGHT = 300
75
 
76
  col1, col2, col3 = st.columns(3)
77
  with col1:
78
+ COLUMNS = st.number_input("Columns" if st.session_state['language'] == Language.English else "列数", min_value=1, max_value=100, value=3)
79
  with col2:
80
+ ROWS = st.number_input("Rows" if st.session_state['language'] == Language.English else "行数", min_value=1, max_value=100, value=3)
81
  with col3:
82
+ fill = st.slider("Minimum Fill" if st.session_state['language'] == Language.English else "最低埋める率", min_value=0.0, max_value=1.0, value=1.0)
83
  waitLimit = st.number_input(
84
+ "Max wait time in seconds" if st.session_state['language'] == Language.English else "最大待つ秒数", value=1, min_value=1, max_value=100
85
  )
86
 
87
  bg_image = Image.fromarray((np.ones((HEIGHT, WIDTH, 3)) * 0).astype(np.uint8))
 
90
  bg_image = draw_grid(bg_image, COLUMNS, ROWS)
91
  # draw.line((0, 0, 100, 100), fill=128)
92
 
93
+ stroke_color = st.color_picker("Point Color: " if st.session_state['language'] == Language.English else "色", "#eab")
94
  # Create a canvas component
95
+ col1, col2 = st.columns(2)
96
+
97
+ with col1:
98
+ canvas_result = st_canvas(
99
+ # fill_color="rgba(255, 165, 0, 0.3)", # Fixed fill color with some opacity
100
+ fill_color=stroke_color, # Fixed fill color with some opacity
101
+ stroke_width=5,
102
+ stroke_color=stroke_color,
103
+ background_color="#fff",
104
+ background_image=bg_image,
105
+ update_streamlit=True,
106
+ height=HEIGHT,
107
+ width=WIDTH,
108
+ drawing_mode="point",
109
+ point_display_radius=min(WIDTH / COLUMNS, HEIGHT / ROWS) / 3,
110
+ key="canvas",
111
+ )
112
+ with col2:
113
+ st.info("""
114
+ Click on the board to add pair of color source(s).
115
+ Change color for different source(s).
116
+ Use White color for unpassable path.
117
+ Results is shown below.
118
+ """
119
+ if st.session_state['language'] == Language.English else
120
+ """
121
+ ボードをクリックして、カラー ソースのペアを追加します。
122
+ ソースごとに色を変更して、
123
+ 通行できないパスには白色を使用してお願いします。
124
+ 結果は下にあります。
125
+ """)
126
 
127
 
128
+ clicked = st.button("Show result" if st.session_state['language'] == Language.English else "結果表示")
129
 
130
 
131
  if clicked:
 
166
  if ax is not None:
167
  st.pyplot(ax.get_figure())
168
  else:
169
+ st.error("Solution does not exist" if st.session_state['language'] == Language.English else "解が見つからない")
170
  # connect dots using or tools