|
import streamlit as st |
|
from datasets import load_dataset |
|
import streamlit.components.v1 as components |
|
import requests |
|
|
|
|
|
dataset = load_dataset("awacke1/DatasetOfDatasetsUSA") |
|
|
|
|
|
if 'index' not in st.session_state: |
|
st.session_state.index = 0 |
|
if 'autoplay' not in st.session_state: |
|
st.session_state.autoplay = False |
|
|
|
|
|
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 |
|
|
|
|
|
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 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'] |
|
|
|
|
|
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}") |
|
|
|
|
|
|