Spaces:
Sleeping
Sleeping
initial commit
Browse files- .gitignore +1 -0
- app.py +88 -0
- requirements.txt +4 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
*.html
|
app.py
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
+
import requests
|
5 |
+
|
6 |
+
def add_data(
|
7 |
+
key,
|
8 |
+
cobie_file,
|
9 |
+
output_format,
|
10 |
+
):
|
11 |
+
url = "https://cobie-qc-deploy-gh4gtquncq-nw.a.run.app/cobie-qc/file"
|
12 |
+
|
13 |
+
files = {
|
14 |
+
'excel_file': cobie_file,
|
15 |
+
}
|
16 |
+
data = {
|
17 |
+
'key': key,
|
18 |
+
'output_format': output_format,
|
19 |
+
}
|
20 |
+
response = requests.post(
|
21 |
+
url,
|
22 |
+
files=files,
|
23 |
+
data=data,
|
24 |
+
)
|
25 |
+
|
26 |
+
return response
|
27 |
+
|
28 |
+
st.markdown(
|
29 |
+
'''
|
30 |
+
# Operance COBie QC
|
31 |
+
|
32 |
+
Upload a COBie file to check it for errors and return a report.:
|
33 |
+
'''
|
34 |
+
)
|
35 |
+
|
36 |
+
cobie_file = None
|
37 |
+
confirm_check = False
|
38 |
+
cobie_file = st.file_uploader(
|
39 |
+
'Upload cobie file',
|
40 |
+
type=['xlsx'],
|
41 |
+
key='cobie_file',
|
42 |
+
)
|
43 |
+
|
44 |
+
if cobie_file is not None:
|
45 |
+
|
46 |
+
confirm_check = st.button(
|
47 |
+
'Check COBie file',
|
48 |
+
key='confirm_check',
|
49 |
+
)
|
50 |
+
|
51 |
+
if cobie_file is not None and confirm_check:
|
52 |
+
|
53 |
+
spinner = st.spinner('Checking COBie file...')
|
54 |
+
|
55 |
+
with st.spinner('Checking COBie file...'):
|
56 |
+
|
57 |
+
response = add_data(
|
58 |
+
key='akljnv13bvi2vfo0b0bw',
|
59 |
+
cobie_file=cobie_file,
|
60 |
+
output_format='html',
|
61 |
+
)
|
62 |
+
|
63 |
+
file_name = cobie_file.name.split('.')[0] + '.html'
|
64 |
+
|
65 |
+
if response.status_code != 200:
|
66 |
+
st.error(f"Error: {response.text}")
|
67 |
+
st.stop()
|
68 |
+
|
69 |
+
os.makedirs("/tmp", exist_ok=True)
|
70 |
+
file_save = open(file_name, 'wb')
|
71 |
+
file_save.write(response.content)
|
72 |
+
file_save.close()
|
73 |
+
|
74 |
+
st.download_button(
|
75 |
+
label="Download check file",
|
76 |
+
data=response.content,
|
77 |
+
file_name=f"/tmp/{file_name}",
|
78 |
+
mime=response.headers['Content-Type'],
|
79 |
+
)
|
80 |
+
|
81 |
+
with open(f"/tmp/{file_name}", 'r') as f:
|
82 |
+
html_string = f.read()
|
83 |
+
st.components.v1.html(
|
84 |
+
html_string,
|
85 |
+
# width=900,
|
86 |
+
height=1000,
|
87 |
+
scrolling=True,
|
88 |
+
)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
simplejson
|
3 |
+
requests
|
4 |
+
requests
|