Spaces:
No application file
No application file
Upload 12 files
Browse files- .gitattributes +1 -0
- pet/pet/.vscode/settings.json +5 -0
- pet/pet/__pycache__/database.cpython-312.pyc +0 -0
- pet/pet/__pycache__/login.cpython-312.pyc +0 -0
- pet/pet/database.py +33 -0
- pet/pet/login.py +121 -0
- pet/pet/pages/2_Gallery.py +145 -0
- pet/pet/pages/3_adoption_form.py +240 -0
- pet/pet/pages/4_Admin_Dashboard.py +327 -0
- pet/pet/pages/main.py +462 -0
- pet/pet/pet_images/dog-5059910_1280.jpg +3 -0
- pet/pet/utils/__pycache__/mongo_utils.cpython-312.pyc +0 -0
- pet/pet/utils/mongo_utils.py +48 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
pet/pet/pet_images/dog-5059910_1280.jpg filter=lfs diff=lfs merge=lfs -text
|
pet/pet/.vscode/settings.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"python.analysis.extraPaths": [
|
| 3 |
+
"./utils"
|
| 4 |
+
]
|
| 5 |
+
}
|
pet/pet/__pycache__/database.cpython-312.pyc
ADDED
|
Binary file (492 Bytes). View file
|
|
|
pet/pet/__pycache__/login.cpython-312.pyc
ADDED
|
Binary file (2.93 kB). View file
|
|
|
pet/pet/database.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pymongo import MongoClient
|
| 2 |
+
from bson import ObjectId
|
| 3 |
+
from pymongo import MongoClient
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
client = MongoClient("mongodb://localhost:27017/pets")
|
| 7 |
+
db = client["pet_database"]
|
| 8 |
+
users_collection = db["users"]
|
| 9 |
+
pet_collection = db["pets"]
|
| 10 |
+
request_collection = db["requests"]
|
| 11 |
+
|
| 12 |
+
# for pet in pet_collection.find():
|
| 13 |
+
# old_path = pet.get("image", "")
|
| 14 |
+
# filename = os.path.basename(old_path.replace("\\", "/")) # handle backslashes
|
| 15 |
+
# new_path = f"images - Copy/{filename}"
|
| 16 |
+
|
| 17 |
+
# pet_collection.update_one(
|
| 18 |
+
# {"_id": pet["_id"]},
|
| 19 |
+
# {"$set": {"image": new_path}}
|
| 20 |
+
# )
|
| 21 |
+
|
| 22 |
+
# print("✅ All image paths updated in database.")
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# result = pet_collection.update_many(
|
| 26 |
+
# {"status": "available"},
|
| 27 |
+
# {
|
| 28 |
+
# "$set": {"available": True},
|
| 29 |
+
# "$unset": {"status": ""}
|
| 30 |
+
# }
|
| 31 |
+
# )
|
| 32 |
+
|
| 33 |
+
# print(f"✅ Updated {request_collection.modified_count} pets")
|
pet/pet/login.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pymongo
|
| 4 |
+
import bcrypt
|
| 5 |
+
|
| 6 |
+
from bson import ObjectId
|
| 7 |
+
from database import users_collection as users_col
|
| 8 |
+
|
| 9 |
+
# Page config
|
| 10 |
+
st.set_page_config(page_title="HappyTails Auth", layout="wide")
|
| 11 |
+
|
| 12 |
+
# CSS
|
| 13 |
+
st.markdown("""
|
| 14 |
+
<style>
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
.stApp {
|
| 18 |
+
background-image:url("https://cdn.pixabay.com/photo/2017/09/25/13/12/dog-2785074_1280.jpg");
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
background-size: cover;
|
| 22 |
+
background-position: center center;
|
| 23 |
+
background-repeat: no-repeat;
|
| 24 |
+
background-attachment: fixed;
|
| 25 |
+
}
|
| 26 |
+
.center-wrap {
|
| 27 |
+
display: flex;
|
| 28 |
+
justify-content: center;
|
| 29 |
+
align-items: center;
|
| 30 |
+
height: 100vh;
|
| 31 |
+
}
|
| 32 |
+
.form-container {
|
| 33 |
+
backdrop-filter: blur(10px);
|
| 34 |
+
background-color: rgba(255, 255, 255, 0.15);
|
| 35 |
+
padding: 3rem 2rem;
|
| 36 |
+
border-radius: 20px;
|
| 37 |
+
max-width: 400px;
|
| 38 |
+
width: 90%;
|
| 39 |
+
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
|
| 40 |
+
color: white;
|
| 41 |
+
}
|
| 42 |
+
h2 {
|
| 43 |
+
text-align: center;
|
| 44 |
+
color: white;
|
| 45 |
+
}
|
| 46 |
+
.stTextInput>div>input, .stSelectbox>div>div>div {
|
| 47 |
+
background-color: rgba(255,255,255,0.8);
|
| 48 |
+
color: black;
|
| 49 |
+
}
|
| 50 |
+
.stButton>button {
|
| 51 |
+
background-color: #0066cc;
|
| 52 |
+
color: white;
|
| 53 |
+
font-weight: bold;
|
| 54 |
+
border-radius: 10px;
|
| 55 |
+
margin-top: 15px;
|
| 56 |
+
}
|
| 57 |
+
</style>
|
| 58 |
+
""", unsafe_allow_html=True)
|
| 59 |
+
|
| 60 |
+
# Session state
|
| 61 |
+
if "logged_in" not in st.session_state:
|
| 62 |
+
st.session_state.logged_in = False
|
| 63 |
+
if "mode" not in st.session_state:
|
| 64 |
+
st.session_state.mode = "Login"
|
| 65 |
+
|
| 66 |
+
# Toggle form
|
| 67 |
+
st.markdown('<div class="center-wrap"><div class="form-container">', unsafe_allow_html=True)
|
| 68 |
+
st.markdown(f"<h2>{st.session_state.mode}</h2>", unsafe_allow_html=True)
|
| 69 |
+
|
| 70 |
+
# Switch button
|
| 71 |
+
if st.button("Switch to " + ("Sign Up" if st.session_state.mode == "Login" else "Login")):
|
| 72 |
+
st.session_state.mode = "Sign Up" if st.session_state.mode == "Login" else "Login"
|
| 73 |
+
st.rerun()
|
| 74 |
+
|
| 75 |
+
# Login Form
|
| 76 |
+
if st.session_state.mode == "Login":
|
| 77 |
+
username = st.text_input("Username")
|
| 78 |
+
password = st.text_input("Password", type="password")
|
| 79 |
+
if st.button("Login"):
|
| 80 |
+
user = users_col.find_one({"username": username})
|
| 81 |
+
if user and bcrypt.checkpw(password.encode(), user["password"]):
|
| 82 |
+
st.success("✅ Logged in!")
|
| 83 |
+
st.session_state.logged_in = True
|
| 84 |
+
st.session_state.user = username
|
| 85 |
+
st.session_state.role = user["role"]
|
| 86 |
+
if user["role"] == "admin":
|
| 87 |
+
st.switch_page("pages/4_Admin_Dashboard.py")
|
| 88 |
+
else:
|
| 89 |
+
st.switch_page("pages/main.py")
|
| 90 |
+
else:
|
| 91 |
+
st.error("❌ Invalid username or password")
|
| 92 |
+
|
| 93 |
+
# Signup Form
|
| 94 |
+
else:
|
| 95 |
+
username = st.text_input("Create username")
|
| 96 |
+
password = st.text_input("Create password", type="password")
|
| 97 |
+
confirm = st.text_input("Confirm password", type="password")
|
| 98 |
+
role = st.selectbox("Select role", ["user", "admin"])
|
| 99 |
+
|
| 100 |
+
if st.button("Sign Up"):
|
| 101 |
+
if password != confirm:
|
| 102 |
+
st.error("❌ Passwords do not match")
|
| 103 |
+
elif users_col.find_one({"username": username}):
|
| 104 |
+
st.error("🚫 Username already exists!")
|
| 105 |
+
else:
|
| 106 |
+
hashed_pw = bcrypt.hashpw(password.encode(), bcrypt.gensalt())
|
| 107 |
+
users_col.insert_one({
|
| 108 |
+
"username": username,
|
| 109 |
+
"password": hashed_pw,
|
| 110 |
+
"role": role
|
| 111 |
+
})
|
| 112 |
+
st.success("✅ Signed up successfully!")
|
| 113 |
+
st.session_state.logged_in = True
|
| 114 |
+
st.session_state.user = username
|
| 115 |
+
st.session_state.role = role
|
| 116 |
+
if role == "admin":
|
| 117 |
+
st.switch_page("pages/4_Admin_Dashboard.py")
|
| 118 |
+
else:
|
| 119 |
+
st.switch_page("pages/main.py")
|
| 120 |
+
|
| 121 |
+
st.markdown('</div></div>', unsafe_allow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et Gallery")
|
| 6 |
+
|
| 7 |
+
# # # Fetch all available pets
|
| 8 |
+
# # available_pets = list(pet_collection.find({"available": True}))
|
| 9 |
+
|
| 10 |
+
# # if not available_pets:
|
| 11 |
+
# # st.info("No pets available for adoption at the moment.")
|
| 12 |
+
# # else:
|
| 13 |
+
# # for pet in available_pets:
|
| 14 |
+
# # with st.container():
|
| 15 |
+
# # cols = st.columns([1, 2])
|
| 16 |
+
# # with cols[0]:
|
| 17 |
+
# # st.image(pet["image_url"], width=200, caption=pet["name"])
|
| 18 |
+
# # with cols[1]:
|
| 19 |
+
# # st.subheader(pet["name"])
|
| 20 |
+
# # st.text(f"Breed: {pet['breed']}")
|
| 21 |
+
# # st.text(f"Age: {pet['age']} years")
|
| 22 |
+
# # st.write(pet["description"])
|
| 23 |
+
|
| 24 |
+
# # col1, col2 = st.columns(2)
|
| 25 |
+
# # unique_id = str(pet["_id"]) # Ensures uniqueness
|
| 26 |
+
# # with col1:
|
| 27 |
+
# # if st.button("Know More ➡️", key=f"more_{unique_id}"):
|
| 28 |
+
# # st.session_state["selected_pet_id"] = unique_id
|
| 29 |
+
# # st.switch_page("pages/3_Adoption_Form.py")
|
| 30 |
+
# # with col2:
|
| 31 |
+
# # if st.button("Adopt Me 🐕", key=f"adopt_{unique_id}"):
|
| 32 |
+
# # st.session_state["selected_pet_id"] = unique_id
|
| 33 |
+
# # st.switch_page("pages/3_Adoption_Form.py")
|
| 34 |
+
|
| 35 |
+
# import streamlit as st
|
| 36 |
+
# from utils.mongo_utils import get_all_pets, delete_pet
|
| 37 |
+
# from bson.objectid import ObjectId
|
| 38 |
+
|
| 39 |
+
# st.set_page_config(page_title="Pet Gallery", page_icon="🐾", layout="wide")
|
| 40 |
+
# st.title("🐾 Pet Gallery")
|
| 41 |
+
|
| 42 |
+
# # --- Filters ---
|
| 43 |
+
# st.sidebar.header("🔍 Search & Filter")
|
| 44 |
+
# breed_filter = st.sidebar.text_input("Breed")
|
| 45 |
+
# status_filter = st.sidebar.selectbox("Availability", ["All", "Available", "Adopted"])
|
| 46 |
+
|
| 47 |
+
# # --- Fetch Pets from DB ---
|
| 48 |
+
# all_pets = get_all_pets()
|
| 49 |
+
# if breed_filter:
|
| 50 |
+
# all_pets = [pet for pet in all_pets if breed_filter.lower() in pet.get("breed", "").lower()]
|
| 51 |
+
|
| 52 |
+
# if status_filter == "Available":
|
| 53 |
+
# all_pets = [pet for pet in all_pets if pet.get("available", True)]
|
| 54 |
+
# elif status_filter == "Adopted":
|
| 55 |
+
# all_pets = [pet for pet in all_pets if not pet.get("available", True)]
|
| 56 |
+
|
| 57 |
+
# # --- Show Pets in Grid ---
|
| 58 |
+
# if not all_pets:
|
| 59 |
+
# st.info("No matching pets found.")
|
| 60 |
+
# else:
|
| 61 |
+
# cols = st.columns(3)
|
| 62 |
+
# for idx, pet in enumerate(all_pets):
|
| 63 |
+
# with cols[idx % 3]:
|
| 64 |
+
# with st.container(border=True):
|
| 65 |
+
# st.image(
|
| 66 |
+
# pet.get("image_url", "https://cdn.pixabay.com/photo/2016/02/19/10/00/dog-1209113_960_720.jpg"),
|
| 67 |
+
# use_column_width="always",
|
| 68 |
+
# caption=pet.get("name", "Unnamed Pet")
|
| 69 |
+
# )
|
| 70 |
+
# st.markdown(f"**Breed**: {pet.get('breed', 'Unknown')}")
|
| 71 |
+
# st.markdown(f"**Age**: {pet.get('age', 'N/A')} years")
|
| 72 |
+
# st.markdown(f"**Status**: {'✅ Available' if pet.get('available', True) else '❌ Adopted'}")
|
| 73 |
+
|
| 74 |
+
# unique_id = str(pet["_id"])
|
| 75 |
+
|
| 76 |
+
# col1, col2 = st.columns(2)
|
| 77 |
+
# with col1:
|
| 78 |
+
# if st.button("Know More ➡️", key=f"more_{unique_id}"):
|
| 79 |
+
# st.session_state["selected_pet_id"] = unique_id
|
| 80 |
+
# st.switch_page("pages/3_Adoption_Form.py")
|
| 81 |
+
|
| 82 |
+
# with col2:
|
| 83 |
+
# if pet.get("available", True):
|
| 84 |
+
# if st.button("Adopt Me 🐕", key=f"adopt_{unique_id}"):
|
| 85 |
+
# st.session_state["selected_pet_id"] = unique_id
|
| 86 |
+
# st.switch_page("pages/3_Adoption_Form.py")
|
| 87 |
+
|
| 88 |
+
# # Admin Controls
|
| 89 |
+
# if st.session_state.get("user_role") == "admin":
|
| 90 |
+
# st.markdown("---")
|
| 91 |
+
# admin_col1, admin_col2 = st.columns(2)
|
| 92 |
+
# with admin_col1:
|
| 93 |
+
# if st.button("✏️ Edit", key=f"edit_{unique_id}"):
|
| 94 |
+
# st.session_state["edit_pet_id"] = unique_id
|
| 95 |
+
# st.switch_page("pages/2_Admin_Edit.py")
|
| 96 |
+
# with admin_col2:
|
| 97 |
+
# if st.button("🗑️ Delete", key=f"delete_{unique_id}"):
|
| 98 |
+
# delete_pet(pet["_id"])
|
| 99 |
+
# st.experimental_rerun()
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
import streamlit as st
|
| 104 |
+
from database import pet_collection
|
| 105 |
+
from bson.objectid import ObjectId
|
| 106 |
+
|
| 107 |
+
st.set_page_config(page_title="Pet Gallery", layout="wide")
|
| 108 |
+
st.title("🐾 Pet Gallery")
|
| 109 |
+
|
| 110 |
+
# Fetch all pets (not just available ones)
|
| 111 |
+
all_pets = list(pet_collection.find({}))
|
| 112 |
+
|
| 113 |
+
if not all_pets:
|
| 114 |
+
st.info("No pets found in the database.")
|
| 115 |
+
else:
|
| 116 |
+
# Display pets in a 3-column grid
|
| 117 |
+
cols = st.columns(3)
|
| 118 |
+
|
| 119 |
+
for index, pet in enumerate(all_pets):
|
| 120 |
+
with cols[index % 3]:
|
| 121 |
+
st.markdown("---")
|
| 122 |
+
image_url = pet.get("image") or "https://cdn.pixabay.com/photo/2016/02/19/10/00/dog-1209113_960_720.jpg"
|
| 123 |
+
st.image(image_url, use_container_width=True)
|
| 124 |
+
|
| 125 |
+
st.markdown(f"### {pet['name']}")
|
| 126 |
+
st.markdown(f"**Breed:** {pet['breed']}")
|
| 127 |
+
st.markdown(f"**Age:** {pet['age']} years")
|
| 128 |
+
|
| 129 |
+
status = pet.get("status", "available").capitalize()
|
| 130 |
+
status_emoji = "✅" if status.lower() == "available" else "❌"
|
| 131 |
+
st.markdown(f"**Status:** {status_emoji} {status}")
|
| 132 |
+
|
| 133 |
+
# Unique key for buttons
|
| 134 |
+
unique_id = str(pet["_id"])
|
| 135 |
+
col1, col2 = st.columns(2)
|
| 136 |
+
with col1:
|
| 137 |
+
if st.button("Adopt Me ➡️", key=f"more_{unique_id}"):
|
| 138 |
+
st.session_state["selected_pet_id"] = unique_id
|
| 139 |
+
st.switch_page("pages/3_Adoption_Form.py")
|
| 140 |
+
# with col2:
|
| 141 |
+
# if st.button("Adopt Me 🐕", key=f"adopt_{unique_id}"):
|
| 142 |
+
# st.session_state["selected_pet_id"] = unique_id
|
| 143 |
+
# st.switch_page("pages/3_Adoption_Form.py")
|
| 144 |
+
|
| 145 |
+
|
pet/pet/pages/3_adoption_form.py
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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et_collection, request_collection
|
| 5 |
+
# # --- MongoDB setup ---
|
| 6 |
+
# # Make sure this matches your collection name
|
| 7 |
+
|
| 8 |
+
# # --- Streamlit page config ---
|
| 9 |
+
# st.set_page_config(page_title="Adopt a Pet", layout="wide")
|
| 10 |
+
# st.title("🐾 Adopt a Pet")
|
| 11 |
+
# st.markdown("Browse and adopt your new best friend!")
|
| 12 |
+
|
| 13 |
+
# # --- Search bar ---
|
| 14 |
+
# search_term = st.text_input("🔍 Search by name or breed")
|
| 15 |
+
|
| 16 |
+
# # --- Fetch available pets ---
|
| 17 |
+
# if search_term:
|
| 18 |
+
# pets = pet_collection.find({
|
| 19 |
+
# "$and": [
|
| 20 |
+
# {"available": True},
|
| 21 |
+
# {"$or": [
|
| 22 |
+
# {"name": {"$regex": search_term, "$options": "i"}},
|
| 23 |
+
# {"breed": {"$regex": search_term, "$options": "i"}}
|
| 24 |
+
# ]}
|
| 25 |
+
# ]
|
| 26 |
+
# })
|
| 27 |
+
# else:
|
| 28 |
+
# pets = pet_collection.find({"available": True})
|
| 29 |
+
|
| 30 |
+
# # --- Display pets ---
|
| 31 |
+
# for pet in pets:
|
| 32 |
+
# unique_id = str(pet["_id"]) # String version for Streamlit keys
|
| 33 |
+
# with st.container():
|
| 34 |
+
# cols = st.columns([1, 2])
|
| 35 |
+
# with cols[0]:
|
| 36 |
+
# # st.image(pet.get("image_url", "https://placekitten.com/200/200"), width=250)
|
| 37 |
+
# st.image(pet.get("image", "https://placekitten.com/200/200"), width=250)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
# with cols[1]:
|
| 41 |
+
# st.subheader(pet["name"])
|
| 42 |
+
# st.markdown(f"""
|
| 43 |
+
# - **Breed**: {pet['breed']}
|
| 44 |
+
# - **Age**: {pet['age']} years
|
| 45 |
+
# - **About**: {pet.get('description', 'No description available.')}
|
| 46 |
+
# """)
|
| 47 |
+
|
| 48 |
+
# if st.button(f"Adopt {pet['name']}", key=f"btn_{unique_id}"):
|
| 49 |
+
# with st.form(f"adopt_form_{unique_id}"):
|
| 50 |
+
# st.subheader(f"📝 Adoption Form for {pet['name']}")
|
| 51 |
+
# user_name = st.text_input("Your Full Name", key=f"name_{unique_id}")
|
| 52 |
+
# email = st.text_input("Email Address", key=f"email_{unique_id}")
|
| 53 |
+
# reason = st.text_area("Why do you want to adopt this pet?", key=f"reason_{unique_id}")
|
| 54 |
+
# submitted = st.form_submit_button("Submit Request")
|
| 55 |
+
|
| 56 |
+
# if submitted:
|
| 57 |
+
# try:
|
| 58 |
+
# # Insert the adoption request
|
| 59 |
+
# request_collection.insert_one({
|
| 60 |
+
# "pet_id": pet["_id"], # Store ObjectId
|
| 61 |
+
# "pet_name": pet["name"],
|
| 62 |
+
# "user_name": user_name,
|
| 63 |
+
# "email": email,
|
| 64 |
+
# "reason": reason,
|
| 65 |
+
# })
|
| 66 |
+
|
| 67 |
+
# # Mark pet as unavailable
|
| 68 |
+
# update_result = pet_collection.update_one(
|
| 69 |
+
# {"_id": ObjectId(unique_id)},
|
| 70 |
+
# {"$set": {"available": False}}
|
| 71 |
+
# )
|
| 72 |
+
|
| 73 |
+
# if update_result.modified_count == 1:
|
| 74 |
+
# st.success(f"🎉 Your request to adopt {pet['name']} has been submitted!")
|
| 75 |
+
# st.balloons()
|
| 76 |
+
# print("✅ Adoption request inserted and pet marked unavailable.")
|
| 77 |
+
# else:
|
| 78 |
+
# st.warning("Something went wrong updating pet status.")
|
| 79 |
+
|
| 80 |
+
# except Exception as e:
|
| 81 |
+
# st.error("❌ Failed to submit adoption request.")
|
| 82 |
+
# print("❌ Error:", e)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
# import streamlit as st
|
| 86 |
+
# from bson import ObjectId
|
| 87 |
+
# from database import pet_collection, request_collection
|
| 88 |
+
|
| 89 |
+
# # --- Streamlit page config ---
|
| 90 |
+
# st.set_page_config(page_title="Adopt a Pet", layout="wide")
|
| 91 |
+
# st.title("🐾 Adopt a Pet")
|
| 92 |
+
# st.markdown("Browse and adopt your new best friend!")
|
| 93 |
+
|
| 94 |
+
# # --- Search bar ---
|
| 95 |
+
# search_term = st.text_input("🔍 Search by name or breed")
|
| 96 |
+
|
| 97 |
+
# # --- Fetch available pets ---
|
| 98 |
+
# if search_term:
|
| 99 |
+
# pets = pet_collection.find({
|
| 100 |
+
# "$and": [
|
| 101 |
+
# {"available": True},
|
| 102 |
+
# {"$or": [
|
| 103 |
+
# {"name": {"$regex": search_term, "$options": "i"}},
|
| 104 |
+
# {"breed": {"$regex": search_term, "$options": "i"}}
|
| 105 |
+
# ]}
|
| 106 |
+
# ]
|
| 107 |
+
# })
|
| 108 |
+
# else:
|
| 109 |
+
# pets = pet_collection.find({"available": True})
|
| 110 |
+
|
| 111 |
+
# # --- Display pets ---
|
| 112 |
+
# for pet in pets:
|
| 113 |
+
# unique_id = str(pet["_id"])
|
| 114 |
+
# with st.container():
|
| 115 |
+
# cols = st.columns([1, 2])
|
| 116 |
+
# with cols[0]:
|
| 117 |
+
# st.image(pet.get("image", "https://placekitten.com/200/200"), width=250)
|
| 118 |
+
|
| 119 |
+
# with cols[1]:
|
| 120 |
+
# st.subheader(pet["name"])
|
| 121 |
+
# st.markdown(f"""
|
| 122 |
+
# - **Breed**: {pet['breed']}
|
| 123 |
+
# - **Age**: {pet['age']} years
|
| 124 |
+
# - **About**: {pet.get('description', 'No description available.')}
|
| 125 |
+
# """)
|
| 126 |
+
|
| 127 |
+
# if st.button(f"Adopt {pet['name']}", key=f"btn_{unique_id}"):
|
| 128 |
+
# with st.form(f"adopt_form_{unique_id}"):
|
| 129 |
+
# st.subheader(f"📝 Adoption Form for {pet['name']}")
|
| 130 |
+
# user_name = st.text_input("Your Full Name", key=f"name_{unique_id}")
|
| 131 |
+
# email = st.text_input("Email Address", key=f"email_{unique_id}")
|
| 132 |
+
# reason = st.text_area("Why do you want to adopt this pet?", key=f"reason_{unique_id}")
|
| 133 |
+
# submitted = st.form_submit_button("Submit Request")
|
| 134 |
+
|
| 135 |
+
# if submitted:
|
| 136 |
+
# if user_name and email and reason:
|
| 137 |
+
# try:
|
| 138 |
+
# # Insert into adoption requests
|
| 139 |
+
# request_collection.insert_one({
|
| 140 |
+
# "pet_id": pet["_id"],
|
| 141 |
+
# "pet_name": pet["name"],
|
| 142 |
+
# "user_name": user_name,
|
| 143 |
+
# "email": email,
|
| 144 |
+
# "reason": reason,
|
| 145 |
+
# "status": "pending"
|
| 146 |
+
# })
|
| 147 |
+
|
| 148 |
+
# # Mark the pet as unavailable
|
| 149 |
+
# pet_collection.update_one(
|
| 150 |
+
# {"_id": pet["_id"]},
|
| 151 |
+
# {"$set": {"available": False}}
|
| 152 |
+
# )
|
| 153 |
+
|
| 154 |
+
# st.success(f"🎉 Your request to adopt {pet['name']} has been submitted!")
|
| 155 |
+
# st.balloons()
|
| 156 |
+
|
| 157 |
+
# except Exception as e:
|
| 158 |
+
# st.error("❌ Failed to submit adoption request.")
|
| 159 |
+
# st.write(e)
|
| 160 |
+
# else:
|
| 161 |
+
# st.warning("Please fill all fields before submitting.")
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
import streamlit as st
|
| 165 |
+
from bson import ObjectId
|
| 166 |
+
from database import pet_collection, request_collection
|
| 167 |
+
|
| 168 |
+
# --- Streamlit page config ---
|
| 169 |
+
st.set_page_config(page_title="Adopt a Pet", layout="wide")
|
| 170 |
+
st.title("🐾 Adopt a Pet")
|
| 171 |
+
st.markdown("Browse and adopt your new best friend!")
|
| 172 |
+
|
| 173 |
+
# --- Search bar ---
|
| 174 |
+
search_term = st.text_input("🔍 Search by name or breed")
|
| 175 |
+
|
| 176 |
+
# --- Fetch available pets ---
|
| 177 |
+
if search_term:
|
| 178 |
+
pets = pet_collection.find({
|
| 179 |
+
"$and": [
|
| 180 |
+
{"available": True},
|
| 181 |
+
{"$or": [
|
| 182 |
+
{"name": {"$regex": search_term, "$options": "i"}},
|
| 183 |
+
{"breed": {"$regex": search_term, "$options": "i"}}
|
| 184 |
+
]}
|
| 185 |
+
]
|
| 186 |
+
})
|
| 187 |
+
else:
|
| 188 |
+
pets = pet_collection.find({"available": True})
|
| 189 |
+
|
| 190 |
+
# --- Display pets ---
|
| 191 |
+
for pet in pets:
|
| 192 |
+
unique_id = str(pet["_id"])
|
| 193 |
+
with st.container():
|
| 194 |
+
cols = st.columns([1, 2])
|
| 195 |
+
with cols[0]:
|
| 196 |
+
st.image(pet.get("image", "https://placekitten.com/200/200"), width=250)
|
| 197 |
+
|
| 198 |
+
with cols[1]:
|
| 199 |
+
st.subheader(pet["name"])
|
| 200 |
+
st.markdown(f"""
|
| 201 |
+
- **Breed**: {pet['breed']}
|
| 202 |
+
- **Age**: {pet['age']} years
|
| 203 |
+
- **About**: {pet.get('description', 'No description available.')}
|
| 204 |
+
""")
|
| 205 |
+
|
| 206 |
+
if st.button(f"Adopt {pet['name']}", key=f"btn_{unique_id}"):
|
| 207 |
+
with st.form(f"adopt_form_{unique_id}"):
|
| 208 |
+
st.subheader(f"📝 Adoption Form for {pet['name']}")
|
| 209 |
+
user_name = st.text_input("Your Full Name", key=f"name_{unique_id}")
|
| 210 |
+
email = st.text_input("Email Address", key=f"email_{unique_id}")
|
| 211 |
+
reason = st.text_area("Why do you want to adopt this pet?", key=f"reason_{unique_id}")
|
| 212 |
+
submitted = st.form_submit_button("Submit Request")
|
| 213 |
+
|
| 214 |
+
if submitted:
|
| 215 |
+
if user_name and email and reason:
|
| 216 |
+
try:
|
| 217 |
+
# Insert into adoption requests
|
| 218 |
+
request_collection.insert_one({
|
| 219 |
+
"pet_id": pet["_id"],
|
| 220 |
+
"pet_name": pet["name"],
|
| 221 |
+
"user_name": user_name,
|
| 222 |
+
"email": email,
|
| 223 |
+
"reason": reason,
|
| 224 |
+
"status": "pending"
|
| 225 |
+
})
|
| 226 |
+
|
| 227 |
+
# Mark the pet as unavailable
|
| 228 |
+
pet_collection.update_one(
|
| 229 |
+
{"_id": pet["_id"]},
|
| 230 |
+
{"$set": {"available": False}}
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
st.success(f"🎉 Your request to adopt {pet['name']} has been submitted!")
|
| 234 |
+
st.balloons()
|
| 235 |
+
|
| 236 |
+
except Exception as e:
|
| 237 |
+
st.error("❌ Failed to submit adoption request.")
|
| 238 |
+
st.write(e)
|
| 239 |
+
else:
|
| 240 |
+
st.warning("Please fill all fields before submitting.")
|
pet/pet/pages/4_Admin_Dashboard.py
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# import streamlit as st
|
| 3 |
+
# from pymongo import MongoClient
|
| 4 |
+
# from bson.objectid import ObjectId
|
| 5 |
+
# import os
|
| 6 |
+
# from PIL import Image
|
| 7 |
+
# from database import pet_collection, request_collection
|
| 8 |
+
|
| 9 |
+
# # # MongoDB connection
|
| 10 |
+
# # client = MongoClient("mongodb://localhost:27017") # Update if needed
|
| 11 |
+
# # db = client["pet_adoption"]
|
| 12 |
+
# # pet_collection = db["pets"]
|
| 13 |
+
# # request_collection = db["adoption_requests"]
|
| 14 |
+
|
| 15 |
+
# st.set_page_config(page_title="Admin Dashboard", layout="wide")
|
| 16 |
+
# st.title("🐾 Admin Dashboard")
|
| 17 |
+
|
| 18 |
+
# # --- Search & Filter ---
|
| 19 |
+
# st.subheader("Search & Filter Pets")
|
| 20 |
+
# search_term = st.text_input("Search by Name, Breed, or Status")
|
| 21 |
+
|
| 22 |
+
# # Fetch pets
|
| 23 |
+
# query = {"$or": [
|
| 24 |
+
# {"name": {"$regex": search_term, "$options": "i"}},
|
| 25 |
+
# {"breed": {"$regex": search_term, "$options": "i"}},
|
| 26 |
+
# {"status": {"$regex": search_term, "$options": "i"}}
|
| 27 |
+
# ]} if search_term else {}
|
| 28 |
+
|
| 29 |
+
# pets = list(pet_collection.find(query))
|
| 30 |
+
|
| 31 |
+
# # --- Show all pets ---
|
| 32 |
+
# st.markdown("### All Pets")
|
| 33 |
+
# if pets:
|
| 34 |
+
# for pet in pets:
|
| 35 |
+
# st.markdown(f"**Name:** {pet.get('name', '')} | **Breed:** {pet.get('breed', '')} | **Status:** {pet.get('status', 'available')}")
|
| 36 |
+
# else:
|
| 37 |
+
# st.info("No pets found.")
|
| 38 |
+
|
| 39 |
+
# # --- Select a pet to edit ---
|
| 40 |
+
# st.subheader("✏️ Edit or Delete Pet")
|
| 41 |
+
# if pets:
|
| 42 |
+
# pet_options = [f"{pet.get('name', 'Unnamed')} - {str(pet['_id'])}" for pet in pets]
|
| 43 |
+
# selected_pet_str = st.selectbox("Select a pet to edit", pet_options)
|
| 44 |
+
# selected_id = selected_pet_str.split(" - ")[-1]
|
| 45 |
+
# selected_pet = pet_collection.find_one({"_id": ObjectId(selected_id)})
|
| 46 |
+
|
| 47 |
+
# # Pre-filled form
|
| 48 |
+
# name = st.text_input("Name", value=selected_pet.get("name", ""))
|
| 49 |
+
# age = st.number_input("Age", value=selected_pet.get("age", 0), min_value=0)
|
| 50 |
+
# breed = st.text_input("Breed", value=selected_pet.get("breed", ""))
|
| 51 |
+
# health = st.text_area("Health Info", value=selected_pet.get("health", ""))
|
| 52 |
+
# description = st.text_area("Description", value=selected_pet.get("description", ""))
|
| 53 |
+
# status = st.selectbox("Status", ["available", "adopted", "pending"],
|
| 54 |
+
# index=["available", "adopted", "pending"].index(selected_pet.get("status", "available")))
|
| 55 |
+
|
| 56 |
+
# # Show image
|
| 57 |
+
# image_url = selected_pet.get("image", "")
|
| 58 |
+
# if image_url:
|
| 59 |
+
# st.image(image_url, width=200, caption="Current Image")
|
| 60 |
+
|
| 61 |
+
# # Upload new image
|
| 62 |
+
# uploaded_image = st.file_uploader("Upload New Image", type=["jpg", "jpeg", "png"])
|
| 63 |
+
# if uploaded_image:
|
| 64 |
+
# image_path = os.path.join("pet_images", uploaded_image.name)
|
| 65 |
+
# os.makedirs("pet_images", exist_ok=True)
|
| 66 |
+
# with open(image_path, "wb") as f:
|
| 67 |
+
# f.write(uploaded_image.getbuffer())
|
| 68 |
+
# image_url = image_path
|
| 69 |
+
|
| 70 |
+
# # Update button
|
| 71 |
+
# if st.button("Update Pet"):
|
| 72 |
+
# if not name:
|
| 73 |
+
# st.warning("Name is required.")
|
| 74 |
+
# else:
|
| 75 |
+
# update_fields = {
|
| 76 |
+
# "name": name,
|
| 77 |
+
# "age": age,
|
| 78 |
+
# "breed": breed,
|
| 79 |
+
# "health": health,
|
| 80 |
+
# "description": description,
|
| 81 |
+
# "status": status,
|
| 82 |
+
# "image": image_url
|
| 83 |
+
# }
|
| 84 |
+
# pet_collection.update_one({"_id": ObjectId(selected_id)}, {"$set": update_fields})
|
| 85 |
+
# st.success("✅ Pet updated!")
|
| 86 |
+
# st.rerun()
|
| 87 |
+
|
| 88 |
+
# # Delete button
|
| 89 |
+
# if st.button("❌ Delete Pet"):
|
| 90 |
+
# pet_collection.delete_one({"_id": ObjectId(selected_id)})
|
| 91 |
+
# st.warning("🗑️ Pet deleted!")
|
| 92 |
+
# st.rerun()
|
| 93 |
+
|
| 94 |
+
# # --- Add new pet section ---
|
| 95 |
+
# st.subheader("➕ Add New Pet")
|
| 96 |
+
|
| 97 |
+
# with st.form("add_pet"):
|
| 98 |
+
# new_name = st.text_input("Pet Name")
|
| 99 |
+
# new_age = st.number_input("Pet Age", min_value=0, step=1)
|
| 100 |
+
# new_breed = st.text_input("Breed")
|
| 101 |
+
# new_health = st.text_area("Health Info")
|
| 102 |
+
# new_description = st.text_area("Description")
|
| 103 |
+
# new_status = st.selectbox("Status", ["available", "adopted", "pending"])
|
| 104 |
+
# new_image = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
|
| 105 |
+
|
| 106 |
+
# submitted = st.form_submit_button("Add Pet")
|
| 107 |
+
|
| 108 |
+
# if submitted:
|
| 109 |
+
# if not new_name:
|
| 110 |
+
# st.warning("Name is required.")
|
| 111 |
+
# else:
|
| 112 |
+
# image_path = ""
|
| 113 |
+
# if new_image:
|
| 114 |
+
# os.makedirs("pet_images", exist_ok=True)
|
| 115 |
+
# image_path = os.path.join("pet_images", new_image.name)
|
| 116 |
+
# with open(image_path, "wb") as f:
|
| 117 |
+
# f.write(new_image.getbuffer())
|
| 118 |
+
|
| 119 |
+
# new_pet = {
|
| 120 |
+
# "name": new_name,
|
| 121 |
+
# "age": new_age,
|
| 122 |
+
# "breed": new_breed,
|
| 123 |
+
# "health": new_health,
|
| 124 |
+
# "description": new_description,
|
| 125 |
+
# "status": new_status,
|
| 126 |
+
# "image": image_path
|
| 127 |
+
# }
|
| 128 |
+
|
| 129 |
+
# pet_collection.insert_one(new_pet)
|
| 130 |
+
# st.success("🎉 New pet added!")
|
| 131 |
+
# st.rerun()
|
| 132 |
+
|
| 133 |
+
# # --- Adoption Request Management ---
|
| 134 |
+
# st.subheader("📋 Adoption Requests")
|
| 135 |
+
# requests = list(request_collection.find())
|
| 136 |
+
|
| 137 |
+
# if requests:
|
| 138 |
+
# for req in requests:
|
| 139 |
+
# pet = pet_collection.find_one({"_id": ObjectId(req["pet_id"])})
|
| 140 |
+
# st.markdown(f"""
|
| 141 |
+
# **Request ID:** {str(req["_id"])}
|
| 142 |
+
# **Pet:** {pet.get("name", "Unknown")}
|
| 143 |
+
# **User:** {req.get("user_name")}
|
| 144 |
+
# **Contact:** {req.get("contact")}
|
| 145 |
+
# **Status:** {req.get("status", "pending")}
|
| 146 |
+
# """)
|
| 147 |
+
|
| 148 |
+
# col1, col2 = st.columns(2)
|
| 149 |
+
# with col1:
|
| 150 |
+
# if st.button(f"✅ Accept", key=f"accept_{req['_id']}"):
|
| 151 |
+
# request_collection.update_one({"_id": req["_id"]}, {"$set": {"status": "accepted"}})
|
| 152 |
+
# pet_collection.update_one({"_id": ObjectId(req["pet_id"])} , {"$set": {"status": "adopted"}})
|
| 153 |
+
# st.success("Request accepted!")
|
| 154 |
+
# st.rerun()
|
| 155 |
+
# with col2:
|
| 156 |
+
# if st.button(f"❌ Reject", key=f"reject_{req['_id']}"):
|
| 157 |
+
# request_collection.update_one({"_id": req["_id"]}, {"$set": {"status": "rejected"}})
|
| 158 |
+
# st.warning("Request rejected!")
|
| 159 |
+
# st.rerun()
|
| 160 |
+
# else:
|
| 161 |
+
# st.info("No adoption requests found.")
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
import streamlit as st
|
| 165 |
+
from pymongo import MongoClient
|
| 166 |
+
from bson.objectid import ObjectId
|
| 167 |
+
from bson.errors import InvalidId
|
| 168 |
+
import os
|
| 169 |
+
from PIL import Image
|
| 170 |
+
from database import pet_collection, request_collection
|
| 171 |
+
|
| 172 |
+
st.set_page_config(page_title="Admin Dashboard", layout="wide")
|
| 173 |
+
st.title("🐾 Admin Dashboard")
|
| 174 |
+
|
| 175 |
+
# --- Search & Filter --- #
|
| 176 |
+
st.subheader("Search & Filter Pets")
|
| 177 |
+
search_term = st.text_input("Search by Name, Breed, or Status")
|
| 178 |
+
|
| 179 |
+
query = {"$or": [
|
| 180 |
+
{"name": {"$regex": search_term, "$options": "i"}},
|
| 181 |
+
{"breed": {"$regex": search_term, "$options": "i"}},
|
| 182 |
+
{"status": {"$regex": search_term, "$options": "i"}}
|
| 183 |
+
]} if search_term else {}
|
| 184 |
+
|
| 185 |
+
pets = list(pet_collection.find(query))
|
| 186 |
+
|
| 187 |
+
# --- Show all pets --- #
|
| 188 |
+
st.markdown("### All Pets")
|
| 189 |
+
if pets:
|
| 190 |
+
for pet in pets:
|
| 191 |
+
st.markdown(f"**Name:** {pet.get('name', '')} | **Breed:** {pet.get('breed', '')} | **Status:** {pet.get('status', 'available')}")
|
| 192 |
+
else:
|
| 193 |
+
st.info("No pets found.")
|
| 194 |
+
|
| 195 |
+
# --- Edit or Delete Pet --- #
|
| 196 |
+
st.subheader("✏️ Edit or Delete Pet")
|
| 197 |
+
if pets:
|
| 198 |
+
pet_options = [f"{pet.get('name', 'Unnamed')} - {str(pet['_id'])}" for pet in pets]
|
| 199 |
+
selected_pet_str = st.selectbox("Select a pet to edit", pet_options)
|
| 200 |
+
selected_id = selected_pet_str.split(" - ")[-1]
|
| 201 |
+
selected_pet = pet_collection.find_one({"_id": ObjectId(selected_id)})
|
| 202 |
+
|
| 203 |
+
# Pre-filled form
|
| 204 |
+
name = st.text_input("Name", value=selected_pet.get("name", ""))
|
| 205 |
+
age = st.number_input("Age", value=selected_pet.get("age", 0), min_value=0)
|
| 206 |
+
breed = st.text_input("Breed", value=selected_pet.get("breed", ""))
|
| 207 |
+
health = st.text_area("Health Info", value=selected_pet.get("health", ""))
|
| 208 |
+
description = st.text_area("Description", value=selected_pet.get("description", ""))
|
| 209 |
+
status = st.selectbox("Status", ["available", "adopted", "pending"],
|
| 210 |
+
index=["available", "adopted", "pending"].index(selected_pet.get("status", "available")))
|
| 211 |
+
|
| 212 |
+
# Show image
|
| 213 |
+
image_url = selected_pet.get("image", "")
|
| 214 |
+
if image_url:
|
| 215 |
+
st.image(image_url, width=200, caption="Current Image")
|
| 216 |
+
|
| 217 |
+
# Upload new image
|
| 218 |
+
uploaded_image = st.file_uploader("Upload New Image", type=["jpg", "jpeg", "png"])
|
| 219 |
+
if uploaded_image:
|
| 220 |
+
image_path = os.path.join("pet_images", uploaded_image.name)
|
| 221 |
+
os.makedirs("pet_images", exist_ok=True)
|
| 222 |
+
with open(image_path, "wb") as f:
|
| 223 |
+
f.write(uploaded_image.getbuffer())
|
| 224 |
+
image_url = image_path
|
| 225 |
+
|
| 226 |
+
# Update button
|
| 227 |
+
if st.button("Update Pet"):
|
| 228 |
+
if not name:
|
| 229 |
+
st.warning("Name is required.")
|
| 230 |
+
else:
|
| 231 |
+
update_fields = {
|
| 232 |
+
"name": name,
|
| 233 |
+
"age": age,
|
| 234 |
+
"breed": breed,
|
| 235 |
+
"health": health,
|
| 236 |
+
"description": description,
|
| 237 |
+
"status": status,
|
| 238 |
+
"image": image_url
|
| 239 |
+
}
|
| 240 |
+
pet_collection.update_one({"_id": ObjectId(selected_id)}, {"$set": update_fields})
|
| 241 |
+
st.success("✅ Pet updated!")
|
| 242 |
+
st.rerun()
|
| 243 |
+
|
| 244 |
+
# Delete button
|
| 245 |
+
if st.button("❌ Delete Pet"):
|
| 246 |
+
pet_collection.delete_one({"_id": ObjectId(selected_id)})
|
| 247 |
+
st.warning("🗑️ Pet deleted!")
|
| 248 |
+
st.rerun()
|
| 249 |
+
|
| 250 |
+
# --- Add New Pet Section --- #
|
| 251 |
+
st.subheader("➕ Add New Pet")
|
| 252 |
+
|
| 253 |
+
with st.form("add_pet"):
|
| 254 |
+
new_name = st.text_input("Pet Name")
|
| 255 |
+
new_age = st.number_input("Pet Age", min_value=0, step=1)
|
| 256 |
+
new_breed = st.text_input("Breed")
|
| 257 |
+
new_health = st.text_area("Health Info")
|
| 258 |
+
new_description = st.text_area("Description")
|
| 259 |
+
new_status = st.selectbox("Status", ["available", "adopted", "pending"])
|
| 260 |
+
new_image = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
|
| 261 |
+
|
| 262 |
+
submitted = st.form_submit_button("Add Pet")
|
| 263 |
+
|
| 264 |
+
if submitted:
|
| 265 |
+
if not new_name:
|
| 266 |
+
st.warning("Name is required.")
|
| 267 |
+
else:
|
| 268 |
+
image_path = ""
|
| 269 |
+
if new_image:
|
| 270 |
+
os.makedirs("pet_images", exist_ok=True)
|
| 271 |
+
image_path = os.path.join("pet_images", new_image.name)
|
| 272 |
+
with open(image_path, "wb") as f:
|
| 273 |
+
f.write(new_image.getbuffer())
|
| 274 |
+
|
| 275 |
+
new_pet = {
|
| 276 |
+
"name": new_name,
|
| 277 |
+
"age": new_age,
|
| 278 |
+
"breed": new_breed,
|
| 279 |
+
"health": new_health,
|
| 280 |
+
"description": new_description,
|
| 281 |
+
"status": new_status,
|
| 282 |
+
"image": image_path
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
pet_collection.insert_one(new_pet)
|
| 286 |
+
st.success("🎉 New pet added!")
|
| 287 |
+
st.rerun()
|
| 288 |
+
|
| 289 |
+
# --- Adoption Request Management --- #
|
| 290 |
+
st.subheader("📋 Adoption Requests")
|
| 291 |
+
|
| 292 |
+
requests = list(request_collection.find())
|
| 293 |
+
|
| 294 |
+
if requests:
|
| 295 |
+
for req in requests:
|
| 296 |
+
pet = None
|
| 297 |
+
try:
|
| 298 |
+
pet_id = ObjectId(req["pet_id"]) if not isinstance(req["pet_id"], ObjectId) else req["pet_id"]
|
| 299 |
+
pet = pet_collection.find_one({"_id": pet_id})
|
| 300 |
+
except (InvalidId, TypeError, KeyError):
|
| 301 |
+
pet = None
|
| 302 |
+
|
| 303 |
+
pet_name = pet.get("name", "Unknown") if pet else "Unknown"
|
| 304 |
+
|
| 305 |
+
st.markdown(f"""
|
| 306 |
+
**Request ID:** {str(req["_id"])}
|
| 307 |
+
**Pet:** {pet_name}
|
| 308 |
+
**User:** {req.get("user_name", "N/A")}
|
| 309 |
+
**Contact:** {req.get("contact", "N/A")}
|
| 310 |
+
**Status:** {req.get("status", "pending")}
|
| 311 |
+
""")
|
| 312 |
+
|
| 313 |
+
col1, col2 = st.columns(2)
|
| 314 |
+
with col1:
|
| 315 |
+
if st.button(f"✅ Accept", key=f"accept_{req['_id']}"):
|
| 316 |
+
request_collection.update_one({"_id": req["_id"]}, {"$set": {"status": "accepted"}})
|
| 317 |
+
if pet:
|
| 318 |
+
pet_collection.update_one({"_id": pet["_id"]}, {"$set": {"status": "adopted"}})
|
| 319 |
+
st.success("Request accepted!")
|
| 320 |
+
st.rerun()
|
| 321 |
+
with col2:
|
| 322 |
+
if st.button(f"❌ Reject", key=f"reject_{req['_id']}"):
|
| 323 |
+
request_collection.update_one({"_id": req["_id"]}, {"$set": {"status": "rejected"}})
|
| 324 |
+
st.warning("Request rejected!")
|
| 325 |
+
st.rerun()
|
| 326 |
+
else:
|
| 327 |
+
st.info("No adoption requests found.")
|
pet/pet/pages/main.py
ADDED
|
@@ -0,0 +1,462 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# import streamlit as st
|
| 2 |
+
# from streamlit_option_menu import option_menu
|
| 3 |
+
# from PIL import Image
|
| 4 |
+
# import random
|
| 5 |
+
|
| 6 |
+
# st.set_page_config(page_title="Happy Tails ", page_icon="🐾", layout="wide")
|
| 7 |
+
|
| 8 |
+
# with st.sidebar:
|
| 9 |
+
# selected=option_menu("Happy Tails", ["Home", "Adopt a Pet", "Pet Care Tips", "Gallery", "Contact","FAQs"],
|
| 10 |
+
# icons=["house", "paw", "heart", "camera", "envelope", "question-circle"], default_index=0, orientation="vertical")
|
| 11 |
+
|
| 12 |
+
# if selected == "Home":
|
| 13 |
+
# st.title("🐾 Welcome to Happy Tails")
|
| 14 |
+
# st.subheader("A loving space for every paw.")
|
| 15 |
+
|
| 16 |
+
# st.markdown("""
|
| 17 |
+
# **Happy Tails** is a pet adoption and care center dedicated to finding loving homes for rescued pets.
|
| 18 |
+
# We offer resources for pet parents, adoption services, and plenty of wagging tails!
|
| 19 |
+
# """)
|
| 20 |
+
# img1 = Image.open("C:\\Users\\sathy\\Downloads\\pet\\images - Copy\\bg_1.jpg")
|
| 21 |
+
# max_size = (800, 600)
|
| 22 |
+
# img1.thumbnail(max_size)
|
| 23 |
+
|
| 24 |
+
# img1.show()
|
| 25 |
+
# st.image(img1, caption="Every pet deserves a family")
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# st.markdown("## 🐶 Our Impact")
|
| 29 |
+
|
| 30 |
+
# col1, col2 = st.columns(2)
|
| 31 |
+
|
| 32 |
+
# with col1:
|
| 33 |
+
# st.subheader("🐾 Pets Adopted")
|
| 34 |
+
# st.metric(label="Since Launch", value=random.randint(100, 500))
|
| 35 |
+
|
| 36 |
+
# with col2:
|
| 37 |
+
# st.subheader("😊 Happy Customers")
|
| 38 |
+
# st.metric(label="Community Count", value=random.randint(200, 1000))
|
| 39 |
+
|
| 40 |
+
# elif selected == "Adopt a Pet":
|
| 41 |
+
# st.title("Adopt a Pet 🐶🐱")
|
| 42 |
+
# st.markdown("Meet our adorable friends looking for a home.")
|
| 43 |
+
|
| 44 |
+
# col1, col2 = st.columns(2)
|
| 45 |
+
# with col1:
|
| 46 |
+
# st.image("C:\\Users\\sathy\\Downloads\\pet\\images - Copy\\about-1.jpg", width=300)
|
| 47 |
+
# st.markdown("**Name:** Max \n**Breed:** Labrador \n**Age:** 2 years \n**Status:** Available")
|
| 48 |
+
# with col2:
|
| 49 |
+
# st.image("C:\\Users\\sathy\\Downloads\\pet\\images - Copy\\about-2.jpg", width=300)
|
| 50 |
+
# st.markdown("**Name:** Luna \n**Breed:** Persian Cat \n**Age:** 1.5 years \n**Status:** Available")
|
| 51 |
+
|
| 52 |
+
# elif selected == "Pet Care Tips":
|
| 53 |
+
# st.title("Pet Care Tips 🧼")
|
| 54 |
+
# st.markdown("""
|
| 55 |
+
# - 🥣 **Nutrition:** Feed a balanced diet.
|
| 56 |
+
# - 🧼 **Hygiene:** Regular grooming and vet visits.
|
| 57 |
+
# - 🐾 **Exercise:** Walks and playtime every day.
|
| 58 |
+
# - 🐕 **Love:** Shower them with affection.
|
| 59 |
+
# """)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
# # elif selected == "Gallery":
|
| 63 |
+
# # st.title("Happy Faces Gallery 📸")
|
| 64 |
+
# # col1, col2, col3,col4,col5,col6 = st.columns(6)
|
| 65 |
+
|
| 66 |
+
# # with col1:
|
| 67 |
+
# # st.image("C:\\Users\\sathy\\Downloads\\pet\\images - Copy\\img10.jpg", use_container_width=True)
|
| 68 |
+
# # with col2:
|
| 69 |
+
# # st.image("C:\\Users\\sathy\\Downloads\\pet\\images - Copy\\image_6.jpg", use_container_width=True)
|
| 70 |
+
# # with col3:
|
| 71 |
+
# # st.image("C:\\Users\\sathy\\Downloads\\pet\\images - Copy\img4.jpg", use_container_width=True)
|
| 72 |
+
# # with col4:
|
| 73 |
+
# # st.image("C:\\Users\\sathy\\Downloads\\pet\\images - Copy\\img1.jpg", use_container_width=True)
|
| 74 |
+
# # with col5:
|
| 75 |
+
# # st.image("C:\\Users\\sathy\\Downloads\\pet\\images - Copy\\img7.jpg", use_container_width=True)
|
| 76 |
+
# # with col6:
|
| 77 |
+
# # st.image("C:\\Users\\sathy\\Downloads\\pet\\images - Copy\\img12.jpg", use_container_width=True)
|
| 78 |
+
|
| 79 |
+
# # elif selected == "Gallery":
|
| 80 |
+
# # st.title("Happy Faces Gallery 📸")
|
| 81 |
+
|
| 82 |
+
# # # List of images and captions
|
| 83 |
+
# # images = [
|
| 84 |
+
# # ("img10.jpg", "Bella"),
|
| 85 |
+
# # ("image_6.jpg", "Max"),
|
| 86 |
+
# # ("img4.jpg", "Coco"),
|
| 87 |
+
# # ("img1.jpg", "Charlie"),
|
| 88 |
+
# # ("img7.jpg", "Luna"),
|
| 89 |
+
# # ("img12.jpg", "Rocky"),
|
| 90 |
+
# # ]
|
| 91 |
+
|
| 92 |
+
# # # Add CSS for hover effect
|
| 93 |
+
# # st.markdown("""
|
| 94 |
+
# # <style>
|
| 95 |
+
# # .img-container {
|
| 96 |
+
# # transition: transform 0.3s;
|
| 97 |
+
# # text-align: center;
|
| 98 |
+
# # padding: 5px;
|
| 99 |
+
# # }
|
| 100 |
+
# # .img-container:hover {
|
| 101 |
+
# # transform: scale(1.05);
|
| 102 |
+
# # }
|
| 103 |
+
# # .caption {
|
| 104 |
+
# # font-size: 16px;
|
| 105 |
+
# # color: #444;
|
| 106 |
+
# # margin-top: 5px;
|
| 107 |
+
# # }
|
| 108 |
+
# # </style>
|
| 109 |
+
# # """, unsafe_allow_html=True)
|
| 110 |
+
|
| 111 |
+
# # # Display images in a 3-column grid
|
| 112 |
+
# # for i in range(0, len(images), 3):
|
| 113 |
+
# # cols = st.columns(3)
|
| 114 |
+
# # for j, col in enumerate(cols):
|
| 115 |
+
# # if i + j < len(images):
|
| 116 |
+
# # img_path = f"C://Users//sathy//Downloads//pet//images - Copy//{images[i + j][0]}"
|
| 117 |
+
# # caption = images[i + j][1]
|
| 118 |
+
# # with col:
|
| 119 |
+
# # col.markdown(f"""
|
| 120 |
+
# # <div class="img-container">
|
| 121 |
+
# # <img src="file:///{img_path}" style="width:100%; border-radius: 10px;" />
|
| 122 |
+
# # <div class="caption">{caption}</div>
|
| 123 |
+
# # </div>
|
| 124 |
+
# # """, unsafe_allow_html=True)
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
# elif selected == "Gallery":
|
| 129 |
+
# st.title("Happy Faces Gallery 📸")
|
| 130 |
+
|
| 131 |
+
# # List of images and captions
|
| 132 |
+
# images = [
|
| 133 |
+
# ("Bella.jpg", "Bella"),
|
| 134 |
+
# ("max.jpg", "Max"),
|
| 135 |
+
# ("img4.jpg", "Coco"),
|
| 136 |
+
# ("molly.jpg", "Charlie"),
|
| 137 |
+
# ("luna.jpg", "Luna"),
|
| 138 |
+
# ("rocky.jpg", "Rocky"),
|
| 139 |
+
# ]
|
| 140 |
+
|
| 141 |
+
# base_path = "C:/Users/sathy/Downloads/pet/images - Copy/"
|
| 142 |
+
|
| 143 |
+
# # Add CSS for zoom on image container
|
| 144 |
+
# st.markdown("""
|
| 145 |
+
# <style>
|
| 146 |
+
# .gallery-img {
|
| 147 |
+
# transition: transform 0.3s ease;
|
| 148 |
+
# border-radius: 10px;
|
| 149 |
+
# }
|
| 150 |
+
# .gallery-img:hover {
|
| 151 |
+
# transform: scale(1.05);
|
| 152 |
+
# }
|
| 153 |
+
# .caption {
|
| 154 |
+
# text-align: center;
|
| 155 |
+
# font-size: 16px;
|
| 156 |
+
# color: #444;
|
| 157 |
+
# margin-top: 5px;
|
| 158 |
+
# font-weight: 500;
|
| 159 |
+
# }
|
| 160 |
+
# </style>
|
| 161 |
+
# """, unsafe_allow_html=True)
|
| 162 |
+
|
| 163 |
+
# # Display in 3-column grid
|
| 164 |
+
# for i in range(0, len(images), 3):
|
| 165 |
+
# cols = st.columns(3)
|
| 166 |
+
# for j, col in enumerate(cols):
|
| 167 |
+
# if i + j < len(images):
|
| 168 |
+
# img_file, caption = images[i + j]
|
| 169 |
+
# img = Image.open(base_path + img_file)
|
| 170 |
+
# with col:
|
| 171 |
+
# st.markdown('<div class="gallery-img">', unsafe_allow_html=True)
|
| 172 |
+
# st.image(img, use_container_width=True)
|
| 173 |
+
# st.markdown('</div>', unsafe_allow_html=True)
|
| 174 |
+
# st.markdown(f'<div class="caption">{caption}</div>', unsafe_allow_html=True)
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
# # --- Contact ---
|
| 179 |
+
# elif selected == "Contact":
|
| 180 |
+
# st.title("Contact Us 📞")
|
| 181 |
+
# st.markdown("""
|
| 182 |
+
# **📍 Address:** RV University, Bengaluru
|
| 183 |
+
# **📧 Email:** happytails.rvu@example.com
|
| 184 |
+
# **📱 Phone:** +91 98800 92264
|
| 185 |
+
# """)
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
# # --- FAQs ---
|
| 190 |
+
# elif selected == "FAQs":
|
| 191 |
+
# st.title("Frequently Asked Questions ❓")
|
| 192 |
+
|
| 193 |
+
# with st.expander("How do I adopt a pet?"):
|
| 194 |
+
# st.markdown("Just go to the 'Adopt a Pet' section, choose your companion, and fill the form (coming soon).")
|
| 195 |
+
|
| 196 |
+
# with st.expander("Is there an adoption fee?"):
|
| 197 |
+
# st.markdown("Yes, a minimal fee is charged to cover vaccinations and care.")
|
| 198 |
+
|
| 199 |
+
# with st.expander("Can I visit the pets in person?"):
|
| 200 |
+
# st.markdown("Absolutely! Visit us at RV University between 10AM to 6PM.")
|
| 201 |
+
|
| 202 |
+
# # --- Footer ---
|
| 203 |
+
# st.markdown("""<hr style="border: 0.5px solid #ccc;" />""", unsafe_allow_html=True)
|
| 204 |
+
# st.markdown(
|
| 205 |
+
# "<center>© 2025 Happy Tails | Built with ❤️ by RVU Students</center>",
|
| 206 |
+
# unsafe_allow_html=True
|
| 207 |
+
# )
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
import streamlit as st
|
| 211 |
+
from streamlit_option_menu import option_menu
|
| 212 |
+
from PIL import Image
|
| 213 |
+
import random
|
| 214 |
+
import os
|
| 215 |
+
import base64
|
| 216 |
+
|
| 217 |
+
# App configuration
|
| 218 |
+
st.set_page_config(page_title="Happy Tails", page_icon="🐾", layout="wide")
|
| 219 |
+
|
| 220 |
+
# Sidebar menu
|
| 221 |
+
with st.sidebar:
|
| 222 |
+
selected = option_menu("Happy Tails", ["Home", "Adopt a Pet", "Pet Care Tips", "Gallery", "Contact", "FAQs"],
|
| 223 |
+
icons=["house", "paw", "heart", "camera", "envelope", "question-circle"],
|
| 224 |
+
default_index=0, orientation="vertical")
|
| 225 |
+
|
| 226 |
+
# Global CSS for styling
|
| 227 |
+
st.markdown("""
|
| 228 |
+
<style>
|
| 229 |
+
.banner {
|
| 230 |
+
background-image: url("https://images.pexels.com/photos/7324407/pexels-photo-7324407.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2");
|
| 231 |
+
|
| 232 |
+
background-size: cover;
|
| 233 |
+
background-position: center;
|
| 234 |
+
height: 400px;
|
| 235 |
+
border-radius: 15px;
|
| 236 |
+
margin-bottom: 30px;
|
| 237 |
+
position: relative;
|
| 238 |
+
}
|
| 239 |
+
.banner-text {
|
| 240 |
+
position: absolute;
|
| 241 |
+
bottom: 20px;
|
| 242 |
+
left: 40px;
|
| 243 |
+
color: white;
|
| 244 |
+
font-size: 40px;
|
| 245 |
+
font-weight: bold;
|
| 246 |
+
text-shadow: 2px 2px 5px #000;
|
| 247 |
+
}
|
| 248 |
+
.gallery-img {
|
| 249 |
+
transition: transform 0.3s ease;
|
| 250 |
+
border-radius: 10px;
|
| 251 |
+
}
|
| 252 |
+
.gallery-img:hover {
|
| 253 |
+
transform: scale(1.05);
|
| 254 |
+
}
|
| 255 |
+
.caption {
|
| 256 |
+
text-align: center;
|
| 257 |
+
font-size: 16px;
|
| 258 |
+
color: #444;
|
| 259 |
+
margin-top: 5px;
|
| 260 |
+
font-weight: 500;
|
| 261 |
+
}
|
| 262 |
+
</style>
|
| 263 |
+
""", unsafe_allow_html=True)
|
| 264 |
+
|
| 265 |
+
# Home Page
|
| 266 |
+
if selected == "Home":
|
| 267 |
+
st.markdown('<div class="banner"><div class="banner-text">🐾 Every Dog Deserves a Family</div></div>', unsafe_allow_html=True)
|
| 268 |
+
|
| 269 |
+
st.title("Welcome to Happy Tails")
|
| 270 |
+
st.subheader("A loving space for every paw.")
|
| 271 |
+
st.markdown("""
|
| 272 |
+
**Happy Tails** is a pet adoption and care center dedicated to finding loving homes for rescued pets.
|
| 273 |
+
We offer resources for pet parents, adoption services, and plenty of wagging tails!
|
| 274 |
+
""")
|
| 275 |
+
|
| 276 |
+
st.markdown("## 🐶 Our Impact")
|
| 277 |
+
col1, col2 = st.columns(2)
|
| 278 |
+
with col1:
|
| 279 |
+
st.subheader("🐾 Pets Adopted")
|
| 280 |
+
st.metric(label="Since Launch", value=random.randint(100, 500))
|
| 281 |
+
with col2:
|
| 282 |
+
st.subheader("😊 Happy Customers")
|
| 283 |
+
st.metric(label="Community Count", value=random.randint(200, 1000))
|
| 284 |
+
|
| 285 |
+
# Adopt Page
|
| 286 |
+
# elif selected == "Adopt a Pet":
|
| 287 |
+
# st.title("Adopt a Pet 🐶🐱")
|
| 288 |
+
# st.markdown("Meet our adorable friends looking for a home.")
|
| 289 |
+
|
| 290 |
+
# col1, col2 = st.columns(3)
|
| 291 |
+
# with col1:
|
| 292 |
+
# st.image("C:/Users/sathy/Downloads/pet/images - Copy/about-1.jpg", width=300)
|
| 293 |
+
# st.markdown("**Name:** Max \n**Breed:** Labrador \n**Age:** 2 years \n**Status:** Available")
|
| 294 |
+
# with col2:
|
| 295 |
+
# st.image("C:/Users/sathy/Downloads/pet/images - Copy/about-2.jpg", width=300)
|
| 296 |
+
# st.markdown("**Name:** Luna \n**Breed:** Persian Cat \n**Age:** 1.5 years \n**Status:** Available")
|
| 297 |
+
# with col3:
|
| 298 |
+
# st.image("C:/Users/sathy/Downloads/pet/images - Copy/about-3.jpg", width=300)
|
| 299 |
+
# st.markdown("**Name:** Bella \n**Breed:** Golden Retriever \n**Age:** 3 years \n**Status:** Available")
|
| 300 |
+
elif selected == "Adopt a Pet":
|
| 301 |
+
st.title("Adopt a Pet 🐶🐱")
|
| 302 |
+
st.markdown("Meet our adorable friends looking for a home.")
|
| 303 |
+
|
| 304 |
+
# Add Roboto Mono font and some styles
|
| 305 |
+
st.markdown("""
|
| 306 |
+
<style>
|
| 307 |
+
@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono&display=swap');
|
| 308 |
+
|
| 309 |
+
.pet-card {
|
| 310 |
+
font-family: 'Roboto Mono', monospace;
|
| 311 |
+
background-color: #f9f9f9;
|
| 312 |
+
padding: 15px;
|
| 313 |
+
margin-bottom: 20px;
|
| 314 |
+
border-radius: 15px;
|
| 315 |
+
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
|
| 316 |
+
text-align: center;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
.pet-img {
|
| 320 |
+
border-radius: 12px;
|
| 321 |
+
margin-bottom: 10px;
|
| 322 |
+
width: 100%;
|
| 323 |
+
height: auto;
|
| 324 |
+
}
|
| 325 |
+
</style>
|
| 326 |
+
""", unsafe_allow_html=True)
|
| 327 |
+
|
| 328 |
+
col1, col2, col3 = st.columns(3)
|
| 329 |
+
|
| 330 |
+
with col1:
|
| 331 |
+
st.markdown('<div class="pet-card">', unsafe_allow_html=True)
|
| 332 |
+
st.image("C:/Users/sathy/Downloads/pet/images - Copy/about-1.jpg", use_container_width=True, caption=None)
|
| 333 |
+
st.markdown("**Name:** Max \n**Breed:** Labrador \n**Age:** 2 years \n**Status:** Available")
|
| 334 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 335 |
+
|
| 336 |
+
with col2:
|
| 337 |
+
st.markdown('<div class="pet-card">', unsafe_allow_html=True)
|
| 338 |
+
st.image("C:/Users/sathy/Downloads/pet/images - Copy/img10.jpg", use_container_width=True, caption=None)
|
| 339 |
+
st.markdown("**Name:** Luna \n**Breed:** Persian Cat \n**Age:** 1.5 years \n**Status:** Available")
|
| 340 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 341 |
+
|
| 342 |
+
with col3:
|
| 343 |
+
st.markdown('<div class="pet-card">', unsafe_allow_html=True)
|
| 344 |
+
st.image("C:/Users/sathy/Downloads/pet/images - Copy/img18.jpg", use_container_width=True, caption=None)
|
| 345 |
+
st.markdown("**Name:** Bella \n**Breed:** Golden Retriever \n**Age:** 3 years \n**Status:** Available")
|
| 346 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 347 |
+
|
| 348 |
+
# Pet Care Tips
|
| 349 |
+
elif selected == "Pet Care Tips":
|
| 350 |
+
st.title("Pet Care Tips 🧼")
|
| 351 |
+
st.markdown("""
|
| 352 |
+
- 🥣 **Nutrition:** Feed a balanced diet.
|
| 353 |
+
- 🧼 **Hygiene:** Regular grooming and vet visits.
|
| 354 |
+
- 🐾 **Exercise:** Walks and playtime every day.
|
| 355 |
+
- 🐕 **Love:** Shower them with affection.
|
| 356 |
+
""")
|
| 357 |
+
|
| 358 |
+
# Gallery Page
|
| 359 |
+
# elif selected == "Gallery":
|
| 360 |
+
# st.title("Happy Faces Gallery 📸")
|
| 361 |
+
|
| 362 |
+
# images = [
|
| 363 |
+
# ("about-1.jpg", "pug"),
|
| 364 |
+
# ("max.jpg", "Max"),
|
| 365 |
+
# ("img2.jpg", "Coco"),
|
| 366 |
+
# ("img8.jpg", "Charlie & Mento"),
|
| 367 |
+
# ("luna.jpg", "Luna"),
|
| 368 |
+
# ("rocky.jpg", "Rocky"),
|
| 369 |
+
# ]
|
| 370 |
+
# base_path = "C:/Users/sathy/Downloads/pet/images - Copy/"
|
| 371 |
+
|
| 372 |
+
# for i in range(0, len(images), 3):
|
| 373 |
+
# cols = st.columns(3)
|
| 374 |
+
# for j, col in enumerate(cols):
|
| 375 |
+
# if i + j < len(images):
|
| 376 |
+
# img_file, caption = images[i + j]
|
| 377 |
+
# img = Image.open(base_path + img_file)
|
| 378 |
+
# with col:
|
| 379 |
+
# st.markdown('<div class="gallery-img">', unsafe_allow_html=True)
|
| 380 |
+
# st.image(img, use_container_width=True)
|
| 381 |
+
# st.markdown('</div>', unsafe_allow_html=True)
|
| 382 |
+
# st.markdown(f'<div class="caption">{caption}</div>', unsafe_allow_html=True)
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
elif selected == "Gallery":
|
| 387 |
+
st.title("Happy Faces Gallery 📸")
|
| 388 |
+
|
| 389 |
+
# Inject Roboto Mono font and some custom styles
|
| 390 |
+
st.markdown("""
|
| 391 |
+
<style>
|
| 392 |
+
@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono&display=swap');
|
| 393 |
+
|
| 394 |
+
.gallery-img {
|
| 395 |
+
padding: 10px;
|
| 396 |
+
text-align: center;
|
| 397 |
+
}
|
| 398 |
+
.caption {
|
| 399 |
+
font-family: 'Roboto Mono', monospace;
|
| 400 |
+
font-size: 16px;
|
| 401 |
+
color: #444;
|
| 402 |
+
margin-top: 8px;
|
| 403 |
+
}
|
| 404 |
+
</style>
|
| 405 |
+
""", unsafe_allow_html=True)
|
| 406 |
+
|
| 407 |
+
images = [
|
| 408 |
+
("about-1.jpg", "pug"),
|
| 409 |
+
("max.jpg", "Max"),
|
| 410 |
+
("img2.jpg", "Coco"),
|
| 411 |
+
("img8.jpg", "Charlie & Mento"),
|
| 412 |
+
("luna.jpg", "Luna"),
|
| 413 |
+
("rocky.jpg", "Rocky"),
|
| 414 |
+
]
|
| 415 |
+
|
| 416 |
+
base_path = "C:/Users/sathy/Downloads/pet/images - Copy/"
|
| 417 |
+
|
| 418 |
+
for i in range(0, len(images), 3):
|
| 419 |
+
cols = st.columns(3)
|
| 420 |
+
for j, col in enumerate(cols):
|
| 421 |
+
if i + j < len(images):
|
| 422 |
+
img_file, caption = images[i + j]
|
| 423 |
+
full_path = os.path.join(base_path, img_file)
|
| 424 |
+
try:
|
| 425 |
+
img = Image.open(full_path)
|
| 426 |
+
with col:
|
| 427 |
+
st.markdown('<div class="gallery-img">', unsafe_allow_html=True)
|
| 428 |
+
st.image(img, use_container_width=True)
|
| 429 |
+
st.markdown(f'<div class="caption">{caption}</div>', unsafe_allow_html=True)
|
| 430 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 431 |
+
except FileNotFoundError:
|
| 432 |
+
with col:
|
| 433 |
+
st.warning(f"Image not found: {img_file}")
|
| 434 |
+
|
| 435 |
+
# Contact Page
|
| 436 |
+
elif selected == "Contact":
|
| 437 |
+
st.title("Contact Us 📞")
|
| 438 |
+
st.markdown("""
|
| 439 |
+
**📍 Address:** RV University, Bengaluru
|
| 440 |
+
**📧 Email:** happytails.rvu@example.com
|
| 441 |
+
**📱 Phone:** +91 98800 92264
|
| 442 |
+
""")
|
| 443 |
+
|
| 444 |
+
# FAQ Page
|
| 445 |
+
elif selected == "FAQs":
|
| 446 |
+
st.title("Frequently Asked Questions ❓")
|
| 447 |
+
|
| 448 |
+
with st.expander("How do I adopt a pet?"):
|
| 449 |
+
st.markdown("Just go to the 'Adopt a Pet' section, choose your companion, and fill the form (coming soon).")
|
| 450 |
+
|
| 451 |
+
with st.expander("Is there an adoption fee?"):
|
| 452 |
+
st.markdown("Yes, a minimal fee is charged to cover vaccinations and care.")
|
| 453 |
+
|
| 454 |
+
with st.expander("Can I visit the pets in person?"):
|
| 455 |
+
st.markdown("Absolutely! Visit us at RV University between 10AM to 6PM.")
|
| 456 |
+
|
| 457 |
+
# Footer
|
| 458 |
+
st.markdown("""<hr style="border: 0.5px solid #ccc;" />""", unsafe_allow_html=True)
|
| 459 |
+
st.markdown(
|
| 460 |
+
"<center>© 2025 Happy Tails | Built with ❤️ by RVU Students</center>",
|
| 461 |
+
unsafe_allow_html=True
|
| 462 |
+
)
|
pet/pet/pet_images/dog-5059910_1280.jpg
ADDED
|
Git LFS Details
|
pet/pet/utils/__pycache__/mongo_utils.cpython-312.pyc
ADDED
|
Binary file (2.27 kB). View file
|
|
|
pet/pet/utils/mongo_utils.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from bson import ObjectId
|
| 2 |
+
from database import pet_collection, request_collection
|
| 3 |
+
|
| 4 |
+
# PET FUNCTIONS
|
| 5 |
+
def get_all_pets(query={}):
|
| 6 |
+
return list(pet_collection.find(query))
|
| 7 |
+
|
| 8 |
+
def get_pet_by_id(pet_id):
|
| 9 |
+
return pet_collection.find_one({"_id": ObjectId(pet_id)})
|
| 10 |
+
|
| 11 |
+
def add_pet(pet_data):
|
| 12 |
+
pet_collection.insert_one(pet_data)
|
| 13 |
+
|
| 14 |
+
def update_pet(pet_id, update_data):
|
| 15 |
+
pet_collection.update_one({"_id": ObjectId(pet_id)}, {"$set": update_data})
|
| 16 |
+
|
| 17 |
+
def delete_pet(pet_id):
|
| 18 |
+
pet_collection.delete_one({"_id": ObjectId(pet_id)})
|
| 19 |
+
|
| 20 |
+
# ADOPTION REQUEST FUNCTIONS
|
| 21 |
+
def get_all_requests():
|
| 22 |
+
return list(request_collection.find())
|
| 23 |
+
|
| 24 |
+
# def update_request_status(request_id, status):
|
| 25 |
+
# request_collection.update_one({"_id": ObjectId(request_id)}, {"$set": {"status": status}})
|
| 26 |
+
|
| 27 |
+
# def mark_pet_as_adopted(pet_id):
|
| 28 |
+
# pet_collection.update_one({"_id": ObjectId(pet_id)}, {"$set": {"status": "adopted"}})
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def mark_pet_as_adopted(pet_id):
|
| 32 |
+
# Mark pet as unavailable and set status (optional)
|
| 33 |
+
pet_collection.update_one(
|
| 34 |
+
{"_id": ObjectId(pet_id)},
|
| 35 |
+
{"$set": {"available": False, "status": "adopted"}}
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# --- ADOPTION REQUEST FUNCTIONS ---
|
| 39 |
+
|
| 40 |
+
def add_adoption_request(request_data):
|
| 41 |
+
request_collection.insert_one(request_data)
|
| 42 |
+
|
| 43 |
+
def update_request_status(request_id, status):
|
| 44 |
+
request_collection.update_one(
|
| 45 |
+
{"_id": ObjectId(request_id)},
|
| 46 |
+
{"$set": {"status": status}}
|
| 47 |
+
)
|
| 48 |
+
|