Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,101 @@
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import firebase_admin
|
| 2 |
+
from firebase_admin import credentials, firestore, auth
|
| 3 |
import streamlit as st
|
| 4 |
+
import requests
|
| 5 |
+
import pandas as pd
|
| 6 |
+
from datetime import datetime
|
| 7 |
|
| 8 |
+
# Initialize Firebase app
|
| 9 |
+
if not firebase_admin._apps:
|
| 10 |
+
cred = credentials.Certificate("healthtrackapp-d4fd4-firebase-adminsdk-98hh7-fa007df972.json")
|
| 11 |
+
firebase_admin.initialize_app(cred)
|
| 12 |
+
|
| 13 |
+
db = firestore.client()
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# Function to fetch user profile from Firebase
|
| 17 |
+
def fetch_user_profile_from_firebase(user_id):
|
| 18 |
+
user_profile_ref = db.collection("users").document(user_id)
|
| 19 |
+
user_profile = user_profile_ref.get().to_dict()
|
| 20 |
+
return user_profile
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# Function for user authentication
|
| 24 |
+
def user_authentication():
|
| 25 |
+
# Add image and title
|
| 26 |
+
st.image("ecomp.png", width=200)
|
| 27 |
+
st.title("E-Complaint")
|
| 28 |
+
|
| 29 |
+
st.header("User Authentication")
|
| 30 |
+
|
| 31 |
+
# Ask the user if they are new users or already have an account
|
| 32 |
+
user_type = st.radio("Admin", ("Admin"))
|
| 33 |
+
|
| 34 |
+
if user_type == "Admin":
|
| 35 |
+
# If the user is an existing user, prompt for email and password
|
| 36 |
+
email = st.text_input("Email")
|
| 37 |
+
password = st.text_input("Password", type="password")
|
| 38 |
+
if st.button("Sign In"):
|
| 39 |
+
try:
|
| 40 |
+
user = auth.get_user_by_email(email)
|
| 41 |
+
st.success(f"Welcome back, {user.email}!")
|
| 42 |
+
user_id = user.uid
|
| 43 |
+
st.session_state.user_id = user_id
|
| 44 |
+
st.experimental_rerun()
|
| 45 |
+
except auth.UserNotFoundError:
|
| 46 |
+
st.error("User not found. Please check your credentials or sign up.")
|
| 47 |
+
except Exception as e:
|
| 48 |
+
st.error(f"Error during sign-in: {e}")
|
| 49 |
+
else:
|
| 50 |
+
st.error(f"Error during sign-in")
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
# Main Streamlit app
|
| 61 |
+
def main():
|
| 62 |
+
if "user_id" not in st.session_state:
|
| 63 |
+
user_authentication()
|
| 64 |
+
return
|
| 65 |
+
|
| 66 |
+
st.set_page_config(page_title="E Complaint", layout="wide")
|
| 67 |
+
st.title("E-Complaint")
|
| 68 |
+
|
| 69 |
+
user_id = st.session_state.user_id
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
# Sidebar
|
| 75 |
+
st.sidebar.title("E-complaint")
|
| 76 |
+
st.sidebar.image("health.png", use_column_width=True)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
st.sidebar.subheader("Technology Stack")
|
| 81 |
+
|
| 82 |
+
st.sidebar.markdown("""
|
| 83 |
+
streamlit!!!!
|
| 84 |
+
""")
|
| 85 |
+
|
| 86 |
+
st.sidebar.subheader("Architecture and Design")
|
| 87 |
+
|
| 88 |
+
st.sidebar.markdown("""
|
| 89 |
+
loggd in
|
| 90 |
+
""")
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
# Display weekly and monthly summaries
|
| 94 |
+
st.header("Weekly and Monthly Trends")
|
| 95 |
+
|
| 96 |
+
if st.button("Logout", key="logout_button"):
|
| 97 |
+
del st.session_state["user_id"]
|
| 98 |
+
st.experimental_rerun()
|
| 99 |
+
|
| 100 |
+
if __name__ == "__main__":
|
| 101 |
+
main()
|