Spaces:
Build error
Build error
website and tools integration
#2
by notjulietxd - opened
Files changed (2)
- helper/data_field.py+21-1
- pages/output.py+63-1
7 unmodified lines8910117 unmodified linesx = mycol.find_one({"data_field": data_src})x = x["result"]["question"]#st.write(x)return x7 unmodified lines89101112131415161718192021222324252627282930317 unmodified linesx = mycol.find_one({"data_field": data_src})x = x["result"]["question"]#st.write(x)return xdef get_analyst_response(data_src):try:mongodb_uri = os.getenv("MONGODB_URI")myclient = MongoClient(mongodb_uri)mydb = myclient.get_database()mycol = mydb["df_response"]x = mycol.find_one({"data_field": data_src},sort=[('timestamp', -1)])if x and "result" in x:return x["result"]else:print(f"No matching document or 'result' field found for data_src: {data_src} in df_response")return None # Return None if no doc or 'result' field foundfinally:if myclient:myclient.close()#
1234567891011121310 unmodified lines242526272829import osimport streamlit as stimport timedef display_outputs():client_name = "RMX Creatives"overview = f"""**{client_name}** is a financial services company based in Auckland, New Zealand, specializing in providing quick and flexible loan solutions for businesses and individuals. Represented by Paul Stone, LoansOne has enlisted ShoreMarketing to perform a deep dive into their digital footprint to have a view of the holistic status of their digital properties and determine how each property can play part in implementing a stronger digital marketing plan.\nThe Digital Marketing Footprint consists of deep-dive research by ShoreMarketing specialists to help the business leaders of LoansOne understand the effectiveness of their existing digital initiatives with the view of giving them an insight to developing a strategy and effectively allocating business resources to digital properties that will give them the best results.\nThis document represents the results of our audit of LoansOne’s digital marketing and management practices. Our audit covered reviews of key digital areas: Website and Tools, PPC/SEM, SEO, Social Media, and Market Places."""# (off_page_thread)# (on_page_thread)10 unmodified linesst.markdown(f"""In today’s digital age, scaling a business is simply impossible without a website. Websites primarily serve as the center for all online conversions, which makes it equally important to guarantee that all pages are optimised to educate all traffic about the brand and ultimately to usher them into conversion. \nIn line with this, we have looked into the technology used by **{client_name}** as well as the different digital channels currently in place to see how they are structured and how they are performing.""")if st.button("Back to Dashboard"):st.switch_page("pages/home.py")1234567891011121314151617181910 unmodified lines3031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091import jsonimport osimport streamlit as stfrom helper.data_field import get_analyst_responseimport timest.set_page_config(layout="centered") # <--- Add this linedef display_outputs():client_name = "RMX Creatives"overview = f"""**{client_name}** is a financial services company based in Auckland, New Zealand, specializing in providing quick and flexible loan solutions for businesses and individuals. Represented by Paul Stone, LoansOne has enlisted ShoreMarketing to perform a deep dive into their digital footprint to have a view of the holistic status of their digital properties and determine how each property can play part in implementing a stronger digital marketing plan.\nThe Digital Marketing Footprint consists of deep-dive research by ShoreMarketing specialists to help the business leaders of LoansOne understand the effectiveness of their existing digital initiatives with the view of giving them an insight to developing a strategy and effectively allocating business resources to digital properties that will give them the best results.\nThis document represents the results of our audit of LoansOne’s digital marketing and management practices. Our audit covered reviews of key digital areas: Website and Tools, PPC/SEM, SEO, Social Media, and Market Places."""website_and_tools_data = get_analyst_response("Website and Tools Analyst")# seo = data_field("SEO")# social_media = data_field("Social Media")# (off_page_thread)# (on_page_thread)10 unmodified linesst.markdown(f"""In today’s digital age, scaling a business is simply impossible without a website. Websites primarily serve as the center for all online conversions, which makes it equally important to guarantee that all pages are optimised to educate all traffic about the brand and ultimately to usher them into conversion. \nIn line with this, we have looked into the technology used by **{client_name}** as well as the different digital channels currently in place to see how they are structured and how they are performing.""")# --- Start: Loop and display data as Markdown table ---if website_and_tools_data:try:# If get_analyst_response returns a JSON string, parse it:# parsed_data = json.loads(website_and_tools_data)# If get_analyst_response returns a Python list/dict directly:parsed_data = website_and_tools_data# Check if the parsed data is a list (expected format for a table)if isinstance(parsed_data, list):# Create Markdown table headermarkdown_table = "| Category | Current Footprint | Best of Breed Solution |\n"markdown_table += "|---|---|---|\n"# Loop through the list of dictionariesfor item in parsed_data:# Use .get() for safety in case keys are missingcategory = item.get('category', 'N/A')current_footprint = item.get('current_footprint', 'N/A')best_of_breed = item.get('best_of_breed_solution', 'N/A')# Add a row to the Markdown table string# Replace underscores with spaces and apply title case to categorycategory_formatted = category.replace('_', ' ').title()current_footprint_formatted = current_footprint.replace('_', ' ')best_of_breed_formatted = best_of_breed.replace('_', ' ')markdown_table += f"| {category_formatted} | {current_footprint_formatted} | {best_of_breed_formatted} |\n"# Display the complete Markdown tablest.markdown(markdown_table)# Handle case if data is not a list (e.g., a single dictionary)elif isinstance(parsed_data, dict):st.write("Website and Tools Analysis Result (Summary):")# You might want to display dictionary data differentlyst.json(parsed_data) # Example: Display as JSONelse:st.warning("Website and Tools data is not in the expected list format.")st.write(parsed_data) # Show the raw dataexcept json.JSONDecodeError:st.error("Error: Could not parse the Website and Tools data as JSON.")st.text(website_and_tools_data) # Show the raw string dataexcept AttributeError:st.error("Error: Could not find expected keys ('category', 'current_footprint', 'best_of_breed_solution') in the data.")st.write(parsed_data) # Show the data that caused the errorexcept Exception as e:st.error(f"An unexpected error occurred while processing Website and Tools data: {e}")st.write(website_and_tools_data) # Show the raw dataelse:st.warning("No data retrieved for Website and Tools analysis.")# --- End: Loop and display data ---if st.button("Back to Dashboard"):st.switch_page("pages/home.py")
helper/data_field.py+21-1
pages/output.py+63-1