File size: 1,793 Bytes
782cbaf
 
 
 
 
 
0360845
 
c2fe98c
 
 
 
 
782cbaf
 
 
 
 
 
 
 
 
 
 
 
7194f0d
b3057ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#write a python streamlit quote generator with a famous quotes dataset.  Load the quotes.csv dataset from a file.  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 with a search textbox and button with the default value for the quote search to be courage.  if the search button is used perform a dataframe query on the set of quotes.  If search is used allow retrieval of up to 1000 quotes that have the search keyword anywhere within the text of a single line from the csv file.

import streamlit as st
import pandas as pd
import numpy as np

# Set the max width of the page
st.set_page_config(layout="wide")

st.title("Quotes Generator and Search")
st.write("Search for quotes by author, quote and category")


# Load the dataset
quotes = pd.read_csv('quotes.csv', index_col=0)

# Generate a random set of ten quotes
quotes_random = quotes.sample(10)
st.write(quotes_random)

# On the sidebar, give user a button to regenerate the random list of ten quotes
if st.button('Regenerate Quotes'):
    quotes_random = quotes.sample(10)
    st.write(quotes_random)


# Load CSV File
quotes_df = pd.read_csv("quotes.csv")

# Create a search text field for each
quote = st.text_input("Quote", "courage")
author = st.text_input("Author", "courage")
category = st.text_input("Category", "courage")

# When button is clicked search and find 10 example random quotes
if st.button("Search"):
    # Filtering data
    quotes_df_filtered = quotes_df[
        (quotes_df["quote"].str.contains(quote))
        & (quotes_df["author"].str.contains(author))
        & (quotes_df["category"].str.contains(category))
    ][:10]
    # Show the results
    st.write(quotes_df_filtered)