Upload 2 files
Browse files- joke_app.py +23 -0
- requirements.txt +4 -0
joke_app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
def fetch_jokes():
|
5 |
+
url = 'https://v2.jokeapi.dev/joke/Any?type=single&amount=5'
|
6 |
+
response = requests.get(url)
|
7 |
+
data = response.json()
|
8 |
+
return data['jokes']
|
9 |
+
|
10 |
+
def display_jokes(jokes):
|
11 |
+
for joke in jokes:
|
12 |
+
with st.container():
|
13 |
+
st.markdown(f"**Category**: {joke['category']} | **Safe**: {'Yes' if joke['safe'] else 'No'}", unsafe_allow_html=True)
|
14 |
+
st.info(joke['joke'])
|
15 |
+
|
16 |
+
# Streamlit app
|
17 |
+
st.title('Joke Generator')
|
18 |
+
|
19 |
+
jokes = fetch_jokes()
|
20 |
+
|
21 |
+
st.write("Here are some jokes for you!")
|
22 |
+
|
23 |
+
display_jokes(jokes)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
request
|
3 |
+
json
|
4 |
+
pandas
|