Spaces:
Running
Running
poemsforaphrodite
commited on
Commit
•
36ebc7b
1
Parent(s):
291574f
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import os
|
|
5 |
|
6 |
# Related third-party imports
|
7 |
import streamlit as st
|
8 |
-
from streamlit_elements import elements
|
9 |
from google_auth_oauthlib.flow import Flow
|
10 |
from googleapiclient.discovery import build
|
11 |
from dotenv import load_dotenv
|
@@ -448,15 +448,28 @@ def show_model_type_selector():
|
|
448 |
def show_tabular_data(df, co):
|
449 |
st.write("Data Table with Relevancy Scores")
|
450 |
|
451 |
-
#
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
def calculate_single_relevancy(row):
|
456 |
-
content = fetch_content(row['page'])
|
457 |
-
score = calculate_relevance_score(content, row['query'], co)
|
458 |
-
return score
|
459 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
460 |
# Display column headers
|
461 |
cols = st.columns([3, 2, 1, 1, 1, 1, 1, 1])
|
462 |
headers = ['Page', 'Query', 'Clicks', 'Impressions', 'CTR', 'Position', 'Relevancy Score', 'Competitors']
|
@@ -464,7 +477,7 @@ def show_tabular_data(df, co):
|
|
464 |
col.write(f"**{header}**")
|
465 |
|
466 |
# Display each row
|
467 |
-
for index, row in
|
468 |
cols = st.columns([3, 2, 1, 1, 1, 1, 1, 1])
|
469 |
cols[0].write(row['page'])
|
470 |
cols[1].write(row['query'])
|
@@ -476,17 +489,20 @@ def show_tabular_data(df, co):
|
|
476 |
# Relevancy Score column
|
477 |
if pd.isna(row['relevancy_score']) or row['relevancy_score'] == 0:
|
478 |
if cols[6].button("Calculate", key=f"calc_{index}"):
|
479 |
-
|
480 |
-
|
481 |
-
|
|
|
482 |
st.experimental_rerun()
|
483 |
else:
|
484 |
cols[6].write(f"{row['relevancy_score']:.4f}")
|
485 |
|
486 |
# Competitors column
|
487 |
-
|
|
|
488 |
st.write(f"Competitor Analysis for: {row['query']}")
|
489 |
with st.spinner('Analyzing competitors...'):
|
|
|
490 |
results_df = analyze_competitors(row, co)
|
491 |
|
492 |
# Sort the results by relevancy score in descending order
|
|
|
5 |
|
6 |
# Related third-party imports
|
7 |
import streamlit as st
|
8 |
+
from streamlit_elements import elements, mui, html
|
9 |
from google_auth_oauthlib.flow import Flow
|
10 |
from googleapiclient.discovery import build
|
11 |
from dotenv import load_dotenv
|
|
|
448 |
def show_tabular_data(df, co):
|
449 |
st.write("Data Table with Relevancy Scores")
|
450 |
|
451 |
+
# Pagination
|
452 |
+
rows_per_page = 10
|
453 |
+
total_rows = len(df)
|
454 |
+
total_pages = (total_rows - 1) // rows_per_page + 1
|
|
|
|
|
|
|
|
|
455 |
|
456 |
+
if 'current_page' not in st.session_state:
|
457 |
+
st.session_state.current_page = 1
|
458 |
+
|
459 |
+
# Pagination controls
|
460 |
+
col1, col2, col3 = st.columns([1,3,1])
|
461 |
+
with col1:
|
462 |
+
if st.button("< Prev", disabled=st.session_state.current_page == 1):
|
463 |
+
st.session_state.current_page -= 1
|
464 |
+
with col2:
|
465 |
+
st.write(f"Page {st.session_state.current_page} of {total_pages}")
|
466 |
+
with col3:
|
467 |
+
if st.button("Next >", disabled=st.session_state.current_page == total_pages):
|
468 |
+
st.session_state.current_page += 1
|
469 |
+
|
470 |
+
start_idx = (st.session_state.current_page - 1) * rows_per_page
|
471 |
+
end_idx = start_idx + rows_per_page
|
472 |
+
|
473 |
# Display column headers
|
474 |
cols = st.columns([3, 2, 1, 1, 1, 1, 1, 1])
|
475 |
headers = ['Page', 'Query', 'Clicks', 'Impressions', 'CTR', 'Position', 'Relevancy Score', 'Competitors']
|
|
|
477 |
col.write(f"**{header}**")
|
478 |
|
479 |
# Display each row
|
480 |
+
for index, row in df.iloc[start_idx:end_idx].iterrows():
|
481 |
cols = st.columns([3, 2, 1, 1, 1, 1, 1, 1])
|
482 |
cols[0].write(row['page'])
|
483 |
cols[1].write(row['query'])
|
|
|
489 |
# Relevancy Score column
|
490 |
if pd.isna(row['relevancy_score']) or row['relevancy_score'] == 0:
|
491 |
if cols[6].button("Calculate", key=f"calc_{index}"):
|
492 |
+
with st.spinner('Calculating...'):
|
493 |
+
elements.mui.CircularProgress(size=20)
|
494 |
+
score = calculate_single_relevancy(row)
|
495 |
+
df.at[index, 'relevancy_score'] = score
|
496 |
st.experimental_rerun()
|
497 |
else:
|
498 |
cols[6].write(f"{row['relevancy_score']:.4f}")
|
499 |
|
500 |
# Competitors column
|
501 |
+
competitor_button = cols[7].button("Show Competitors", key=f"comp_{index}", disabled=pd.isna(row['relevancy_score']) or row['relevancy_score'] == 0)
|
502 |
+
if competitor_button:
|
503 |
st.write(f"Competitor Analysis for: {row['query']}")
|
504 |
with st.spinner('Analyzing competitors...'):
|
505 |
+
elements.mui.CircularProgress(size=20)
|
506 |
results_df = analyze_competitors(row, co)
|
507 |
|
508 |
# Sort the results by relevancy score in descending order
|