Spaces:
Sleeping
Sleeping
initial commit
Browse files- app.py +152 -0
- requirements.txt +9 -0
app.py
ADDED
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# coding: utf-8
|
3 |
+
|
4 |
+
|
5 |
+
import pandas as pd
|
6 |
+
import base64
|
7 |
+
import uuid
|
8 |
+
import io
|
9 |
+
import pickle
|
10 |
+
import string
|
11 |
+
import simplejson as json
|
12 |
+
import regex as re
|
13 |
+
from functools import reduce
|
14 |
+
import streamlit as st
|
15 |
+
|
16 |
+
|
17 |
+
chars = string.digits + string.ascii_uppercase + string.ascii_lowercase + '_$'
|
18 |
+
selected_sheet = None
|
19 |
+
|
20 |
+
def compress(g):
|
21 |
+
bs = [int(g[i:i + 2], 16) for i in range(0, len(g), 2)]
|
22 |
+
|
23 |
+
def b64(v, l=4):
|
24 |
+
return ''.join([chars[(v // (64 ** i)) % 64] for i in range(l)][::-1])
|
25 |
+
|
26 |
+
return ''.join([b64(bs[0], 2)] + [b64((bs[i] << 16) + (bs[i + 1] << 8) + bs[i + 2]) for i in range(1, 16, 3)])
|
27 |
+
|
28 |
+
|
29 |
+
def download_button(object_to_download, download_filename, button_text, pickle_it=False):
|
30 |
+
"""
|
31 |
+
Generates a link to download the given object_to_download.
|
32 |
+
Params:
|
33 |
+
------
|
34 |
+
object_to_download: The object to be downloaded.
|
35 |
+
download_filename (str): filename and extension of file. e.g. mydata.csv,
|
36 |
+
some_txt_output.txt download_link_text (str): Text to display for download
|
37 |
+
link.
|
38 |
+
button_text (str): Text to display on download button (e.g. 'click here to download file')
|
39 |
+
pickle_it (bool): If True, pickle file.
|
40 |
+
Returns:
|
41 |
+
-------
|
42 |
+
(str): the anchor tag to download object_to_download
|
43 |
+
Examples:
|
44 |
+
--------
|
45 |
+
download_link(your_df, 'YOUR_DF.csv', 'Click to download data!')
|
46 |
+
download_link(your_str, 'YOUR_STRING.txt', 'Click to download text!')
|
47 |
+
"""
|
48 |
+
if pickle_it:
|
49 |
+
try:
|
50 |
+
object_to_download = pickle.dumps(object_to_download)
|
51 |
+
except pickle.PicklingError as e:
|
52 |
+
st.write(e)
|
53 |
+
return None
|
54 |
+
|
55 |
+
else:
|
56 |
+
if isinstance(object_to_download, bytes):
|
57 |
+
pass
|
58 |
+
|
59 |
+
elif isinstance(object_to_download, pd.DataFrame):
|
60 |
+
#object_to_download = object_to_download.to_csv(index=False)
|
61 |
+
towrite = io.BytesIO()
|
62 |
+
object_to_download = object_to_download.to_excel(
|
63 |
+
towrite,
|
64 |
+
encoding='utf-8',
|
65 |
+
index=False,
|
66 |
+
header=True,
|
67 |
+
na_rep=''
|
68 |
+
)
|
69 |
+
towrite.seek(0)
|
70 |
+
|
71 |
+
# Try JSON encode for everything else
|
72 |
+
else:
|
73 |
+
object_to_download = json.dumps(object_to_download)
|
74 |
+
|
75 |
+
try:
|
76 |
+
# some strings <-> bytes conversions necessary here
|
77 |
+
b64 = base64.b64encode(object_to_download.encode()).decode()
|
78 |
+
|
79 |
+
except AttributeError as e:
|
80 |
+
b64 = base64.b64encode(towrite.read()).decode()
|
81 |
+
|
82 |
+
button_uuid = str(uuid.uuid4()).replace('-', '')
|
83 |
+
button_id = re.sub('\d+', '', button_uuid)
|
84 |
+
|
85 |
+
custom_css = f"""
|
86 |
+
<style>
|
87 |
+
#{button_id} {{
|
88 |
+
display: inline-flex;
|
89 |
+
align-items: center;
|
90 |
+
justify-content: center;
|
91 |
+
background-color: rgb(255, 255, 255);
|
92 |
+
color: rgb(38, 39, 48);
|
93 |
+
padding: .25rem .75rem;
|
94 |
+
position: relative;
|
95 |
+
text-decoration: none;
|
96 |
+
border-radius: 4px;
|
97 |
+
border-width: 1px;
|
98 |
+
border-style: solid;
|
99 |
+
border-color: rgb(230, 234, 241);
|
100 |
+
border-image: initial;
|
101 |
+
}}
|
102 |
+
#{button_id}:hover {{
|
103 |
+
border-color: rgb(246, 51, 102);
|
104 |
+
color: rgb(246, 51, 102);
|
105 |
+
}}
|
106 |
+
#{button_id}:active {{
|
107 |
+
box-shadow: none;
|
108 |
+
background-color: rgb(246, 51, 102);
|
109 |
+
color: white;
|
110 |
+
}}
|
111 |
+
</style> """
|
112 |
+
|
113 |
+
dl_link = custom_css + f'<a download="{download_filename}" id="{button_id}" href="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,{b64}">{button_text}</a><br></br>'
|
114 |
+
|
115 |
+
return dl_link
|
116 |
+
|
117 |
+
|
118 |
+
|
119 |
+
|
120 |
+
cobie_file_button = st.text_input("Dropbox link to COBie file", key="cobie_file_button")
|
121 |
+
|
122 |
+
# In[ ]:
|
123 |
+
|
124 |
+
if cobie_file_button:
|
125 |
+
|
126 |
+
cobie_file_path = st.session_state.cobie_file_button
|
127 |
+
|
128 |
+
if '=0' in cobie_file_path:
|
129 |
+
|
130 |
+
cobie_file_path = cobie_file_path.replace('=0', '=1')
|
131 |
+
|
132 |
+
cobie_file = pd.ExcelFile(cobie_file_path)
|
133 |
+
tabs = pd.ExcelFile("path").sheet_names
|
134 |
+
|
135 |
+
selected_sheet = st.selectbox(
|
136 |
+
'Select sheet for changing revit ids to COBie ids',
|
137 |
+
tabs,
|
138 |
+
)
|
139 |
+
|
140 |
+
|
141 |
+
if selected_sheet:
|
142 |
+
|
143 |
+
df = cobie_file.parse(selected_sheet)
|
144 |
+
|
145 |
+
st.write(df)
|
146 |
+
|
147 |
+
# st.markdown(download_button(df, 'COBieIDs.xlsx', 'Download COBieIDs.xlsx'), unsafe_allow_html=True)
|
148 |
+
|
149 |
+
|
150 |
+
|
151 |
+
|
152 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pandas
|
3 |
+
numpy
|
4 |
+
openpyxl
|
5 |
+
simplejson
|
6 |
+
functools
|
7 |
+
# sqlalchemy
|
8 |
+
# psycopg2-binary
|
9 |
+
# https://www.dropbox.com/s/9yfqtw4qldma1kf/ifc-0.3.18h.tar.gz?dl=1
|