Em4e commited on
Commit
2ecf6a4
·
verified ·
1 Parent(s): 1e7bcd6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -111,13 +111,13 @@ def calculate(df, target_position, conversion_rate, close_rate, mrr_per_customer
111
  ctr = {i: v for i, v in zip(range(1, 11), [0.25,0.15,0.10,0.08,0.06,0.04,0.03,0.02,0.015,0.01])}
112
  ctr.update({i: 0.005 for i in range(11,21)})
113
  get_ctr = lambda p: ctr.get(int(round(p)), 0.005)
 
114
  df['current_ctr'] = df['position'].apply(get_ctr)
115
  df['target_ctr'] = df['position'].apply(lambda x: ctr.get(int(round(target_position)), 0.005))
116
 
117
  df['current_clicks'] = df['impressions'] * df['current_ctr']
118
  df['projected_clicks'] = df['impressions'] * df['target_ctr']
119
  df['incremental_clicks'] = df['projected_clicks'] - df['current_clicks']
120
-
121
  df['avoided_paid_spend'] = df['incremental_clicks'] * df['cpc']
122
 
123
  # Financial calculations
@@ -126,7 +126,6 @@ def calculate(df, target_position, conversion_rate, close_rate, mrr_per_customer
126
 
127
  total_incremental_conversions = df['incremental_clicks'].sum() * (conversion_rate / 100)
128
  total_incremental_customers = total_incremental_conversions * (close_rate / 100)
129
-
130
  incremental_mrr = total_incremental_customers * mrr_per_customer
131
 
132
  # SEO ROI calculation
@@ -164,6 +163,7 @@ if df is not None:
164
  if metrics is not None:
165
  st.write("---")
166
  st.header("📊 SEO Performance Summary")
 
167
  col1, col2, col3 = st.columns(3)
168
  with col1:
169
  st.metric(label="Total Avoided Paid Spend 💰", value=f"${metrics['total_avoided_paid_spend']:,.2f}")
@@ -182,26 +182,30 @@ if df is not None:
182
 
183
  st.write("---")
184
  st.header("Hypothetical Comparison: SEO vs. Additional Ad Spend")
185
- col_ad1, col_ad2 = st.columns(2)
 
 
186
  with col_ad1:
187
  st.metric(label="Incremental MRR from SEO", value=f"${metrics['incremental_mrr']:,.2f}")
 
188
  with col_ad2:
 
 
 
189
  if metrics['incremental_mrr'] > add_spend:
190
- ad_spend_color = "green"
191
- ad_spend_message = "SEO is a better investment!"
192
  else:
193
- ad_spend_color = "red"
194
- ad_spend_message = "Ad Spend is a better investment!"
195
-
196
- # Increased font-size for the 'add_spend' value and added the message
197
  st.markdown(f"""
198
  <div style="text-align: center;">
199
- <p style="font-size: 1.2em; margin-bottom: 0;">Additional Ad Spend</p>
200
- <p style="color:{ad_spend_color}; font-weight:bold; font-size: 2.5em; margin-top: 0;">${add_spend:,.2f}</p>
201
- <p style="font-weight:bold; font-size: 1.5em; color:{ad_spend_color};">{ad_spend_message}</p>
202
  </div>
203
  """, unsafe_allow_html=True)
204
 
 
205
  st.write("---")
206
  st.header("Detailed Keyword Performance") # Kept as st.header for prominence
207
  st.dataframe(df_results[[
 
111
  ctr = {i: v for i, v in zip(range(1, 11), [0.25,0.15,0.10,0.08,0.06,0.04,0.03,0.02,0.015,0.01])}
112
  ctr.update({i: 0.005 for i in range(11,21)})
113
  get_ctr = lambda p: ctr.get(int(round(p)), 0.005)
114
+
115
  df['current_ctr'] = df['position'].apply(get_ctr)
116
  df['target_ctr'] = df['position'].apply(lambda x: ctr.get(int(round(target_position)), 0.005))
117
 
118
  df['current_clicks'] = df['impressions'] * df['current_ctr']
119
  df['projected_clicks'] = df['impressions'] * df['target_ctr']
120
  df['incremental_clicks'] = df['projected_clicks'] - df['current_clicks']
 
121
  df['avoided_paid_spend'] = df['incremental_clicks'] * df['cpc']
122
 
123
  # Financial calculations
 
126
 
127
  total_incremental_conversions = df['incremental_clicks'].sum() * (conversion_rate / 100)
128
  total_incremental_customers = total_incremental_conversions * (close_rate / 100)
 
129
  incremental_mrr = total_incremental_customers * mrr_per_customer
130
 
131
  # SEO ROI calculation
 
163
  if metrics is not None:
164
  st.write("---")
165
  st.header("📊 SEO Performance Summary")
166
+
167
  col1, col2, col3 = st.columns(3)
168
  with col1:
169
  st.metric(label="Total Avoided Paid Spend 💰", value=f"${metrics['total_avoided_paid_spend']:,.2f}")
 
182
 
183
  st.write("---")
184
  st.header("Hypothetical Comparison: SEO vs. Additional Ad Spend")
185
+
186
+ col_ad1, col_ad2, col_advice = st.columns([1, 1, 1]) # Added a third column for advice
187
+
188
  with col_ad1:
189
  st.metric(label="Incremental MRR from SEO", value=f"${metrics['incremental_mrr']:,.2f}")
190
+
191
  with col_ad2:
192
+ st.metric(label="Additional Ad Spend", value=f"${add_spend:,.2f}")
193
+
194
+ with col_advice:
195
  if metrics['incremental_mrr'] > add_spend:
196
+ advice_message = "SEO is a better investment!"
197
+ advice_color = "green"
198
  else:
199
+ advice_message = "Ad Spend may yield higher returns."
200
+ advice_color = "red"
 
 
201
  st.markdown(f"""
202
  <div style="text-align: center;">
203
+ <p style="font-size: 1.2em; margin-bottom: 0;">Advice</p>
204
+ <p style="color:{advice_color}; font-weight:bold; font-size: 1.5em; margin-top: 0;">{advice_message}</p>
 
205
  </div>
206
  """, unsafe_allow_html=True)
207
 
208
+
209
  st.write("---")
210
  st.header("Detailed Keyword Performance") # Kept as st.header for prominence
211
  st.dataframe(df_results[[