IanYeo's picture
file name update
7556dc1
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(f"/tmp/{file_name}", 'wb')
file_save.write(response.content)
file_save.close()
st.download_button(
label="Download check file",
data=response.content,
file_name=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,
)