import streamlit as st import requests import base64 example_1 = { "story": "The parade is starting and people line the streets. The folks who live upstairs in the buildings get a good view. The really cool floats are coming next. It's raining harder but no one seems to mind. The people came prepared with umbrellas for this special occasion.The more the parade goes on, the better the displays seem to be. The zoo animals are very well done and everybody is standing in the rain to see them. The man's dog is a bit confused by these animals. Everyone is having a good time watching the parade and chatting with their neighbors.", "entity": "Rhinoceros - on a float in the street", "goal": "Watch a parade from the high vantage point.", "images": [ "https://drive.google.com/uc?export=view&id=1LhLpWAkuIIVDf5jl1E7_DppoHQwl-7P9", "https://drive.google.com/uc?export=view&id=11r_tEEa7QcEkalT_wcZOtOxnaztqtETh", "https://drive.google.com/uc?export=view&id=1NsZpx_otGbh9Jz00A9eyF3xoUfTnvNxH" ] } example_2 = { "story": "There is a place in the world where the most people go to in their holidays they visit the biggest desert where people gets into helicopter and sees the enormous land from above and the warm air they you feel and there are other people who just like to travel by travel by walking with your family and friends.There is a ancient history with that log old cowboys of the western side used to camp there and have fum stories with their family and friends but one day a disaster happened which caused the log get red and rotten and from all over there world tourist goes to that wonderful place.", "entity": "Sand", "goal": "See a beautiful desert landscape.", "images": [ "https://drive.google.com/uc?export=view&id=1DyIOAuMsSy1flFmvB255cT5F3ScI2qfd", "https://drive.google.com/uc?export=view&id=1rn7_WOGfwMoUurHog8DQV5GEIA0kugGB", "https://drive.google.com/uc?export=view&id=112TxpwMDA34EO0Rrleh7XnBG56YN0vHt" ] } class Example: def __init__(self, story, entity, goal, images): self.story = story self.entity = entity self.goal = goal self.images = images self.images_base64 = self.get_images() @st.cache_data def download_image(_self, image_url): return requests.get(image_url).content @st.cache_data def get_base64(_self, img_data): return base64.b64encode(img_data) def get_images(self): return [self.get_base64(self.download_image(image_url)) for image_url in self.images] example_1 = Example(example_1["story"], example_1["entity"], example_1["goal"], example_1["images"]) example_2 = Example(example_2["story"], example_2["entity"], example_2["goal"], example_2["images"])