import streamlit as st import requests def fetch_chuck_norris_joke(): try: response = requests.get("https://api.chucknorris.io/jokes/random") if response.status_code == 200: joke = response.json()['value'] return joke else: return "Failed to fetch Chuck Norris joke: {}".format(response.status_code) except requests.RequestException as e: return "Error fetching Chuck Norris joke: {}".format(e) def main(): st.title('Chuck Norris Joke Generator') if st.button('Generate Joke'): joke = fetch_chuck_norris_joke() st.write("Chuck Norris Joke:") st.write(joke) if __name__ == "__main__": main()