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 | |
# 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) |