Created
October 19, 2021 08:07
-
-
Save wfng92/9dc26a12ded0359c31887052e11ef8ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streamlit as st | |
import requests | |
def fetch(session, url): | |
try: | |
result = session.get(url) | |
return result.json() | |
except Exception: | |
return {} | |
def main(): | |
st.set_page_config(page_title="Example App", page_icon="🤖") | |
st.title("Get Image by Id") | |
session = requests.Session() | |
with st.form("my_form"): | |
index = st.number_input("ID", min_value=0, max_value=100, key="index") | |
submitted = st.form_submit_button("Submit") | |
if submitted: | |
st.write("Result") | |
data = fetch(session, f"https://picsum.photos/id/{index}/info") | |
if data: | |
st.image(data['download_url'], caption=f"Author: {data['author']}") | |
else: | |
st.error("Error") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment