Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
|
4 |
+
# Define pages
|
5 |
+
pages = {
|
6 |
+
'page1': {
|
7 |
+
'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?",
|
8 |
+
'left': 'page2',
|
9 |
+
'right': 'page3',
|
10 |
+
'image': 'forest.jpg'
|
11 |
+
},
|
12 |
+
'page2': {
|
13 |
+
'text': "You chose to go left. You come across a river. Do you want to swim across or build a raft?",
|
14 |
+
'left': 'page4',
|
15 |
+
'right': 'page5',
|
16 |
+
'image': 'river.jpg'
|
17 |
+
},
|
18 |
+
'page3': {
|
19 |
+
'text': "You chose to go right. You come across a pack of wolves. Do you want to fight them or run away?",
|
20 |
+
'left': 'page6',
|
21 |
+
'right': 'page7',
|
22 |
+
'image': 'wolves.jpg'
|
23 |
+
},
|
24 |
+
'page4': {
|
25 |
+
'text': "You chose to swim across. You make it to the other side safely.",
|
26 |
+
'left': 'page8',
|
27 |
+
'right': 'page8',
|
28 |
+
'image': 'swim.jpg'
|
29 |
+
},
|
30 |
+
'page5': {
|
31 |
+
'text': "You chose to build a raft. It takes a while, but you eventually make it across the river safely.",
|
32 |
+
'left': 'page8',
|
33 |
+
'right': 'page8',
|
34 |
+
'image': 'raft.jpg'
|
35 |
+
},
|
36 |
+
'page6': {
|
37 |
+
'text': "You chose to fight the wolves. You defeat them, but you sustain some injuries in the process.",
|
38 |
+
'left': 'page8',
|
39 |
+
'right': 'page8',
|
40 |
+
'image': 'fight.jpg'
|
41 |
+
},
|
42 |
+
'page7': {
|
43 |
+
'text': "You chose to run away. You escape the wolves, but you get lost in the forest.",
|
44 |
+
'left': 'page8',
|
45 |
+
'right': 'page8',
|
46 |
+
'image': 'run.jpg'
|
47 |
+
},
|
48 |
+
'page8': {
|
49 |
+
'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.",
|
50 |
+
'left': None,
|
51 |
+
'right': None,
|
52 |
+
'image': 'castle.jpg'
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
+
# Define show_page function
|
57 |
+
def show_page(page_name):
|
58 |
+
page = pages[page_name]
|
59 |
+
image = Image.open(page['image'])
|
60 |
+
st.image(image, caption='', use_column_width=True)
|
61 |
+
st.write(page['text'])
|
62 |
+
if page['left'] is not None:
|
63 |
+
if st.button('Go left'):
|
64 |
+
show_page(page['left'])
|
65 |
+
if page['right'] is not None:
|
66 |
+
if st.button('Go right'):
|
67 |
+
show_page(page['right'])
|
68 |
+
|
69 |
+
# Render initial page
|
70 |
+
show_page('page1')
|