Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import streamlit.components.v1 as components
|
3 |
+
import subprocess
|
4 |
+
import time
|
5 |
+
import requests
|
6 |
+
|
7 |
+
hide_streamlit_style = """
|
8 |
+
<style>
|
9 |
+
/* Hide the hamburger menu */
|
10 |
+
#MainMenu {visibility: hidden;}
|
11 |
+
/* Hide the header */
|
12 |
+
header {visibility: hidden;}
|
13 |
+
/* Hide the footer */
|
14 |
+
footer {visibility: hidden;}
|
15 |
+
</style>
|
16 |
+
"""
|
17 |
+
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
chainlit_url = f"https://deepseek-r1-nextjs.vercel.app/"
|
22 |
+
timeout = 60 # Maximum wait time in seconds
|
23 |
+
start_time = time.time()
|
24 |
+
|
25 |
+
# Create a progress bar and a placeholder for status messages
|
26 |
+
progress_bar = st.progress(0)
|
27 |
+
status_text = st.empty()
|
28 |
+
|
29 |
+
with st.spinner("Please wait to prepare the app..."):
|
30 |
+
while True:
|
31 |
+
try:
|
32 |
+
response = requests.get(chainlit_url)
|
33 |
+
if response.status_code == 200:
|
34 |
+
break # app is ready
|
35 |
+
except Exception:
|
36 |
+
pass # Keep waiting if there's an error (e.g., connection refused)
|
37 |
+
|
38 |
+
elapsed = time.time() - start_time
|
39 |
+
# Update progress (capped at 100%)
|
40 |
+
progress = min(int((elapsed / timeout) * 100), 100)
|
41 |
+
progress_bar.progress(progress)
|
42 |
+
status_text.text(f"Waiting... {int(elapsed)} seconds elapsed.")
|
43 |
+
time.sleep(1)
|
44 |
+
|
45 |
+
if elapsed > timeout:
|
46 |
+
st.error("main app did not start in time.")
|
47 |
+
st.stop()
|
48 |
+
|
49 |
+
st.success("App loaded!")
|
50 |
+
status_text.text("")
|
51 |
+
|
52 |
+
# Embed the Chainlit app using an iframe
|
53 |
+
# components.iframe(chainlit_url, width=800)
|
54 |
+
html_code = f"""
|
55 |
+
<style>
|
56 |
+
.full-screen-iframe {{
|
57 |
+
position: fixed;
|
58 |
+
top: 0;
|
59 |
+
left: 0;
|
60 |
+
width: 100vw;
|
61 |
+
height: 100vh;
|
62 |
+
border: none;
|
63 |
+
z-index: 9999;
|
64 |
+
}}
|
65 |
+
</style>
|
66 |
+
<iframe src="{chainlit_url}" class="full-screen-iframe"></iframe>
|
67 |
+
"""
|
68 |
+
|
69 |
+
st.markdown(html_code, unsafe_allow_html=True)
|