Spaces:
Sleeping
Sleeping
File size: 6,948 Bytes
4ab6643 |
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 |
import streamlit as st
from pymongo import MongoClient
import os
from dotenv import load_dotenv
load_dotenv()
import time
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
AWS_BUCKET_NAME = os.getenv("AWS_BUCKET_NAME")
MONGO_URI = os.getenv("MONGO_URI")
DB_NAME = os.getenv("DB_NAME")
COLLECTION_NAME = os.getenv("COMPANY_COLLECTION_NAME")
mongo_client = MongoClient(MONGO_URI)
db = mongo_client[DB_NAME]
collection = db[COLLECTION_NAME]
def upload_main_page():
#
if st.button("Back",key="Back_button"):
st.session_state.page = "home"
st.rerun()
st.markdown("---")
col1, col2 = st.columns([1,6])
with col1:
if st.button("Upload Image",key="upload_image_button"):
st.session_state.page="upload_image"
st.rerun()
# Placeholder for image upload function
with col2:
if st.button("View Images",key="view_image_button"):
st.session_state.page = "view_image"
st.rerun()
# Row 2: Buttons for PDF actions
col3, col4 = st.columns([1,6])
with col3:
if st.button("Upload PDF",key="upload_pdf_button"):
st.session_state.page="upload_pdf"
st.rerun()
with col4:
if st.button("View PDFs",key="view_pdf_button"):
st.session_state.page="view_pdf"
st.rerun()
# Line break
st.markdown("---")
# Section for company description
st.subheader("Tell us about your company in a few lines")
# Fetch the "about_company" document from MongoDB
about_company_doc = collection.find_one({"type": "about_company"})
if about_company_doc and "company_description" in about_company_doc:
# If company_description exists, show it and allow for updates
st.write("### Current Description")
st.write(about_company_doc["company_description"]) # Display current description (non-editable)
# Show an empty text box for new input
new_description = st.text_area("Enter new description to update", "")
if st.button("Update",key="update_company"):
# Update the company description in MongoDB
collection.update_one(
{"_id": about_company_doc["_id"]},
{"$set": {"company_description": new_description}}
)
st.success("Company description updated successfully.")
time.sleep(3)
st.rerun()
else:
# If company_description does not exist, show an empty text box for initial input
new_description = st.text_area("Enter company description", "")
if st.button("Save",key="save_description"):
# Insert a new company description field in MongoDB
if about_company_doc:
# Update the existing document
collection.update_one(
{"_id": about_company_doc["_id"]},
{"$set": {"company_description": new_description}}
)
else:
# Insert a new document if it doesn't exist
collection.insert_one({"type": "about_company", "company_description": new_description})
st.success("Company description saved successfully.")
st.markdown("---")
# Section for adding and displaying tags
st.subheader("Manage Tags and Categories")
# Part 1: Tags
st.write("#### Add Tags")
# Fetch tags document
tags_doc = collection.find_one({"type": "tags"})
current_tags = tags_doc["tags"] if tags_doc and "tags" in tags_doc else []
# Display current tags with horizontal alignment and black-blue text color
if current_tags:
st.write("Current Tags:")
tag_html = " ".join([
f"<span style='display: inline-block; padding: 5px 10px; margin: 5px; border-radius: 15px; background-color: #e0e0e0; color: #0000FF;'>{tag}</span>"
for tag in current_tags
])
st.markdown(tag_html, unsafe_allow_html=True)
else:
st.write("No tags available.")
# Input box to add new tags
new_tags = st.text_input("Enter new tags separated by commas", "")
if st.button("Add Tags",key="add_tags"):
# Split the input tags by commas, strip whitespace, and remove any duplicates
tags_to_add = list(set([tag.strip() for tag in new_tags.split(",") if tag.strip()]))
# Update the MongoDB document with new tags
if tags_doc:
# Update the existing tags document
collection.update_one(
{"_id": tags_doc["_id"]},
{"$addToSet": {"tags": {"$each": tags_to_add}}}
)
else:
# Insert a new tags document if it doesn't exist
collection.insert_one({"type": "tags", "tags": tags_to_add})
st.success("Tags added successfully.")
st.rerun() # Refresh the page to display updated tags
# Part 2: Categories
st.write("#### Add Categories")
# Fetch categories document
categories_doc = collection.find_one({"type": "categories"})
current_categories = categories_doc["categories"] if categories_doc and "categories" in categories_doc else []
# Display current categories with horizontal alignment and black-blue text color
if current_categories:
st.write("Current Categories:")
category_html = " ".join([
f"<span style='display: inline-block; padding: 5px 10px; margin: 5px; border-radius: 15px; background-color: #e0e0e0; color: #0000FF;'>{category}</span>"
for category in current_categories
])
st.markdown(category_html, unsafe_allow_html=True)
else:
st.write("No categories available.")
# Input box to add new categories
new_categories = st.text_input("Enter new categories separated by commas", "")
if st.button("Add Categories",key="add_categories"):
# Split the input categories by commas, strip whitespace, and remove any duplicates
categories_to_add = list(set([category.strip() for category in new_categories.split(",") if category.strip()]))
# Update the MongoDB document with new categories
if categories_doc:
# Update the existing categories document
collection.update_one(
{"_id": categories_doc["_id"]},
{"$addToSet": {"categories": {"$each": categories_to_add}}}
)
else:
# Insert a new categories document if it doesn't exist
collection.insert_one({"type": "categories", "categories": categories_to_add})
st.success("Categories added successfully.")
st.rerun() # Refresh the page to display updated categories
|