Mattral commited on
Commit
08dd78a
Β·
verified Β·
1 Parent(s): 4eea4b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py CHANGED
@@ -4,6 +4,46 @@ from PIL import Image
4
  from tensorflow.keras.models import load_model
5
  from streamlit_drawable_canvas import st_canvas
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  # Function to preprocess the image
8
  def preprocess_image(image, target_size):
9
  if image.mode != "RGB":
 
4
  from tensorflow.keras.models import load_model
5
  from streamlit_drawable_canvas import st_canvas
6
 
7
+ ms = st.session_state
8
+ if "themes" not in ms:
9
+ ms.themes = {"current_theme": "light",
10
+ "refreshed": True,
11
+
12
+ "light": {"theme.base": "dark",
13
+ "theme.backgroundColor": "black",
14
+ "theme.primaryColor": "#c98bdb",
15
+ "theme.secondaryBackgroundColor": "#5591f5",
16
+ "theme.textColor": "white",
17
+ "theme.textColor": "white",
18
+ "button_face": "🌜"},
19
+
20
+ "dark": {"theme.base": "light",
21
+ "theme.backgroundColor": "white",
22
+ "theme.primaryColor": "#5591f5",
23
+ "theme.secondaryBackgroundColor": "#82E1D7",
24
+ "theme.textColor": "#0a1464",
25
+ "button_face": "🌞"},
26
+ }
27
+
28
+
29
+ def ChangeTheme():
30
+ previous_theme = ms.themes["current_theme"]
31
+ tdict = ms.themes["light"] if ms.themes["current_theme"] == "light" else ms.themes["dark"]
32
+ for vkey, vval in tdict.items():
33
+ if vkey.startswith("theme"): st._config.set_option(vkey, vval)
34
+
35
+ ms.themes["refreshed"] = False
36
+ if previous_theme == "dark": ms.themes["current_theme"] = "light"
37
+ elif previous_theme == "light": ms.themes["current_theme"] = "dark"
38
+
39
+
40
+ btn_face = ms.themes["light"]["button_face"] if ms.themes["current_theme"] == "light" else ms.themes["dark"]["button_face"]
41
+ st.button(btn_face, on_click=ChangeTheme)
42
+
43
+ if ms.themes["refreshed"] == False:
44
+ ms.themes["refreshed"] = True
45
+ st.rerun()
46
+
47
  # Function to preprocess the image
48
  def preprocess_image(image, target_size):
49
  if image.mode != "RGB":