Skip to content

Instantly share code, notes, and snippets.

@wfng92
Created October 19, 2021 08:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wfng92/9dc26a12ded0359c31887052e11ef8ff to your computer and use it in GitHub Desktop.
Save wfng92/9dc26a12ded0359c31887052e11ef8ff to your computer and use it in GitHub Desktop.
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