awacke1 commited on
Commit
b4b04d4
ยท
verified ยท
1 Parent(s): 90307a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -35
app.py CHANGED
@@ -1,52 +1,50 @@
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
 
 
 
 
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
+ # Assuming the dataset has the columns 'cityOrState', 'link', and 'linkType'
33
  item = dataset['train'][st.session_state.index]
34
+ cityOrState = item['cityOrState']
35
  link = item['link']
36
+ linkType = item['linkType']
37
+
38
+ # Build the HTML for the current record
39
+ links_html = f"""
40
+ <ul style="list-style: none; padding: 0;">
41
+ <li style="margin: 10px 0; padding: 10px; background-color: #f0f0f0; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);">
42
+ <a href="{link}" target="_blank" style="text-decoration: none; color: #333;">
43
+ <strong>{cityOrState}</strong> - {linkType} ๐Ÿ”—
44
+ </a>
45
+ </li>
46
+ </ul>
47
+ """
48
+
49
+ # Use Streamlit components to render the HTML
50
+ components.html(links_html, height=100)