awacke1 commited on
Commit
e29354c
·
verified ·
1 Parent(s): b9e24c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -38
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
- # Navigation buttons
16
- col1, col2, col3, col4, col5 = st.columns(5)
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
- with col5:
29
- if st.button('⏭️'):
30
- st.session_state.index = max_index
31
-
32
- # Generate the A-Frame scene HTML with links from the dataset
33
- aframe_html = """
34
- <a-scene embedded style="width: 800px; height: 600px;">
35
- <a-sky color="#ECECEC"></a-sky>
36
- """
37
-
38
- # Loop through the dataset and create a-link entities for each record
39
- for index, item in enumerate(dataset['train']):
40
- cityOrState = item['cityOrState']
41
- link = item['link']
42
- linkType = item['linkType']
43
- position = f"{index * 1.5} 1.25 -3" # Simple positioning logic
44
- aframe_html += f"""
45
- <a-link href="{link}" position="{position}" title="{cityOrState} - {linkType}" image="#homeThumbnail"></a-link>
46
- """
47
-
48
- # Close the A-Scene tag
49
- aframe_html += "</a-scene>"
50
-
51
- # Use Streamlit components to render the A-Frame HTML
52
- components.html(aframe_html, height=600)
 
 
 
 
 
 
 
 
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