File size: 1,657 Bytes
f937044
 
 
e29354c
f937044
 
 
 
e29354c
da0f43e
 
e29354c
 
da0f43e
 
 
 
e29354c
 
da0f43e
e29354c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import streamlit as st
from datasets import load_dataset
import streamlit.components.v1 as components
import requests

# Load the dataset
dataset = load_dataset("awacke1/DatasetOfDatasetsUSA")

# Initialize session state for record navigation and autoplay
if 'index' not in st.session_state:
    st.session_state.index = 0
if 'autoplay' not in st.session_state:
    st.session_state.autoplay = False

# Define the maximum index as the length of the dataset - 1
max_index = len(dataset['train']) - 1

def advance_record():
    if st.session_state.index < max_index:
        st.session_state.index += 1
    else:
        st.session_state.autoplay = False  # Stop when reaching the end of the dataset

# Autoplay control
col1, col2 = st.columns([1, 10])
with col1:
    if st.button('โ–ถ๏ธ Play'):
        st.session_state.autoplay = not st.session_state.autoplay
        if st.session_state.autoplay:
            st.experimental_rerun()

# If autoplay is enabled, advance the record every second
if st.session_state.autoplay:
    st.session_state.time = st.session_state.get('time', 0) + 1
    st.write(f"Autoplaying... Record {st.session_state.index + 1} of {max_index + 1}")
    st.experimental_rerun()
    advance_record()

item = dataset['train'][st.session_state.index]
link = item['link']

# Fetch and display the HTML content
try:
    response = requests.get(link)
    if response.status_code == 200:
        components.html(response.text, height=600, scrolling=True)
    else:
        st.error(f"Failed to load content from {link}")
except Exception as e:
    st.error(f"An error occurred: {e}")

# Note: Adjust the delay and autoplay logic as needed