Pedro Cuenca commited on
Commit
5d07e74
1 Parent(s): 7ef7bd9

Retire demo code, replace with links to new space.

Browse files
Files changed (1) hide show
  1. app/streamlit/app.py +10 -78
app/streamlit/app.py CHANGED
@@ -1,28 +1,7 @@
1
  #!/usr/bin/env python
2
  # coding: utf-8
3
 
4
- import base64
5
- from io import BytesIO
6
-
7
- import requests
8
  import streamlit as st
9
- from PIL import Image
10
-
11
-
12
- class ServiceError(Exception):
13
- def __init__(self, status_code):
14
- self.status_code = status_code
15
-
16
-
17
- def get_images_from_backend(prompt, backend_url):
18
- r = requests.post(backend_url, json={"prompt": prompt})
19
- if r.status_code == 200:
20
- images = r.json()["images"]
21
- images = [Image.open(BytesIO(base64.b64decode(img))) for img in images]
22
- return images
23
- else:
24
- raise ServiceError(r.status_code)
25
-
26
 
27
  st.sidebar.markdown(
28
  """
@@ -56,62 +35,15 @@ Created by Boris Dayma et al. 2021
56
  st.header("DALL·E mini")
57
  st.subheader("Generate images from text")
58
 
59
- prompt = st.text_input("What do you want to see?")
 
 
 
60
 
61
- DEBUG = False
62
- if prompt != "":
63
- container = st.empty()
64
- container.markdown(
65
- f"""
66
- <style> p {{ margin:0 }} div {{ margin:0 }} </style>
67
- <div data-stale="false" class="element-container css-1e5imcs e1tzin5v1">
68
- <div class="stAlert">
69
- <div role="alert" data-baseweb="notification" class="st-ae st-af st-ag st-ah st-ai st-aj st-ak st-g3 st-am st-b8 st-ao st-ap st-aq st-ar st-as st-at st-au st-av st-aw st-ax st-ay st-az st-b9 st-b1 st-b2 st-b3 st-b4 st-b5 st-b6">
70
- <div class="st-b7">
71
- <div class="css-whx05o e13vu3m50">
72
- <div data-testid="stMarkdownContainer" class="css-1ekf893 e16nr0p30">
73
- <img src="https://raw.githubusercontent.com/borisdayma/dalle-mini/main/app/streamlit/img/loading.gif" width="30"/>
74
- Generating predictions for: <b>{prompt}</b>
75
- </div>
76
- </div>
77
- </div>
78
- </div>
79
- </div>
80
- </div>
81
- <small><i>Predictions may take up to 40s under high load. Please stand by.</i></small>
82
- """,
83
- unsafe_allow_html=True,
84
- )
85
 
86
- try:
87
- backend_url = st.secrets["BACKEND_SERVER"]
88
- print(f"Getting selections: {prompt}")
89
- selected = get_images_from_backend(prompt, backend_url)
90
-
91
- margin = 0.1 # for better position of zoom in arrow
92
- n_columns = 3
93
- cols = st.columns([1] + [margin, 1] * (n_columns - 1))
94
- for i, img in enumerate(selected):
95
- cols[(i % n_columns) * 2].image(img)
96
- container.markdown(f"**{prompt}**")
97
-
98
- st.button("Again!", key="again_button")
99
-
100
- except ServiceError as error:
101
- container.text(f"Service unavailable, status: {error.status_code}")
102
- except KeyError:
103
- if DEBUG:
104
- container.markdown(
105
- """
106
- **Error: BACKEND_SERVER unset**
107
-
108
- Please, create a file called `.streamlit/secrets.toml` inside the app's folder and include a line to configure the server URL:
109
- ```
110
- BACKEND_SERVER="<server url>"
111
- ```
112
- """
113
- )
114
- else:
115
- container.markdown(
116
- "Error -5, please try again or [report it](mailto:pcuenca-dalle@guenever.net)."
117
- )
 
1
  #!/usr/bin/env python
2
  # coding: utf-8
3
 
 
 
 
 
4
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  st.sidebar.markdown(
7
  """
 
35
  st.header("DALL·E mini")
36
  st.subheader("Generate images from text")
37
 
38
+ container = st.empty()
39
+ container.markdown(
40
+ f"""
41
+ A new demo with a better model is now available [in this space](https://huggingface.co/spaces/dalle-mini/dalle-mini)! Check it out!
42
 
43
+ For more information about the project, please visit:
44
+ * [Our GitHub repository](https://github.com/borisdayma/dalle-mini).
45
+ * [The project report](https://wandb.ai/dalle-mini/dalle-mini/reports/DALL-E-mini--Vmlldzo4NjIxODA) we wrote during the initial JAX-Flax sprint organized by 🤗 Hugging Face.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
+ Stay tuned for larger and better models, and more technical details!
48
+ """
49
+ )