Spaces:
Running
Running
poemsforaphrodite
commited on
Commit
•
2038e8b
1
Parent(s):
3250b31
Update app.py
Browse files
app.py
CHANGED
@@ -287,6 +287,34 @@ def show_dimensions_selector(search_type):
|
|
287 |
key='dimensions_selector'
|
288 |
)
|
289 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
def show_paginated_dataframe(report, rows_per_page=20, model_type='english'):
|
291 |
report['position'] = report['position'].astype(int)
|
292 |
report['impressions'] = pd.to_numeric(report['impressions'], errors='coerce')
|
@@ -299,7 +327,7 @@ def show_paginated_dataframe(report, rows_per_page=20, model_type='english'):
|
|
299 |
|
300 |
def format_relevancy_score(x):
|
301 |
if x is None:
|
302 |
-
return "Calculate
|
303 |
try:
|
304 |
return f"{float(x):.2f}"
|
305 |
except ValueError:
|
@@ -328,7 +356,7 @@ def show_paginated_dataframe(report, rows_per_page=20, model_type='english'):
|
|
328 |
return 0
|
329 |
|
330 |
report['ctr_numeric'] = report['ctr'].apply(safe_float_convert)
|
331 |
-
report['relevancy_score_numeric'] = report['relevancy_score'].apply(lambda x: safe_float_convert(x) if x != "Calculate
|
332 |
|
333 |
sort_column_numeric = sort_column + '_numeric' if sort_column in ['ctr', 'relevancy_score'] else sort_column
|
334 |
report = report.sort_values(by=sort_column_numeric, ascending=ascending)
|
@@ -361,7 +389,11 @@ def show_paginated_dataframe(report, rows_per_page=20, model_type='english'):
|
|
361 |
def update_dataframe():
|
362 |
df_html = report.iloc[start_idx:end_idx].to_html(escape=False, index=False)
|
363 |
df_html = df_html.replace('</table>', ''.join([
|
364 |
-
|
|
|
|
|
|
|
|
|
365 |
for i in range(min(rows_per_page, len(report) - start_idx))]
|
366 |
]) + '</table>')
|
367 |
dataframe_placeholder.markdown(df_html, unsafe_allow_html=True)
|
@@ -389,7 +421,6 @@ def show_paginated_dataframe(report, rows_per_page=20, model_type='english'):
|
|
389 |
update_dataframe() # Update the dataframe display
|
390 |
|
391 |
return report
|
392 |
-
|
393 |
# -------------
|
394 |
# Main Streamlit App Function
|
395 |
# -------------
|
@@ -440,7 +471,7 @@ def main():
|
|
440 |
st.session_state.report_data = fetch_gsc_data(webproperty, search_type, start_date, end_date, selected_dimensions)
|
441 |
|
442 |
if st.session_state.report_data is not None and not st.session_state.report_data.empty:
|
443 |
-
st.write("Data fetched successfully. Click 'Calculate' in the Relevancy Score column to calculate the score for each row.")
|
444 |
st.session_state.report_data = show_paginated_dataframe(st.session_state.report_data, model_type=model_type)
|
445 |
download_csv_link(st.session_state.report_data)
|
446 |
elif st.session_state.report_data is not None:
|
|
|
287 |
key='dimensions_selector'
|
288 |
)
|
289 |
|
290 |
+
import datetime
|
291 |
+
import base64
|
292 |
+
import os
|
293 |
+
|
294 |
+
import streamlit as st
|
295 |
+
from streamlit_elements import elements
|
296 |
+
from google_auth_oauthlib.flow import Flow
|
297 |
+
from googleapiclient.discovery import build
|
298 |
+
from dotenv import load_dotenv
|
299 |
+
import pandas as pd
|
300 |
+
import searchconsole
|
301 |
+
import cohere
|
302 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
303 |
+
import requests
|
304 |
+
from bs4 import BeautifulSoup
|
305 |
+
|
306 |
+
# ... (keep the existing imports and configuration)
|
307 |
+
|
308 |
+
# -------------
|
309 |
+
# Data Processing Functions
|
310 |
+
# -------------
|
311 |
+
|
312 |
+
# ... (keep existing functions)
|
313 |
+
|
314 |
+
# -------------
|
315 |
+
# Streamlit UI Components
|
316 |
+
# -------------
|
317 |
+
|
318 |
def show_paginated_dataframe(report, rows_per_page=20, model_type='english'):
|
319 |
report['position'] = report['position'].astype(int)
|
320 |
report['impressions'] = pd.to_numeric(report['impressions'], errors='coerce')
|
|
|
327 |
|
328 |
def format_relevancy_score(x):
|
329 |
if x is None:
|
330 |
+
return '<button class="calculate-btn">Calculate</button>'
|
331 |
try:
|
332 |
return f"{float(x):.2f}"
|
333 |
except ValueError:
|
|
|
356 |
return 0
|
357 |
|
358 |
report['ctr_numeric'] = report['ctr'].apply(safe_float_convert)
|
359 |
+
report['relevancy_score_numeric'] = report['relevancy_score'].apply(lambda x: safe_float_convert(x) if x != '<button class="calculate-btn">Calculate</button>' else -1)
|
360 |
|
361 |
sort_column_numeric = sort_column + '_numeric' if sort_column in ['ctr', 'relevancy_score'] else sort_column
|
362 |
report = report.sort_values(by=sort_column_numeric, ascending=ascending)
|
|
|
389 |
def update_dataframe():
|
390 |
df_html = report.iloc[start_idx:end_idx].to_html(escape=False, index=False)
|
391 |
df_html = df_html.replace('</table>', ''.join([
|
392 |
+
'<style>',
|
393 |
+
'.calculate-btn { cursor: pointer; padding: 5px 10px; background-color: #4CAF50; color: white; border: none; border-radius: 4px; }',
|
394 |
+
'.calculate-btn:hover { background-color: #45a049; }',
|
395 |
+
'</style>',
|
396 |
+
*[f'<script>document.getElementsByTagName("table")[0].rows[{i+1}].cells[6].onclick = function(e) {{ if(e.target.classList.contains("calculate-btn")) calculate_relevancy({start_idx + i}) }}</script>'
|
397 |
for i in range(min(rows_per_page, len(report) - start_idx))]
|
398 |
]) + '</table>')
|
399 |
dataframe_placeholder.markdown(df_html, unsafe_allow_html=True)
|
|
|
421 |
update_dataframe() # Update the dataframe display
|
422 |
|
423 |
return report
|
|
|
424 |
# -------------
|
425 |
# Main Streamlit App Function
|
426 |
# -------------
|
|
|
471 |
st.session_state.report_data = fetch_gsc_data(webproperty, search_type, start_date, end_date, selected_dimensions)
|
472 |
|
473 |
if st.session_state.report_data is not None and not st.session_state.report_data.empty:
|
474 |
+
st.write("Data fetched successfully. Click the 'Calculate' button in the Relevancy Score column to calculate the score for each row.")
|
475 |
st.session_state.report_data = show_paginated_dataframe(st.session_state.report_data, model_type=model_type)
|
476 |
download_csv_link(st.session_state.report_data)
|
477 |
elif st.session_state.report_data is not None:
|