Delete app.py
Browse files
app.py
DELETED
@@ -1,82 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import requests
|
3 |
-
from PIL import Image
|
4 |
-
from io import BytesIO
|
5 |
-
import json
|
6 |
-
|
7 |
-
from prompt_generation import pipeline
|
8 |
-
|
9 |
-
|
10 |
-
# Function to create the page navigation
|
11 |
-
def page_navigation(current_page):
|
12 |
-
col1, col2, col3 = st.columns(3)
|
13 |
-
|
14 |
-
if current_page > 0:
|
15 |
-
with col1:
|
16 |
-
if st.button('<< Previous'):
|
17 |
-
current_page -= 1
|
18 |
-
|
19 |
-
with col2:
|
20 |
-
st.write(f'Step {current_page} of 10')
|
21 |
-
|
22 |
-
if current_page < 10:
|
23 |
-
with col3:
|
24 |
-
if st.button('Next >>'):
|
25 |
-
if current_page == 0:
|
26 |
-
user_input = st.session_state.user_input
|
27 |
-
response = pipeline(user_input, 10)
|
28 |
-
|
29 |
-
st.session_state.pipeline_response = response
|
30 |
-
|
31 |
-
current_page += 1
|
32 |
-
|
33 |
-
return current_page
|
34 |
-
|
35 |
-
|
36 |
-
# Main function to display the pages
|
37 |
-
def get_pipeline_data(page_number):
|
38 |
-
pipeline_response = st.session_state.pipeline_response
|
39 |
-
text_output = pipeline_response.get("steps")[page_number - 1]
|
40 |
-
|
41 |
-
random_img = f"https://picsum.photos/800/600?random={page_number}"
|
42 |
-
response = requests.get(random_img)
|
43 |
-
image = Image.open(BytesIO(response.content))
|
44 |
-
|
45 |
-
return {"text_output": text_output, "image_obj": image}
|
46 |
-
|
47 |
-
|
48 |
-
def main():
|
49 |
-
st.set_page_config(page_title="Narrative chat", layout="wide")
|
50 |
-
st.title("DreamBot")
|
51 |
-
|
52 |
-
# Initialize the current page
|
53 |
-
current_page = st.session_state.get('current_page', 0)
|
54 |
-
|
55 |
-
# Display content for each page
|
56 |
-
if current_page == 0:
|
57 |
-
st.write("Tell me what story you would like me to tell:")
|
58 |
-
user_input = st.text_area("")
|
59 |
-
st.session_state.user_input = user_input
|
60 |
-
|
61 |
-
else:
|
62 |
-
# Retrieve data from random generators
|
63 |
-
data = get_pipeline_data(current_page)
|
64 |
-
text_output = data.get('text_output', '')
|
65 |
-
image = data.get('image_obj', '')
|
66 |
-
|
67 |
-
# Display text output
|
68 |
-
st.write(text_output)
|
69 |
-
|
70 |
-
# Display image output
|
71 |
-
if image:
|
72 |
-
st.image(image, use_column_width=False, width=400)
|
73 |
-
|
74 |
-
# Display page navigation
|
75 |
-
current_page = page_navigation(current_page)
|
76 |
-
|
77 |
-
st.write('current_page:', current_page)
|
78 |
-
st.session_state.current_page = current_page
|
79 |
-
|
80 |
-
|
81 |
-
if __name__ == "__main__":
|
82 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|