awacke1's picture
Update app.py
f7eafd6 verified
raw
history blame
1.42 kB
# app.py
import streamlit as st
import streamlit.components.v1 as components
import os # Used to construct the file path reliably
# --- 1. Set Page Configuration ---
# This must be the first Streamlit command called
st.set_page_config(
page_title="Three.js Game Viewer",
layout="wide" # Set the layout to wide mode
)
st.header("🎮 Basic Three.js Game Embed")
st.caption("Displays the content of index.html below.")
# --- 2. Define the path to your HTML file ---
# Assumes index.html is in the same directory as app.py
html_file_path = 'index.html'
# --- 3. Read the HTML file ---
try:
with open(html_file_path, 'r', encoding='utf-8') as f:
html_content = f.read()
# --- 4. Embed the HTML into the Streamlit app ---
# Adjust the height as needed for your specific game view
components.html(
html_content,
height=700, # You might need to adjust this value
scrolling=False # Set to True if your HTML content needs scrolling
)
st.sidebar.info("Use WASD or Arrow Keys inside the frame above to move the cube.")
except FileNotFoundError:
st.error(f"Error: Could not find the file '{html_file_path}'.")
st.warning("Please make sure the `index.html` file (containing the Three.js code) is in the same directory as this `app.py` script.")
except Exception as e:
st.error(f"An error occurred while reading or embedding the HTML file: {e}")