|
import streamlit as st |
|
from datasets import load_dataset |
|
import pandas as pd |
|
import json |
|
import os |
|
|
|
|
|
dataset = load_dataset("awacke1/DatasetOfDatasetsInternational") |
|
df = pd.DataFrame(dataset['train']) |
|
|
|
|
|
likes_file_path = 'likes_data.json' |
|
|
|
|
|
if os.path.exists(likes_file_path): |
|
with open(likes_file_path, 'r') as file: |
|
likes_history = json.load(file) |
|
else: |
|
likes_history = {} |
|
|
|
|
|
def save_likes_history(): |
|
with open(likes_file_path, 'w') as file: |
|
json.dump(likes_history, file) |
|
|
|
|
|
def update_likes(index): |
|
if index in likes_history: |
|
likes_history[index] += 1 |
|
else: |
|
likes_history[index] = 1 |
|
save_likes_history() |
|
st.experimental_rerun() |
|
|
|
|
|
with st.sidebar: |
|
search_query = st.text_input("π Search", "") |
|
search_button = st.button("Search") |
|
|
|
|
|
if search_query: |
|
filtered_df = df[df.apply(lambda row: search_query.lower() in row.to_string().lower(), axis=1)] |
|
else: |
|
filtered_df = df |
|
|
|
|
|
start_index = 0 |
|
display_limit = 10 |
|
|
|
|
|
if 'index' not in st.session_state: |
|
st.session_state.index = 0 |
|
|
|
|
|
for i in range(st.session_state.index, min(st.session_state.index + display_limit, len(filtered_df))): |
|
item = filtered_df.iloc[i] |
|
cityOrState, link, linkType = item['Country'], item['link'], item['linkType'] |
|
liked = likes_history.get(str(i), 0) |
|
|
|
with st.expander(f"{Country} - {linkType} π"): |
|
st.markdown(f"[{link}]({link})") |
|
like_button = st.button("π Like", key=f"like_{i}") |
|
if like_button: |
|
update_likes(str(i)) |
|
|
|
|
|
prev, _, next = st.columns([1,10,1]) |
|
if prev.button("Previous"): |
|
st.session_state.index = max(0, st.session_state.index - display_limit) |
|
if next.button("Next") and st.session_state.index + display_limit < len(filtered_df): |
|
st.session_state.index += display_limit |
|
|
|
|
|
|
|
|
|
|
|
|