Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#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.
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
+
import pandas as pd
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
# Load the dataset
|
8 |
+
quotes = pd.read_csv('quotes.csv', index_col=0)
|
9 |
+
|
10 |
+
# Start the Streamlit App
|
11 |
+
st.title('Quote Generator')
|
12 |
+
|
13 |
+
# Generate a random set of ten quotes
|
14 |
+
quotes_random = quotes.sample(10)
|
15 |
+
st.write(quotes_random)
|
16 |
+
|
17 |
+
# On the sidebar, give user a button to regenerate the random list of ten quotes
|
18 |
+
if st.button('Regenerate Quotes'):
|
19 |
+
quotes_random = quotes.sample(10)
|
20 |
+
st.write(quotes_random)
|
21 |
+
|
22 |
+
# Search textbox and button with the default value for the quote search to be courage
|
23 |
+
search_term = st.text_input(label='Search Term', value='courage')
|
24 |
+
if st.button('Search'):
|
25 |
+
quotes_search = quotes[quotes['text'].str.contains(search_term, case=False)].head(1000)
|
26 |
+
st.write(quotes_search)
|