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