Spaces:
Sleeping
Sleeping
import streamlit as st | |
import streamlit.components.v1 as components | |
import subprocess | |
import time | |
import requests | |
hide_streamlit_style = """ | |
<style> | |
/* Hide the hamburger menu */ | |
#MainMenu {visibility: hidden;} | |
/* Hide the header */ | |
header {visibility: hidden;} | |
/* Hide the footer */ | |
footer {visibility: hidden;} | |
</style> | |
""" | |
st.markdown(hide_streamlit_style, unsafe_allow_html=True) | |
chainlit_url = f"https://deepseek-r1-nextjs.vercel.app/" | |
timeout = 60 # Maximum wait time in seconds | |
start_time = time.time() | |
# Create a progress bar and a placeholder for status messages | |
progress_bar = st.progress(0) | |
status_text = st.empty() | |
with st.spinner("Please wait to prepare the app..."): | |
while True: | |
try: | |
response = requests.get(chainlit_url) | |
if response.status_code == 200: | |
break # app is ready | |
except Exception: | |
pass # Keep waiting if there's an error (e.g., connection refused) | |
elapsed = time.time() - start_time | |
# Update progress (capped at 100%) | |
progress = min(int((elapsed / timeout) * 100), 100) | |
progress_bar.progress(progress) | |
status_text.text(f"Waiting... {int(elapsed)} seconds elapsed.") | |
time.sleep(1) | |
if elapsed > timeout: | |
st.error("main app did not start in time.") | |
st.stop() | |
st.success("App loaded!") | |
status_text.text("") | |
# Embed the Chainlit app using an iframe | |
# components.iframe(chainlit_url, width=800) | |
html_code = f""" | |
<style> | |
.full-screen-iframe {{ | |
position: fixed; | |
top: 0; | |
left: 0; | |
width: 100vw; | |
height: 100vh; | |
border: none; | |
z-index: 9999; | |
}} | |
</style> | |
<iframe src="{chainlit_url}" class="full-screen-iframe"></iframe> | |
""" | |
st.markdown(html_code, unsafe_allow_html=True) | |