Spaces:
Runtime error
Runtime error
Upload intro.py
Browse files- page/intro.py +139 -0
page/intro.py
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import collections
|
2 |
+
from numpy.core.defchararray import lower
|
3 |
+
import streamlit as st
|
4 |
+
import numpy as np
|
5 |
+
import pandas as pd
|
6 |
+
import zipfile
|
7 |
+
import io
|
8 |
+
import os
|
9 |
+
from streamlit.elements.image import image_to_url
|
10 |
+
import gzip
|
11 |
+
import requests
|
12 |
+
from io import BytesIO
|
13 |
+
from PIL import Image, ImageDraw
|
14 |
+
import base64
|
15 |
+
import datetime
|
16 |
+
import random, os, time
|
17 |
+
import threading
|
18 |
+
|
19 |
+
|
20 |
+
#List of files to use for each image object, 40 images total
|
21 |
+
files = [None]*40
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
def randomFile(ix):
|
26 |
+
|
27 |
+
path = r"exampleImages"
|
28 |
+
|
29 |
+
dd = list(os.listdir(path))
|
30 |
+
random.shuffle(dd)
|
31 |
+
|
32 |
+
#Parse through each file in directory
|
33 |
+
for file in dd:
|
34 |
+
|
35 |
+
#If file is not in files list, use it for next image
|
36 |
+
if file not in files:
|
37 |
+
|
38 |
+
files[ix] = file
|
39 |
+
return "exampleImages/"+file
|
40 |
+
|
41 |
+
def gen(_p):
|
42 |
+
|
43 |
+
|
44 |
+
if(_p is not False):
|
45 |
+
st.session_state.prompt = _p
|
46 |
+
st.session_state.page = 0
|
47 |
+
return
|
48 |
+
|
49 |
+
_1 = ["A modern ","A post-modern ","A classical ", "A parametric ", "A contemporary ", "A minimalist "]
|
50 |
+
_2 = ["museum architecture","home architecture","landscape architecture","interior design","structural architecture"]
|
51 |
+
_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"]
|
52 |
+
_4 = [" photograph",", watercolor painting",", oil painting", ", digital art"]
|
53 |
+
|
54 |
+
st.session_state.prompt = str(random.choice(_1)+random.choice(_2)+random.choice(_3)+random.choice(_4))
|
55 |
+
st.session_state.page = 0
|
56 |
+
|
57 |
+
|
58 |
+
def app():
|
59 |
+
|
60 |
+
#Array of image objects
|
61 |
+
images = []
|
62 |
+
|
63 |
+
for i in range(30):
|
64 |
+
files.append( randomFile(i) )
|
65 |
+
|
66 |
+
placeholder = st.empty()
|
67 |
+
|
68 |
+
with placeholder.container():
|
69 |
+
|
70 |
+
columns = [col1, col2, col3, col4, col5] = st.columns(5)
|
71 |
+
|
72 |
+
ix = 0
|
73 |
+
for column in columns:
|
74 |
+
with column:
|
75 |
+
for i in range(2):
|
76 |
+
images.append( st.empty() )
|
77 |
+
|
78 |
+
with images[ix].container():
|
79 |
+
st.image("exampleImages/"+files[ix])
|
80 |
+
|
81 |
+
ix += 1
|
82 |
+
|
83 |
+
|
84 |
+
st.title('AI-Generated Architecture')
|
85 |
+
|
86 |
+
prompt = st.text_input(label="Describe the architecture you want to see",value="An oil painting of a modern architecture")
|
87 |
+
|
88 |
+
c1,c2,c3 = st.columns(3)
|
89 |
+
|
90 |
+
with c1:
|
91 |
+
if st.button("Generate Architecture"):
|
92 |
+
if prompt:
|
93 |
+
gen(prompt)
|
94 |
+
elif prompt == "":
|
95 |
+
gen(False)
|
96 |
+
return
|
97 |
+
|
98 |
+
|
99 |
+
with c2:
|
100 |
+
if st.button("Random Prompt"):
|
101 |
+
gen(False)
|
102 |
+
return
|
103 |
+
|
104 |
+
st.text("")
|
105 |
+
|
106 |
+
|
107 |
+
columns2 = [col1, col2, col3, col4, col5] = st.columns(5)
|
108 |
+
|
109 |
+
|
110 |
+
for column in columns2:
|
111 |
+
with column:
|
112 |
+
for i in range(4):
|
113 |
+
|
114 |
+
images.append( st.empty() )
|
115 |
+
|
116 |
+
with images[ix].container():
|
117 |
+
st.image("exampleImages/"+files[ix])
|
118 |
+
|
119 |
+
ix += 1
|
120 |
+
|
121 |
+
last = -1
|
122 |
+
|
123 |
+
while(True):
|
124 |
+
ch = random.randrange(30)
|
125 |
+
with images[ch].container():
|
126 |
+
st.image(randomFile(ch))
|
127 |
+
time.sleep(0.33)
|
128 |
+
|
129 |
+
|
130 |
+
|
131 |
+
#download_thread = threading.Thread(target=background, name="Downloader")
|
132 |
+
#download_thread.start()
|
133 |
+
|
134 |
+
|
135 |
+
|
136 |
+
|
137 |
+
|
138 |
+
|
139 |
+
|