poemsforaphrodite commited on
Commit
885e4ad
1 Parent(s): 07135b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -28
app.py CHANGED
@@ -481,22 +481,10 @@ def show_tabular_data(df, co):
481
  for col, header in zip(cols, headers):
482
  col.write(f"**{header}**")
483
 
484
- def truncate_url(url, max_length=50):
485
- parsed_url = urllib.parse.urlparse(url)
486
- base_url = f"{parsed_url.scheme}://{parsed_url.netloc}"
487
- path = parsed_url.path
488
- if len(base_url) + len(path) > max_length:
489
- return base_url + path[:max_length - len(base_url) - 3] + '...'
490
- return base_url + path
491
-
492
- def make_clickable(url):
493
- truncated_url = truncate_url(url)
494
- return f'<a href="{url}" target="_blank">{truncated_url}</a>'
495
-
496
  # Display each row
497
  for index, row in df.iloc[start_idx:end_idx].iterrows():
498
  cols = st.columns([3, 2, 1, 1, 1, 1, 1, 1])
499
- cols[0].markdown(make_clickable(row['page']), unsafe_allow_html=True)
500
  cols[1].write(row['query'])
501
  cols[2].write(row['clicks'])
502
  cols[3].write(row['impressions'])
@@ -588,24 +576,13 @@ def show_paginated_dataframe(report, rows_per_page=20):
588
 
589
  report['ctr'] = report['ctr'].apply(format_ctr)
590
  report['relevancy_score'] = report['relevancy_score'].apply(format_relevancy_score)
591
- def truncate_url(url, max_length=5):
592
- parsed_url = urllib.parse.urlparse(url)
593
- base_url = f"{parsed_url.scheme}://{parsed_url.netloc}"
594
- path = parsed_url.path
595
- print(base_url)
596
- print(path)
597
- if len(base_url) + len(path) > max_length:
598
- return base_url + path[:max_length - len(base_url) - 3] + '...'
599
- return base_url + path
600
-
601
  def make_clickable(url):
602
- truncated_url = truncate_url(url)
603
- print(truncated_url)
604
- return f'<a href="{url}" target="_blank">{truncated_url}</a>'
605
 
606
- report['page'] = report['page'].apply(make_clickable)
607
 
608
- columns = ['page', 'query', 'impressions', 'clicks', 'ctr', 'position', 'relevancy_score']
609
  report = report[columns]
610
 
611
  sort_column = st.selectbox("Sort by:", columns[1:], index=columns[1:].index('impressions'))
 
481
  for col, header in zip(cols, headers):
482
  col.write(f"**{header}**")
483
 
 
 
 
 
 
 
 
 
 
 
 
 
484
  # Display each row
485
  for index, row in df.iloc[start_idx:end_idx].iterrows():
486
  cols = st.columns([3, 2, 1, 1, 1, 1, 1, 1])
487
+ cols[0].write(row['page'])
488
  cols[1].write(row['query'])
489
  cols[2].write(row['clicks'])
490
  cols[3].write(row['impressions'])
 
576
 
577
  report['ctr'] = report['ctr'].apply(format_ctr)
578
  report['relevancy_score'] = report['relevancy_score'].apply(format_relevancy_score)
579
+
 
 
 
 
 
 
 
 
 
580
  def make_clickable(url):
581
+ return f'<a href="{url}" target="_blank">{url}</a>'
 
 
582
 
583
+ report['clickable_url'] = report['page'].apply(make_clickable)
584
 
585
+ columns = ['clickable_url', 'query', 'impressions', 'clicks', 'ctr', 'position', 'relevancy_score']
586
  report = report[columns]
587
 
588
  sort_column = st.selectbox("Sort by:", columns[1:], index=columns[1:].index('impressions'))