Navpreet/Rabbit
0
1import streamlit as st2import pyrebase3from datetime import datetime4from streamlit_option_menu import option_menu5from PIL import Image6import requests7 8 9#streamlit-1.16.010 11 12im = Image.open("icons8-rabbit-100.png")13st.set_page_config(14 page_title="Rabbit.web",15 page_icon=im16 17)18 19 20 21 22def add_bg_from_url():23 st.markdown(24 f"""25 <style>26 .stApp {{27 background-image: url("https://images.squarespace-cdn.com/content/v1/5fe4caeadae61a2f19719512/1609537599282-NP1M5U8V0U0NDWQY9QRR/Starfield");28 background-attachment: fixed;29 background-size: cover30 }}31 </style>32 """,33 unsafe_allow_html=True34 )35 36add_bg_from_url()37 38hide_streamlit_style = """39 <style>40 #MainMenu {visibility: hidden;}41 footer {visibility: hidden;}42 </style>43 """44st.markdown(hide_streamlit_style, unsafe_allow_html=True)45 46firebaseConfig = {47 "apiKey": "AIzaSyDTY8XA0vTApBwTVurob82FFUOMBkWzg-w",48 "authDomain": "none-d12f3.firebaseapp.com",49 "projectId": "none-d12f3",50 "storageBucket": "none-d12f3.appspot.com",51 "databaseURL":"https://none-d12f3-default-rtdb.firebaseio.com/",52 "messagingSenderId": "300216235483",53 "appId": "1:300216235483:web:cf88ae462225f8ce16e3fe",54 "measurementId": "G-MLZN385TMD"55};56 57firebase=pyrebase.initialize_app(firebaseConfig)58auth=firebase.auth()59 60data=firebase.database()61storage=firebase.storage()62 63st.markdown("<center><img src=https://img.icons8.com/ios-filled/100/228BE6/rabbit.png; alt=centered image; height=100; width=100> </center>",unsafe_allow_html=True)64labela=("<h1 style='font-family:arial;color:#228BE6;text-align:center'>Rabbit.web</h1>")65st.markdown(labela,unsafe_allow_html=True)66streamlit_style = """67 <style>68 @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap');69 70 html, body, [class*="css"] {71 font-family: 'Roboto', sans-serif;72 }73 </style>74 """75st.markdown(streamlit_style, unsafe_allow_html=True)76streamlitstyle = """77 <style>78 @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap');79 80 html, body, [class*="css"] {81 font-family: 'Roboto', sans-serif;82 }83 </style>84 """85st.sidebar.markdown(streamlitstyle, unsafe_allow_html=True)86st.sidebar.markdown("<center><img src=https://img.icons8.com/ios-filled/100/228BE6/rabbit.png ; alt=centered image; height=100; width=100> </center>",unsafe_allow_html=True)87 88 89 90label=("<h1 style='font-family:arial;color:#228BE6;text-align:center'>Rabbit.web</h1>")91st.sidebar.markdown(label,unsafe_allow_html=True)92 93labelb=("<h4 style='font-family:arial;color:#228BE6;text-align:center'>A perfect place to chat with your friend's</h4>")94st.sidebar.markdown(labelb,unsafe_allow_html=True)95 96choice=st.sidebar.selectbox("Sign in to your account or create an account :",["sign in","create an account"])97 98 99 100email=st.sidebar.text_input("",placeholder="Hello please enter you email")101passw=st.sidebar.text_input("",placeholder="Hello please enter your password",type="password")102 103 104 105if choice=="create an account":106 handle=st.sidebar.text_input("",placeholder="Hello please enter your name")107 subbt=st.sidebar.button("Create an new account")108 109 if subbt:110 user=auth.create_user_with_email_and_password(email,passw)111 st.success("Your Rabbit.web account has created successfully !")112 113 user=auth.sign_in_with_email_and_password(email,passw)114 data.child(user["localId"]).child("Handle").set(handle)115 data.child(user["localId"]).child("ID").set(user["localId"])116 st.info("You have successfully logged in")117 118 119 120 121 122if choice=="sign in":123 124 signin=st.sidebar.checkbox("sign in")125 126 127 if signin:128 user=auth.sign_in_with_email_and_password(email,passw)129 130 131 nav = option_menu(menu_title=None, options=["Home", "Posts", "Settings","About us"],icons=["house", "book", "gear","info"],menu_icon="cast",default_index=0,orientation="verticle",styles={132 "container": {"padding": "0!important", "background-color": "#1c1c1c"},133 "icon": {"color": "lightblue", "font-size": "20px"}, 134 "nav-link": {"text-align":"left", "margin":"0px", "--hover-color": "#1c1c1c"},135 "nav-link-selected": {"background-color": "#228BE6","color":"#1c1c1c"},})136 137 if nav =="Home":138 139 post=st.text_input("",placeholder="share your thought with your friend's",max_chars=250)140 add_post=st.button("Share your thought")141 142 143 144 if add_post:145 now=datetime.now()146 dt=now.strftime("%d / %m / %y")147 dtt=now.strftime("%I:%M %p")148 149 post="Post: "+post+ ";"+" Posted on:"+ dt +" at "+dtt150 results=data.child(user["localId"]).child("Posts").push(post)151 st.balloons()152 components.html("""<hr style="height:2px;border:none;color:#333;background-color:white;" /> """)153 col1,col2=st.columns(2)154 155 with col1:156 nimg=data.child(user["localId"]).child("Image").get().val()157 if nimg is not None:158 v=data.child(user["localId"]).child("Image").get()159 for img in v.each():160 imgc=img.val()161 st.image(imgc,use_column_width=True)162 163 else:164 st.info("Oop's no profile pic till now ")165 166 167 168 with col2:169 st.title("Post's :")170 all_posts=data.child(user['localId']).child("Posts").get()171 172 if all_posts.val() is not None:173 for Posts in reversed(all_posts.each()):174 st.success(Posts.val())175 176 else:177 st.info("Oop's no thought till now")178 col3=st.columns(1)179 with col1:180 st.title("Bio :")181 all_bio=data.child(user["localId"]).child("Bio").get()182 183 if all_bio.val() is not None:184 185 bio=data.child(user["localId"]).child("Bio").get()186 for bio in bio.each():187 bioc=bio.val()188 st.info(bioc)189 else:190 st.info("Oop's no Bio till now")191 192 193 elif nav =="Settings":194 nimg=data.child(user["localId"]).child("Image").get().val()195 if nimg is not None:196 Image=data.child(user["localId"]).child("Image").get()197 for img in Image.each():198 imgc=img.val()199 st.image(imgc)200 201 expa=st.expander("Change your profile pic")202 203 with expa:204 newimgp=st.file_uploader("Please choose your profile pic")205 upbt=st.button("Upload profile pic")206 if upbt:207 uid=user["localId"]208 dataup=storage.child(uid).put(newimgp,user["idToken"])209 aimgdata=storage.child(uid).get_url(dataup["downloadTokens"])210 211 data.child(user["localId"]).child("Image").push(aimgdata)212 213 st.info("Your profile pic is set successfully")214 st.balloons()215 else:216 st.info("Oop's no profile pic till now")217 newimgp=st.file_uploader("Please choose your profile pic")218 upbt=st.button("Upload profile pic")219 if upbt:220 uid=user["localId"]221 dataup=storage.child(uid).put(newimgp,user["idToken"])222 aimgdata=storage.child(uid).get_url(dataup["downloadTokens"])223 data.child(user["localId"]).child("Image").push(aimgdata)224 225 bio=data.child(user["localId"]).child("Bio").get().val()226 if bio is not None:227 bio=data.child(user["localId"]).child("Bio").get()228 for bio in bio.each():229 bioc=bio.val()230 st.info(bioc)231 232 bioin=st.text_area("",placeholder="Enter your Bio to be uploaded eg: name,date of birth etc")233 upbtn=st.button("Upload Bio")234 235 if upbtn:236 237 238 239 data.child(user["localId"]).child("Bio").push(bioin)240 241 st.info("Your Bio is set successfully")242 st.balloons()243 else:244 st.info("Oop's no Bio till now")245 bioin=st.text_area("",placeholder="Enter your Bio to be uploaded eg: name,date of birth etc")246 upbtn=st.button("Upload Bio")247 248 if upbtn:249 250 251 data.child(user["localId"]).child("Bio").push(bioin)252 253 st.info("Your Bio is set successfully")254 st.balloons()255 256 257 elif nav=="Posts":258 allu=data.get()259 resa=[]260 261 for ush in allu.each():262 263 k=ush.val().get("Handle")264 resa.append(k)265 266 n = len(resa)267 268 st.title("Search your Friend's :")269 cho = st.selectbox('',resa)270 pusha = st.button('Show Profile')271 272 if pusha:273 for ush in allu.each():274 k=ush.val().get("Handle")275 if k==cho:276 l=ush.val().get("ID")277 278 hn=data.child(l).child("Handle").get().val()279 280 st.markdown(hn,unsafe_allow_html=True)281 components.html("""<hr style="height:2px;border:none;color:#333;background-color:white;" /> """)282 col1,col2=st.columns(2)283 with col1:284 nimg=data.child(l).child("Image").get().val()285 if nimg is not None:286 v=data.child(l).child("Image").get()287 for img in v.each():288 imgc=img.val()289 st.image(imgc,use_column_width=True)290 291 else:292 st.info("Oop's no profile pic till now ")293 294 295 296 297 with col2:298 st.title("Post's :")299 all_posts=data.child(l).child("Posts").get()300 if all_posts.val() is not None:301 for Posts in reversed(all_posts.each()):302 st.success(Posts.val())303 else:304 st.info("Oop's no thought till now")305 col3=st.columns(1)306 with col1:307 st.title("Bio :")308 all_bio=data.child(l).child("Bio").get()309 310 if all_bio.val() is not None:311 bio=data.child(l).child("Bio").get()312 for bio in bio.each():313 bioc=bio.val()314 st.info(bioc)315 else:316 st.info("Oop's no Bio till now")317 318 else:319 st.write("Rabbit.web")320 st.write("Created and maintained by Navpreet Singh")321 st.write("For help,feedback or suggestion contact our company at rabbitweb854@gmail.com")322 st.write("For reporting a user on Rabbit.web contact us at rabbitweb854@gmail.com")323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 