42
42
if "image" not in st .session_state :
43
43
st .session_state .image = "https://f8n-production.s3.us-east-2.amazonaws.com/collections/awzn1l17u-beach%20relax-export.gif"
44
44
45
+ if "selected_video" not in st .session_state :
46
+ st .session_state .selected_video = ("None" ,"" )
47
+
48
+
49
+ if "videos" not in st .session_state :
50
+ st .session_state .videos = {
51
+ "None" :"" ,
52
+ "Pokemon" : "YMEblRM4pGc" ,
53
+ "Minecraft" : "0KvlwMd3C4Y" ,
54
+ "Lofi Girl" : "BTYAsjAVa3I" ,
55
+ "Upbeat Classical" : "mv5SZ7i6QLI" ,
56
+ "Classical Music" :"jgpJVI3tDbY" ,
57
+ "Upbeat Study" :"xcwA5h85AvA" ,
58
+ "Soft Techno" :"7j0yL8A-k4E" ,
59
+ "8D Binaural" :"n0SpKMnkPec" ,
60
+ "Input youtube link" :""
61
+ }
62
+
63
+
45
64
#function to change format from printable to executable
46
65
def format_funct (val ):
47
66
i = st .session_state .timezones .index (val )
@@ -53,6 +72,14 @@ def get_index(val):
53
72
def get_image_data_url (img_bytes ):
54
73
encoded = base64 .b64encode (img_bytes ).decode ()
55
74
return f"data:image/png;base64,{ encoded } "
75
+
76
+ def extract_youtube_id (url ):
77
+ start = url .find ("?v=" ) + 3
78
+ end = url .find ("&" , start )
79
+ if end == - 1 :
80
+ end = len (url )
81
+ return url [start :end ]
82
+
56
83
#save timezone value:
57
84
st .session_state .timezone = st .selectbox ("Select Timezone:" , st .session_state .timezones , index = get_index (st .session_state .timezone ), format_func = format_funct , placeholder = "Europe: Italy" )
58
85
@@ -63,4 +90,28 @@ def get_image_data_url(img_bytes):
63
90
64
91
uploaded_file = st .file_uploader ("Choose an image..." , type = ["png" , "jpg" , "jpeg" , "gif" ])
65
92
if uploaded_file is not None :
66
- st .session_state .image = get_image_data_url (uploaded_file .read ())
93
+ st .session_state .image = get_image_data_url (uploaded_file .read ())
94
+
95
+
96
+
97
+
98
+ list_keys = list (st .session_state .videos .keys ())#easy way to get all names of choices
99
+ sel_obj = st .session_state .selected_video [0 ]#extract the current name
100
+ col1 , col2 = st .columns (2 )
101
+ with col1 :
102
+ st .markdown ("""<div style="display:flex; font-size: 30px; justify-content:center; align-items:center; font-weight: bold; color: "white";">
103
+ Beats🎶
104
+ </div>""" ,unsafe_allow_html = True )
105
+ key = st .selectbox ("select ambient music" , list_keys , index = list_keys .index (sel_obj ), label_visibility = "collapsed" )
106
+
107
+ if key == "Input youtube link" :
108
+ text = st .text_input ("input link:" , placeholder = "https://www.youtube.com/watch?v=jNQXAC9IVRw" )
109
+ text = extract_youtube_id (text )
110
+ if len (text ) != 11 :
111
+ st .toast ("Please input a valid youtube link" )
112
+ else :
113
+ st .session_state .videos [key ]= text
114
+ st .toast ("Youtube link accepted!" )
115
+
116
+
117
+ st .session_state .selected_video = (key ,st .session_state .videos [key ])
0 commit comments