ai_architecture / page /generate.py
JMalott's picture
Update page/generate.py
29b03c5
raw
history blame
3.84 kB
import collections
from numpy.core.defchararray import lower
import streamlit as st
import numpy as np
import pandas as pd
import streamlit as st
import pandas as pd
import numpy as np
import os, random, time
from utils import footer, generate, drawGrid, generate2
from PIL import Image
mode = "ai"
#mode = "dummy"
def app():
global _prompt
st.title('AI-Generated Architecture')
#st.subheader('(beta v1.1)')
#st.text('This is a working beta version with bugs. Known issues are:\n-Some images will grey out when you change the input parameters')
st.subheader('Describe a building, interior, or other architecture you would like to see. You can change the prompt and input parameters on the fly.')
#Modern architecture museum with black brick and large windows.
print("Prompt: "+st.session_state.prompt)
prompt = st.text_input(label="",value=st.session_state.prompt)
st.text("")
#with st.expander("Having trouble thinking of something? Click here to view examples."):
# st.write("""
# • Modern architecture museum with black brick and large windows.\n
# • A prosaic, simple architecture.\n
# • An urban, post-modern architecture with concrete and steel.\n
# • A sleek urban interior design.
# """)
st.text("")
crazy = st.slider('Temperature. This controls how "crazy" generated images are, where 0 is the least crazy.', 0.0, 1.0, 0.75)
k = st.slider('Top K. The higher the value, the higher quality the results tend to be at the cost of extra processing time.', 1, 10, 5)
#k = k*400
if( 'results' not in st.session_state ):
st.session_state.results = []
c1,c2 = st.columns(2)
with c1:
holder = st.empty()
with c2:
holder2 = st.empty()
startButton = holder.button("Start")
already = []
if startButton or hasattr(st.session_state, 'load_state') or st.session_state.prompt is not None:
with st.spinner("Generating..."):
holder.empty()
st.session_state.load_state = True
placeholder = st.empty()
second = st.empty()
nextButton = False
randomButton = False
f = True
ii = 0
while len(st.session_state.results) <= 128:
ii += 1
if(f and len(st.session_state.results) > 0):
f = False
randomButton = holder2.button("randomize prompt")
nextButton = holder.button("finished generating images")
with second.container():
drawGrid()
with placeholder.container():
st.session_state.bar = placeholder.progress(0)
if(len(st.session_state.results) > 0 and nextButton):
st.session_state.page = 1
break
if(randomButton):
randomButton = False
_1 = ["A modern ","A post-modern ","An ultramodern ", "A classical ", "A parametric ", "A contemporary ", "A minimalist "]
_2 = ["museum architecture","home architecture","landscape architecture","interior design","structure architecture"]
_3 = [""," in the style of I.M. Pei"," in the style of Frank Gehry"," in the style of John Lautner"," in the style of Frank Lloyd Wright"]
_4 = [" photograph",", watercolor painting",", oil painting", ", digital art"]
prompt = str(random.choice(_1)+random.choice(_2)+random.choice(_3)+random.choice(_4))
st.session_state.prompt = prompt
generate(prompt,crazy,k)
st.session_state.bar = st.container()