Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import streamlit.components.v1 as components
|
3 |
+
import random
|
4 |
+
import string
|
5 |
+
import time
|
6 |
+
|
7 |
+
# Load the initial HTML5 app
|
8 |
+
with open("aframe_app.html", "r") as f:
|
9 |
+
initial_html = f.read()
|
10 |
+
|
11 |
+
# Initialize session state
|
12 |
+
if "html_content" not in st.session_state:
|
13 |
+
st.session_state.html_content = initial_html
|
14 |
+
if "player_names" not in st.session_state:
|
15 |
+
st.session_state.player_names = []
|
16 |
+
|
17 |
+
# Function to generate a random name for a new player
|
18 |
+
def generate_player_name():
|
19 |
+
adjectives = ["Adventurous", "Brave", "Curious", "Daring", "Fearless", "Intrepid", "Valiant"]
|
20 |
+
nouns = ["Explorer", "Wanderer", "Pathfinder", "Trailblazer", "Voyager", "Wayfarer", "Traveler"]
|
21 |
+
return random.choice(adjectives) + " " + random.choice(nouns)
|
22 |
+
|
23 |
+
# Function to add a new player to the scene
|
24 |
+
def add_player():
|
25 |
+
player_name = generate_player_name()
|
26 |
+
while player_name in st.session_state.player_names:
|
27 |
+
player_name = generate_player_name()
|
28 |
+
st.session_state.player_names.append(player_name)
|
29 |
+
player_html = f'<a-entity id="{player_name}" geometry="primitive: box" material="color: {random.choice(['red', 'green', 'blue', 'yellow', 'purple'])}"></a-entity>'
|
30 |
+
st.session_state.html_content = st.session_state.html_content.replace("</a-scene>", player_html + "\n</a-scene>")
|
31 |
+
|
32 |
+
# Streamlit app
|
33 |
+
def main():
|
34 |
+
st.set_page_config(page_title="3D House Exploration", layout="wide")
|
35 |
+
st.title("3D House Exploration")
|
36 |
+
|
37 |
+
# Add a new player button
|
38 |
+
if st.button("Join Game"):
|
39 |
+
add_player()
|
40 |
+
|
41 |
+
# Display the HTML5 app
|
42 |
+
components.html(st.session_state.html_content, height=800)
|
43 |
+
|
44 |
+
# Editor for HTML5 content
|
45 |
+
st.subheader("Edit Content")
|
46 |
+
new_html = st.text_area("HTML5 Content", st.session_state.html_content, height=300)
|
47 |
+
|
48 |
+
# Save button
|
49 |
+
if st.button("Save"):
|
50 |
+
st.session_state.html_content = new_html
|
51 |
+
|
52 |
+
# Refresh timer
|
53 |
+
last_refresh = st.button("Refresh")
|
54 |
+
if last_refresh:
|
55 |
+
st.experimental_rerun()
|
56 |
+
|
57 |
+
if not st.button("Refresh", key="refresh_button"):
|
58 |
+
refresh_timer = st.empty()
|
59 |
+
while True:
|
60 |
+
time.sleep(5)
|
61 |
+
refresh_timer.text(f"Refreshing in {5 - int(time.time()) % 5} seconds...")
|
62 |
+
if st.button("Refresh", key="refresh_button"):
|
63 |
+
st.experimental_rerun()
|
64 |
+
break
|
65 |
+
|
66 |
+
if __name__ == "__main__":
|
67 |
+
main()
|