add on page & off page

#4
by notjulietxd - opened
Files changed (1) hide show
  1. pages/output.py +69 -2
pages/output.py CHANGED
@@ -59,6 +59,59 @@ def write_table(website_and_tools_data):
59
  st.warning("No data retrieved for analysis.")
60
  # --- End: Loop and display data ---
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
 
64
  def display_outputs():
@@ -104,7 +157,7 @@ In line with this, we have looked into the technology used by **{client_name}**
104
  With several businesses out there all vying for the same eyeballs, it’s never been more important to advertise online, and search engine marketing is the most effective way to promote need-based, high-investment products and services such as solar energy services.\n
105
  Currently, {client_name} has already explored numerous online advertising. Its competitors are also experienced in PPC in multiple platforms. """)
106
 
107
- # Write W&T Table
108
  sem_data = get_analyst_response("SEM PPC Analyst")
109
  write_table(sem_data)
110
 
@@ -114,11 +167,25 @@ Currently, {client_name} has already explored numerous online advertising. Its c
114
  st.markdown(f"""The purpose of Search Engine Optimization (SEO) is to strategically rearrange the website’s pages, attributes, content, and structure so that the website appears as high as possible in the results list displayed by search engines like Google, Bing, and Yahoo! when certain queries are entered by an internet user. Since high ranking positions are generally earned and worked for, ranking on the first page promotes trust between you and the search engine as well as to ultimately receive organic visibility with your users.\n
115
  There are two types of SEO based on where the optimization is implemented: On-page SEO (which refers to any type of optimization done within the website) and Off-page SEO (which is often called Link Building or Link Acquisition – the process of getting more “votes” for the website through other domains). Both are essential in increasing a website’s visibility in search results pages and in ranking for more business-related keywords. """)
116
 
117
- # Write W&T Table
118
  seo_data = get_analyst_response("SEO Analyst")
119
  write_table(seo_data)
120
 
121
  st.markdown("---")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
  if st.button("Back to Dashboard"):
124
  st.switch_page("pages/home.py")
 
59
  st.warning("No data retrieved for analysis.")
60
  # --- End: Loop and display data ---
61
 
62
+ def seo_on_page_table(df_data):
63
+
64
+ if df_data:
65
+ try:
66
+
67
+ parsed_data = df_data
68
+
69
+ if isinstance(parsed_data, list):
70
+ # Create Markdown table header
71
+ markdown_table = "| Element | Description | Remarks |\n"
72
+ markdown_table += "|---|---|---|\n"
73
+
74
+ # Loop through the list of dictionaries
75
+ for item in parsed_data:
76
+ # Use .get() for safety in case keys are missing
77
+ element = item.get('elements', 'N/A')
78
+ description = item.get('description', 'Static information')
79
+ remarks = item.get('remarks', 'N/A')
80
+
81
+ # Add a row to the Markdown table string
82
+ # Replace underscores with spaces and apply title case to element
83
+ element_formatted = element.replace('_', ' ').title()
84
+ description_formatted = description.replace('_', ' ')
85
+ remarks_formatted = remarks.replace('_', ' ')
86
+
87
+ markdown_table += f"| {element_formatted} | {description_formatted} | {remarks_formatted} |\n"
88
+
89
+
90
+ # Display the complete Markdown table
91
+ st.markdown(markdown_table)
92
+
93
+ # Handle case if data is not a list (e.g., a single dictionary)
94
+ elif isinstance(parsed_data, dict):
95
+ st.write("Analysis Result (Summary):")
96
+ # You might want to display dictionary data differently
97
+ st.json(parsed_data) # Example: Display as JSON
98
+ else:
99
+ st.warning("data is not in the expected list format.")
100
+ st.write(parsed_data) # Show the raw data
101
+
102
+ except json.JSONDecodeError:
103
+ st.error("Error: Could not parse the data as JSON.")
104
+ st.text(df_data) # Show the raw string data
105
+ except AttributeError:
106
+ st.error("Error: Could not find expected keys ('category', 'current_footprint', 'best_of_breed_solution') in the data.")
107
+ st.write(parsed_data) # Show the data that caused the error
108
+ except Exception as e:
109
+ st.error(f"An unexpected error occurred while processing data: {e}")
110
+ st.write(df_data) # Show the raw data
111
+ else:
112
+ st.warning("No data retrieved for analysis.")
113
+ # --- End: Loop and display data ---
114
+
115
 
116
 
117
  def display_outputs():
 
157
  With several businesses out there all vying for the same eyeballs, it’s never been more important to advertise online, and search engine marketing is the most effective way to promote need-based, high-investment products and services such as solar energy services.\n
158
  Currently, {client_name} has already explored numerous online advertising. Its competitors are also experienced in PPC in multiple platforms. """)
159
 
160
+ # Write SEM Table
161
  sem_data = get_analyst_response("SEM PPC Analyst")
162
  write_table(sem_data)
163
 
 
167
  st.markdown(f"""The purpose of Search Engine Optimization (SEO) is to strategically rearrange the website’s pages, attributes, content, and structure so that the website appears as high as possible in the results list displayed by search engines like Google, Bing, and Yahoo! when certain queries are entered by an internet user. Since high ranking positions are generally earned and worked for, ranking on the first page promotes trust between you and the search engine as well as to ultimately receive organic visibility with your users.\n
168
  There are two types of SEO based on where the optimization is implemented: On-page SEO (which refers to any type of optimization done within the website) and Off-page SEO (which is often called Link Building or Link Acquisition – the process of getting more “votes” for the website through other domains). Both are essential in increasing a website’s visibility in search results pages and in ranking for more business-related keywords. """)
169
 
170
+ # Write SEO Table
171
  seo_data = get_analyst_response("SEO Analyst")
172
  write_table(seo_data)
173
 
174
  st.markdown("---")
175
+
176
+ # Write On Page Table
177
+ st.markdown("### ON-PAGE OPTIMIZATION")
178
+ on_page_data = get_analyst_response("On Page Analyst")
179
+ seo_on_page_table(on_page_data)
180
+
181
+ st.markdown("---")
182
+
183
+ # Write Off Page Table
184
+ st.markdown("### OFF PAGE OPTIMIZATION")
185
+ on_page_data = get_analyst_response("Off Page Analyst")
186
+ seo_on_page_table(on_page_data)
187
+
188
+ st.markdown("---")
189
 
190
  if st.button("Back to Dashboard"):
191
  st.switch_page("pages/home.py")