Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,52 +1,52 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from datasets import load_dataset
|
| 3 |
import streamlit.components.v1 as components
|
|
|
|
| 4 |
|
| 5 |
# Load the dataset
|
| 6 |
dataset = load_dataset("awacke1/DatasetOfDatasetsUSA")
|
| 7 |
|
| 8 |
-
# Initialize session state for record navigation
|
| 9 |
if 'index' not in st.session_state:
|
| 10 |
st.session_state.index = 0
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Define the maximum index as the length of the dataset - 1
|
| 13 |
max_index = len(dataset['train']) - 1
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
with col1:
|
| 18 |
-
if st.button('โฎ๏ธ'):
|
| 19 |
-
st.session_state.index = 0
|
| 20 |
-
with col2:
|
| 21 |
-
if st.button('โ๏ธ') and st.session_state.index > 0:
|
| 22 |
-
st.session_state.index -= 1
|
| 23 |
-
with col3:
|
| 24 |
-
st.write(f"Record {st.session_state.index + 1} of {max_index + 1}")
|
| 25 |
-
with col4:
|
| 26 |
-
if st.button('โถ๏ธ') and st.session_state.index < max_index:
|
| 27 |
st.session_state.index += 1
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from datasets import load_dataset
|
| 3 |
import streamlit.components.v1 as components
|
| 4 |
+
import requests
|
| 5 |
|
| 6 |
# Load the dataset
|
| 7 |
dataset = load_dataset("awacke1/DatasetOfDatasetsUSA")
|
| 8 |
|
| 9 |
+
# Initialize session state for record navigation and autoplay
|
| 10 |
if 'index' not in st.session_state:
|
| 11 |
st.session_state.index = 0
|
| 12 |
+
if 'autoplay' not in st.session_state:
|
| 13 |
+
st.session_state.autoplay = False
|
| 14 |
|
| 15 |
# Define the maximum index as the length of the dataset - 1
|
| 16 |
max_index = len(dataset['train']) - 1
|
| 17 |
|
| 18 |
+
def advance_record():
|
| 19 |
+
if st.session_state.index < max_index:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
st.session_state.index += 1
|
| 21 |
+
else:
|
| 22 |
+
st.session_state.autoplay = False # Stop when reaching the end of the dataset
|
| 23 |
+
|
| 24 |
+
# Autoplay control
|
| 25 |
+
col1, col2 = st.columns([1, 10])
|
| 26 |
+
with col1:
|
| 27 |
+
if st.button('โถ๏ธ Play'):
|
| 28 |
+
st.session_state.autoplay = not st.session_state.autoplay
|
| 29 |
+
if st.session_state.autoplay:
|
| 30 |
+
st.experimental_rerun()
|
| 31 |
+
|
| 32 |
+
# If autoplay is enabled, advance the record every second
|
| 33 |
+
if st.session_state.autoplay:
|
| 34 |
+
st.session_state.time = st.session_state.get('time', 0) + 1
|
| 35 |
+
st.write(f"Autoplaying... Record {st.session_state.index + 1} of {max_index + 1}")
|
| 36 |
+
st.experimental_rerun()
|
| 37 |
+
advance_record()
|
| 38 |
+
|
| 39 |
+
item = dataset['train'][st.session_state.index]
|
| 40 |
+
link = item['link']
|
| 41 |
+
|
| 42 |
+
# Fetch and display the HTML content
|
| 43 |
+
try:
|
| 44 |
+
response = requests.get(link)
|
| 45 |
+
if response.status_code == 200:
|
| 46 |
+
components.html(response.text, height=600, scrolling=True)
|
| 47 |
+
else:
|
| 48 |
+
st.error(f"Failed to load content from {link}")
|
| 49 |
+
except Exception as e:
|
| 50 |
+
st.error(f"An error occurred: {e}")
|
| 51 |
+
|
| 52 |
+
# Note: Adjust the delay and autoplay logic as needed
|