awacke1 commited on
Commit
00b370d
·
1 Parent(s): a584b9a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ import streamlit as st
3
+
4
+ # Define the list of jokes
5
+ jokes = [
6
+ "Why couldn't the bicycle stand up by itself? Because it was two-tired.",
7
+ "Why did the tomato turn red? Because it saw the salad dressing!",
8
+ "Why did the chicken cross the playground? To get to the other slide!",
9
+ "Why did the teddy bear say no to dessert? Because it was already stuffed!",
10
+ "Why do seagulls fly over the sea? Because if they flew over the bay, they'd be bagels!",
11
+ "Why did the scarecrow win an award? Because he was outstanding in his field!",
12
+ "Why do elephants never use computers? Because they're afraid of mice!",
13
+ "Why do bees have sticky hair? Because they use honeycombs!",
14
+ "Why did the cookie go to the doctor? Because it was feeling crummy!",
15
+ "Why did the hipster burn his tongue? Because he drank his coffee before it was cool!",
16
+ "Why don't scientists trust atoms? Because they make up everything!",
17
+ "Why don't zombies eat brains? Because they're on a no-brain diet!",
18
+ "Why did the banana go to the doctor? Because it wasn't peeling well!",
19
+ "Why did the tomato turn green? Because it saw the salad dressing!",
20
+ "Why did the chicken go to the seance? To talk to the other side!",
21
+ "Why did the teddy bear say no to candy? Because it was trying to be a little bit bear-y!",
22
+ "Why don't sharks live in the jungle? Because they can't climb trees!",
23
+ "Why did the scarecrow go to the gym? To work on his straw-nth!",
24
+ "Why did the computer go to the doctor? Because it had a virus!",
25
+ "Why did the pencil go to the doctor? Because it had a broken lead!"
26
+ ]
27
+
28
+ # Define the UI elements
29
+ st.title("No Pun Intended Joke Book for Kids")
30
+
31
+ if st.button("Tell Me a Joke!"):
32
+ # Randomly select a joke
33
+ joke = random.choice(jokes)
34
+ st.write(joke)
35
+
36
+ # Define the file IO elements
37
+ st.header("File IO for Jokes")
38
+
39
+ # Load the jokes from a text file
40
+ with st.beta_expander("Load Jokes"):
41
+ uploaded_file = st.file_uploader("Choose a file")
42
+ if uploaded_file is not None:
43
+ jokes = uploaded_file.read().decode().split("\n")
44
+ st.success("Loaded {} jokes from the file!".format(len(jokes)))
45
+
46
+ # Save the jokes to a text file
47
+ with st.beta_expander("Save Jokes"):
48
+ uploaded_file = st.file_uploader("Choose a file")
49
+ if uploaded_file is not None:
50
+ uploaded_file.write("\n".join(jokes))
51
+ st.success("Saved {} jokes to the file!".format(len(jokes)))