Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,42 @@
|
|
1 |
-
#write a python streamlit quote generator with a famous quotes dataset. Load the famous quotes dataset from a file in github. When the program starts generate a random set of ten quotes and show them to the user. On the streamlit sidebar give the user a button to regenerate the random list of ten quotes.
|
2 |
-
|
3 |
import streamlit as st
|
4 |
import pandas as pd
|
5 |
import numpy as np
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
#
|
11 |
-
st.title(
|
12 |
-
st.write(
|
13 |
-
st.write('Cite Source for quotes.csv file: https://www.kaggle.com/datasets/manann/quotes-500k?resource=download')
|
14 |
|
15 |
-
#
|
16 |
random_list = np.random.choice(quotes_data.index.values, 10, replace=False)
|
17 |
random_quotes = quotes_data.loc[random_list]
|
18 |
|
19 |
-
#
|
20 |
-
st.
|
21 |
|
22 |
-
|
23 |
-
if st.button('Regenerate Quotes'):
|
24 |
-
random_list = np.random.choice(quotes_data.index.values, 10, replace=False)
|
25 |
-
random_quotes = quotes_data.loc[random_list]
|
26 |
-
st.table(random_quotes)
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
4 |
|
5 |
+
st.set_page_config(layout="wide")
|
6 |
+
|
7 |
+
# Custom CSS for larger font
|
8 |
+
st.markdown("""
|
9 |
+
<style>
|
10 |
+
.stDataFrame {
|
11 |
+
font-size: 20px;
|
12 |
+
}
|
13 |
+
.stMarkdown {
|
14 |
+
font-size: 24px;
|
15 |
+
}
|
16 |
+
</style>
|
17 |
+
""", unsafe_allow_html=True)
|
18 |
+
|
19 |
+
# Load dataset
|
20 |
+
@st.cache_data
|
21 |
+
def load_data():
|
22 |
+
return pd.read_csv('https://raw.githubusercontent.com/manann/quotes-500k/main/quotes.csv', index_col=0)
|
23 |
+
|
24 |
+
quotes_data = load_data()
|
25 |
+
|
26 |
+
# Sidebar
|
27 |
+
st.sidebar.title("π Refresh")
|
28 |
+
if st.sidebar.button("π² New Quotes"):
|
29 |
+
st.rerun()
|
30 |
|
31 |
+
# Main content
|
32 |
+
st.title("π Famous Quotes Generator")
|
33 |
+
st.write("π Here are 10 random famous quotes!")
|
|
|
34 |
|
35 |
+
# Generate random list
|
36 |
random_list = np.random.choice(quotes_data.index.values, 10, replace=False)
|
37 |
random_quotes = quotes_data.loc[random_list]
|
38 |
|
39 |
+
# Display random list
|
40 |
+
st.dataframe(random_quotes[['quote', 'author']], use_container_width=True)
|
41 |
|
42 |
+
st.markdown("π Source: [Kaggle - Quotes 500k](https://www.kaggle.com/datasets/manann/quotes-500k)")
|
|
|
|
|
|
|
|