boris commited on
Commit
5d39a05
2 Parent(s): 720a5df 0b4b9a3

Merge pull request #47 from borisdayma/demo-improvements

Browse files

Demo improvements

Former-commit-id: d80c40f0c12dab92a636eda9172fff67511206b4

Files changed (1) hide show
  1. app/app.py +44 -23
app/app.py CHANGED
@@ -3,33 +3,47 @@
3
 
4
  import random
5
  from dalle_mini.backend import ServiceError, get_images_from_backend
6
- from dalle_mini.helpers import captioned_strip
7
 
8
  import streamlit as st
9
 
10
- st.sidebar.title("DALL-E Mini")
11
 
12
- sc = st.sidebar.beta_columns(2)
13
- sc[0].image('../img/logo.png', width=150)
14
- sc[1].write(" ")
15
- sc[1].markdown("Generate images from a text prompt")
 
 
 
 
 
 
 
 
 
 
 
16
  st.sidebar.markdown("""
17
- ##### Dall-E Mini
18
  ___
19
- Dall-E Mini is an AI model that generates images of your prompt!
20
 
21
- Created by Boris Dayma et al. 2021 | [GitHub](https://github.com/borisdayma/dalle-mini) | See [Report](https://wandb.ai/dalle-mini/dalle-mini/reports/DALL-E-mini--Vmlldzo4NjIxODA)
22
- """)
 
 
 
23
 
24
- st.header('DALL-E mini Demo')
25
- st.subheader('Generate images from a text prompt')
26
 
27
  prompt = st.text_input("What do you want to see?")
28
 
29
  #TODO: I think there's an issue where we can't run twice the same inference (not due to caching) - may need to use st.form
30
 
31
- if prompt != "":
32
- st.write(f"Generating candidates for: {prompt}")
 
 
33
 
34
  try:
35
  backend_url = st.secrets["BACKEND_SERVER"]
@@ -39,15 +53,22 @@ if prompt != "":
39
  cols = st.beta_columns(4)
40
  for i, img in enumerate(selected):
41
  cols[i%4].image(img)
 
 
42
 
 
 
43
  except ServiceError as error:
44
- st.write(f"Service unavailable, status: {error.status_code}")
45
  except KeyError:
46
- st.write("""
47
- **Error: BACKEND_SERVER unset**
48
-
49
- Please, create a file called `.streamlit/secrets.toml` inside the app's folder and include a line to configure the server URL:
50
- ```
51
- BACKEND_SERVER="<server url>"
52
- ```
53
- """)
 
 
 
 
3
 
4
  import random
5
  from dalle_mini.backend import ServiceError, get_images_from_backend
 
6
 
7
  import streamlit as st
8
 
9
+ # st.sidebar.title("DALL·E mini")
10
 
11
+ # sc = st.sidebar.beta_columns(2)
12
+ # st.sidebar.image('../img/logo.png', width=150)
13
+ # sc[1].write(" ")
14
+ # st.sidebar.markdown("Generate images from text")
15
+
16
+ st.sidebar.markdown("""
17
+ <style>
18
+ .aligncenter {
19
+ text-align: center;
20
+ }
21
+ </style>
22
+ <p class="aligncenter">
23
+ <img src="https://raw.githubusercontent.com/borisdayma/dalle-mini/main/img/logo.png"/>
24
+ </p>
25
+ """, unsafe_allow_html=True)
26
  st.sidebar.markdown("""
 
27
  ___
28
+ DALL·E mini is an AI model that generates images from any prompt you give!
29
 
30
+ <p style='text-align: center'>
31
+ Created by Boris Dayma et al. 2021
32
+ <a href="https://github.com/borisdayma/dalle-mini">GitHub</a> | <a href="https://wandb.ai/dalle-mini/dalle-mini/reports/DALL-E-mini--Vmlldzo4NjIxODA">Report</a>
33
+ </p>
34
+ """, unsafe_allow_html=True)
35
 
36
+ st.header('DALL·E mini')
37
+ st.subheader('Generate images from text')
38
 
39
  prompt = st.text_input("What do you want to see?")
40
 
41
  #TODO: I think there's an issue where we can't run twice the same inference (not due to caching) - may need to use st.form
42
 
43
+ DEBUG = False
44
+ if prompt != "" or st.session_state.get("again", False):
45
+ container = st.empty()
46
+ container.markdown(f"Generating predictions for: **{prompt}**")
47
 
48
  try:
49
  backend_url = st.secrets["BACKEND_SERVER"]
 
53
  cols = st.beta_columns(4)
54
  for i, img in enumerate(selected):
55
  cols[i%4].image(img)
56
+
57
+ container.markdown(f"**{prompt}**")
58
 
59
+ st.session_state["again"] = st.button('Again!', key='again_button')
60
+
61
  except ServiceError as error:
62
+ container.text(f"Service unavailable, status: {error.status_code}")
63
  except KeyError:
64
+ if DEBUG:
65
+ container.markdown("""
66
+ **Error: BACKEND_SERVER unset**
67
+
68
+ Please, create a file called `.streamlit/secrets.toml` inside the app's folder and include a line to configure the server URL:
69
+ ```
70
+ BACKEND_SERVER="<server url>"
71
+ ```
72
+ """)
73
+ else:
74
+ container.markdown('Error -5, please try again or [report it](mailto:pcuenca-dalle@guenever.net).')