awacke1 commited on
Commit
b7addcc
Β·
verified Β·
1 Parent(s): 98a523c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -16
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
- # load dataset
8
- quotes_data = pd.read_csv('quotes.csv', index_col=0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- # display random list of ten quotes
11
- st.title('Famous Quotes Generator')
12
- st.write('Generate a random list of ten famous quotes!')
13
- st.write('Cite Source for quotes.csv file: https://www.kaggle.com/datasets/manann/quotes-500k?resource=download')
14
 
15
- # generate random list
16
  random_list = np.random.choice(quotes_data.index.values, 10, replace=False)
17
  random_quotes = quotes_data.loc[random_list]
18
 
19
- # display random list
20
- st.table(random_quotes)
21
 
22
- # give user button to regenerate random list
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)")