#!/usr/bin/env python
# coding: utf-8
from datetime import datetime
import streamlit as st
from backend import ServiceError, get_images_from_backend, get_model_version
st.sidebar.markdown(
"""
""",
unsafe_allow_html=True,
)
st.sidebar.markdown(
"""
___
DALL·E mini is an AI model that generates images from any prompt you give!
Created by Boris Dayma et al. 2021-2022
GitHub | Project Report
""",
unsafe_allow_html=True,
)
st.header("DALL·E mini")
st.subheader("Generate images from text")
prompt = st.text_input("What do you want to see?")
DEBUG = False
if prompt != "":
container = st.empty()
container.markdown(
f"""
Generating predictions for:
{prompt}
Predictions may take up to 5mn under high load. Please stand by.
""",
unsafe_allow_html=True,
)
try:
backend_url = st.secrets["BACKEND_SERVER"] + "/generate"
selected = get_images_from_backend(prompt, backend_url)
margin = 0.1 # for better position of zoom in arrow
n_columns = 3
cols = st.columns([1] + [margin, 1] * (n_columns - 1))
for i, img in enumerate(selected):
cols[(i % n_columns) * 2].image(img)
container.markdown(f"**{prompt}**")
version_url = st.secrets["BACKEND_SERVER"] + "/version"
version = get_model_version(version_url)
st.sidebar.markdown(
f"{version}", unsafe_allow_html=True
)
st.markdown(
f"""
These results have been obtained using model `{version}` from [an ongoing training run](https://wandb.ai/dalle-mini/dalle-mini/runs/mheh9e55).
"""
)
st.button("Again!", key="again_button")
except ServiceError as error:
container.text(f"Service unavailable, status: {error.status_code}")
except KeyError:
if DEBUG:
container.markdown(
"""
**Error: BACKEND_SERVER unset**
Please, create a file called `.streamlit/secrets.toml` inside the app's folder and include a line to configure the server URL:
```
BACKEND_SERVER=""
```
"""
)
else:
container.markdown(
"Error -5, please try again or [report it](mailto:pcuenca-dalle@guenever.net)."
)