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