File size: 1,885 Bytes
13cb503
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)