Spaces:
Runtime error
Runtime error
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': 'Aaron_Wacker_Peter_Paul_Rubens_Masterpieces_muscle_monsters_05402d99-cc69-4f6a-965c-fcb08953aa56.png' | |
}, | |
'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': 'Aaron_Wacker_Peter_Paul_Rubens_Masterpieces_muscle_monsters_05402d99-cc69-4f6a-965c-fcb08953aa56.png' | |
}, | |
'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': 'Aaron_Wacker_Peter_Paul_Rubens_Masterpieces_muscle_monsters_05402d99-cc69-4f6a-965c-fcb08953aa56.png' | |
}, | |
'page4': { | |
'text': "You chose to swim across. You make it to the other side safely.", | |
'left': 'page8', | |
'right': 'page8', | |
'image': 'Aaron_Wacker_Peter_Paul_Rubens_Masterpieces_muscle_monsters_05402d99-cc69-4f6a-965c-fcb08953aa56.png' | |
}, | |
'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': 'Aaron_Wacker_Peter_Paul_Rubens_Masterpieces_muscle_monsters_05402d99-cc69-4f6a-965c-fcb08953aa56.png' | |
}, | |
'page6': { | |
'text': "You chose to fight the wolves. You defeat them, but you sustain some injuries in the process.", | |
'left': 'page8', | |
'right': 'page8', | |
'image': 'Aaron_Wacker_Peter_Paul_Rubens_Masterpieces_muscle_monsters_05402d99-cc69-4f6a-965c-fcb08953aa56.png' | |
}, | |
'page7': { | |
'text': "You chose to run away. You escape the wolves, but you get lost in the forest.", | |
'left': 'page8', | |
'right': 'page8', | |
'image': 'Aaron_Wacker_Peter_Paul_Rubens_Masterpieces_muscle_monsters_05402d99-cc69-4f6a-965c-fcb08953aa56.png' | |
}, | |
'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': 'Aaron_Wacker_Peter_Paul_Rubens_Masterpieces_muscle_monsters_05402d99-cc69-4f6a-965c-fcb08953aa56.png' | |
} | |
} | |
# 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', key=hash(page['left'])): | |
show_page(page['left']) | |
if page['right'] is not None: | |
if st.button('Go right', key=hash(page['right'])): | |
show_page(page['right']) | |
# Render initial page | |
show_page('page1') |