
import os
os.environ['POLLINATION_API_URL'] = 'https://api.staging.pollination.cloud'

import streamlit.components.v1 as components
from pollination_streamlit.selectors import get_api_client
from pollination_streamlit_io import create_study

from pollination_streamlit_viewer import viewer
import streamlit as st

api_client = get_api_client()

study = create_study('st-study',
                     api_client=api_client)

if study:
    name, value, type = study.progress_report(show_output=True)
    if name and name.endswith('vtkjs'):
        viewer(key='model', content=value)
    
    # get file
    sun_up_hours_bytes = study.download_artifact('results/direct_sun_hours/sun-up-hours.txt')
    if sun_up_hours_bytes:
        st.text(sun_up_hours_bytes.decode('utf-8'))
