awacke1 commited on
Commit
c4c8c89
Β·
verified Β·
1 Parent(s): 352697d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -26
app.py CHANGED
@@ -1,9 +1,18 @@
1
  import streamlit as st
 
 
2
  import time
3
- from io import StringIO # Import StringIO from io module
4
 
5
- # Your list of quotes as a dictionary
6
- quotes = [
 
 
 
 
 
 
 
7
  {"Number": 1, "Quote Topic": "Stages of Life 🌱", "Quote": "Every age unfolds a new lesson. Life's chapters evolve, each teaching us anew."},
8
  {"Number": 2, "Quote Topic": "Stages of Life 🌱", "Quote": "From infancy to twilight, our journey is painted in growth. Every stage shines with its own wisdom."},
9
  {"Number": 3, "Quote Topic": "Identity 🎭", "Quote": "We piece together our identity with experiences. In the vast cosmos, our ever-changing signature is our identity."},
@@ -106,35 +115,68 @@ quotes = [
106
  {"Number": 100, "Quote Topic": "Love ❀️", "Quote": "Through love, we find connection, unity, and the essence of existence."}
107
  ]
108
 
 
 
 
 
 
 
 
 
109
 
 
 
 
 
 
 
 
 
 
110
 
111
- def display_quote(index):
112
- '''Function to display the quote using st.markdown()'''
113
- number = quotes[index]['Number']
114
- topic = quotes[index]['Quote Topic']
115
- quote = quotes[index]['Quote']
116
- st.markdown(f"### {number}. {topic}")
117
- st.markdown(quote)
 
 
 
 
 
 
 
118
 
119
- # Streamlit app
120
- def main():
121
- st.title("Quote Timer")
 
 
 
 
 
 
122
 
123
- # Select a random quote to start
124
- import random
125
- index = random.randint(0, len(quotes)-1)
126
-
127
- display_quote(index)
128
 
129
- # Timer logic
130
- for i in range(15, 0, -1):
131
- # st.write(f"Time left: {i} seconds")
132
- time.sleep(1)
133
- st.experimental_rerun()
134
 
135
- # Display a new quote when timer finishes
136
- index = (index + 1) % len(quotes)
137
- display_quote(index)
 
 
 
 
 
 
138
 
139
  if __name__ == "__main__":
140
  main()
 
1
  import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
  import time
5
+ import random
6
 
7
+ # Load famous quotes dataset
8
+ @st.cache_data
9
+ def load_famous_quotes():
10
+ url = 'https://raw.githubusercontent.com/your-username/your-repo/main/quotes.csv' # Replace with actual URL
11
+ quotes_data = pd.read_csv(url)
12
+ return quotes_data
13
+
14
+ # Predefined custom quotes
15
+ custom_quotes = [
16
  {"Number": 1, "Quote Topic": "Stages of Life 🌱", "Quote": "Every age unfolds a new lesson. Life's chapters evolve, each teaching us anew."},
17
  {"Number": 2, "Quote Topic": "Stages of Life 🌱", "Quote": "From infancy to twilight, our journey is painted in growth. Every stage shines with its own wisdom."},
18
  {"Number": 3, "Quote Topic": "Identity 🎭", "Quote": "We piece together our identity with experiences. In the vast cosmos, our ever-changing signature is our identity."},
 
115
  {"Number": 100, "Quote Topic": "Love ❀️", "Quote": "Through love, we find connection, unity, and the essence of existence."}
116
  ]
117
 
118
+ # Function to display quotes
119
+ def display_quotes(quotes_df):
120
+ st.table(quotes_df[['Quote Topic', 'Quote']])
121
+
122
+ # Main app function
123
+ def main():
124
+ st.title("πŸ“ Super Quote Generator")
125
+ st.write("Welcome to the Super Quote Generator! Enjoy famous and custom quotes with advanced features.")
126
 
127
+ # Initialize session states
128
+ if 'auto_repeat' not in st.session_state:
129
+ st.session_state.auto_repeat = False
130
+ if 'data_source' not in st.session_state:
131
+ st.session_state.data_source = 'Famous Quotes'
132
+ if 'num_quotes' not in st.session_state:
133
+ st.session_state.num_quotes = 10
134
+ if 'quotes_df' not in st.session_state:
135
+ st.session_state.quotes_df = pd.DataFrame()
136
 
137
+ # Sidebar configuration
138
+ with st.sidebar:
139
+ st.header("Settings")
140
+ # Data source selection
141
+ st.session_state.data_source = st.radio("Select Quote Source:", ['Famous Quotes', 'Custom Quotes'])
142
+ # Number of quotes to display
143
+ st.session_state.num_quotes = st.slider("Number of Quotes:", 1, 20, 10)
144
+ # AutoRepeat toggle
145
+ st.session_state.auto_repeat = st.checkbox("AutoRepeat", value=False)
146
+ # Regenerate quotes button
147
+ if st.button('πŸ”„ Regenerate Quotes'):
148
+ regenerate_quotes()
149
+ st.markdown("---")
150
+ st.write("Cite Source for famous quotes dataset: [Kaggle - Quotes](https://www.kaggle.com/datasets/manann/quotes-500k?resource=download)")
151
 
152
+ # Function to regenerate quotes
153
+ def regenerate_quotes():
154
+ if st.session_state.data_source == 'Famous Quotes':
155
+ quotes_data = load_famous_quotes()
156
+ random_quotes = quotes_data.sample(n=st.session_state.num_quotes)
157
+ st.session_state.quotes_df = random_quotes.reset_index(drop=True)
158
+ else:
159
+ random_quotes = random.sample(custom_quotes, st.session_state.num_quotes)
160
+ st.session_state.quotes_df = pd.DataFrame(random_quotes)
161
 
162
+ # Initial load of quotes
163
+ if st.session_state.quotes_df.empty:
164
+ regenerate_quotes()
 
 
165
 
166
+ # Display quotes
167
+ quote_placeholder = st.empty()
168
+ with quote_placeholder.container():
169
+ display_quotes(st.session_state.quotes_df)
 
170
 
171
+ # AutoRepeat functionality
172
+ if st.session_state.auto_repeat:
173
+ interval = st.slider("AutoRepeat Interval (seconds):", 5, 30, 10)
174
+ while st.session_state.auto_repeat:
175
+ time.sleep(interval)
176
+ regenerate_quotes()
177
+ with quote_placeholder.container():
178
+ display_quotes(st.session_state.quotes_df)
179
+ st.experimental_rerun()
180
 
181
  if __name__ == "__main__":
182
  main()