Spaces:
Runtime error
Runtime error
#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 | |
# Load the dataset | |
quotes = pd.read_csv('quotes.csv', index_col=0) | |
# Start the Streamlit App | |
st.title('Quote Generator') | |
# 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) | |
#add three search buttons to search the dataframe columns | |
search_quote = st.text_input(label='Search Quote') | |
search_author = st.text_input(label='Search Author') | |
search_category = st.text_input(label='Search Category') | |
if st.button('Search'): | |
quotes_search = quotes[quotes['quote'].str.contains(search_quote, case=False)] | |
quotes_search1 = quotes_search[quotes_search['author'].str.contains(search_author, case=False)] | |
quotes_search2 = quotes_search1[quotes_search1['category'].str.contains(search_category, case=False)].head(1000) | |
st.write(quotes_search2) |