import streamlit as st from PIL import Image # Define pages pages = { 'page1': { 'text': "You are a brave hero on a quest to save the princess. You must travel through a dangerous forest to reach the castle where she is being held captive. Do you want to go left or right?", 'left': 'page2', 'right': 'page3', 'image': 'forest.jpg' }, 'page2': { 'text': "You chose to go left. You come across a river. Do you want to swim across or build a raft?", 'left': 'page4', 'right': 'page5', 'image': 'river.jpg' }, 'page3': { 'text': "You chose to go right. You come across a pack of wolves. Do you want to fight them or run away?", 'left': 'page6', 'right': 'page7', 'image': 'wolves.jpg' }, 'page4': { 'text': "You chose to swim across. You make it to the other side safely.", 'left': 'page8', 'right': 'page8', 'image': 'swim.jpg' }, 'page5': { 'text': "You chose to build a raft. It takes a while, but you eventually make it across the river safely.", 'left': 'page8', 'right': 'page8', 'image': 'raft.jpg' }, 'page6': { 'text': "You chose to fight the wolves. You defeat them, but you sustain some injuries in the process.", 'left': 'page8', 'right': 'page8', 'image': 'fight.jpg' }, 'page7': { 'text': "You chose to run away. You escape the wolves, but you get lost in the forest.", 'left': 'page8', 'right': 'page8', 'image': 'run.jpg' }, 'page8': { 'text': "You continue on your journey and eventually reach the castle where the princess is being held. You rescue her and she rewards you with a chest full of gold.", 'left': None, 'right': None, 'image': 'castle.jpg' } } # Define show_page function def show_page(page_name): page = pages[page_name] image = Image.open(page['image']) st.image(image, caption='', use_column_width=True) st.write(page['text']) if page['left'] is not None: if st.button('Go left'): show_page(page['left']) if page['right'] is not None: if st.button('Go right'): show_page(page['right']) # Render initial page show_page('page1')