Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,18 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
import time
|
3 |
-
|
4 |
|
5 |
-
#
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
-
#
|
120 |
-
def
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
-
#
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
display_quote(index)
|
128 |
|
129 |
-
#
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
st.experimental_rerun()
|
134 |
|
135 |
-
#
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|